org.eclipse.xtext.xbase.lib.util.ReflectExtensions Java Examples

The following examples show how to use org.eclipse.xtext.xbase.lib.util.ReflectExtensions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XExecutableCommandRegistry.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Map<String, Type[]> argumentTypes() {
	try {
		Multimap<String, IExecutableCommandService> registeredCommands = new ReflectExtensions().get(this,
				"registeredCommands");
		Map<String, Type[]> result = new HashMap<>();
		for (IExecutableCommandService service : new HashSet<>(registeredCommands.values())) {
			if (service instanceof ExecuteCommandParamsDescriber) {
				result.putAll(((ExecuteCommandParamsDescriber) service).argumentTypes());
			}
		}
		return result;
	} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
		return Collections.emptyMap();
	}
}
 
Example #2
Source File: ProjectOpenedOrClosedListener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.8
 */
protected void scheduleRemoveProjectJobIfNecessary(IProject project, IResourceDelta delta) {
	try {
		ReflectExtensions reflector = new ReflectExtensions();
		Object oldInfo = reflector.get(delta, "oldInfo");
		Map<?, ?> natures = reflector.get(oldInfo, "natures");
		if (natures != null && natures.containsKey(XtextProjectHelper.NATURE_ID)) {
			scheduleRemoveProjectJob(project);
		}
	} catch (Exception e) {
		if (!reflectErrorLogged) {
			log.error("Scheduled unnecessary build due to reflective code failure", e);
			reflectErrorLogged = true;
		}
		scheduleRemoveProjectJob(project);
	}
}
 
Example #3
Source File: AbstractSarlBatchCompilerMojo.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected void prepareExecution() throws MojoExecutionException {
	if (this.injector == null) {
		final Injector mainInjector = SARLStandaloneSetup.doSetup();
		this.injector = mainInjector.createChildInjector(Arrays.asList(new MavenPrivateModule()));
	}
	if (this.sarlBatchCompilerProvider == null) {
		this.sarlBatchCompilerProvider = this.injector.getProvider(SarlBatchCompiler.class);
	}
	if (this.reflect == null) {
		this.reflect = this.injector.getInstance(ReflectExtensions.class);
	}
	if (this.sarlBatchCompilerProvider == null || this.reflect == null) {
		throw new MojoExecutionException(Messages.AbstractSarlBatchCompilerMojo_0);
	}
}
 
Example #4
Source File: AbstractStructuredIdeTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Executes the test with the given default setup. Depending on whether {@link #getDefaultTestWorkspace()} returns a
 * non-empty result, {@link #testWS(List, Object)} will be triggered. Otherwise {@link #test(List, Object)} will be
 * used and uses the default setup of {@link #getDefaultTestProject()}.
 * <p>
 * For further details mind the {@link Documentation documentation} of {@link #getDefaultTestWorkspace()} or
 * {@link #getDefaultTestProject()} respectively.
 */
protected void testInDefaultWorkspace(String content, T t) {
	String nameWithSelector = DEFAULT_MODULE_NAME + TestWorkspaceManager.MODULE_SELECTOR;
	Pair<String, String> moduleContents = Pair.of(nameWithSelector, content);

	boolean moduleAdded = false;
	if (!getDefaultTestWorkspace().isEmpty()) {
		List<Pair<String, List<Pair<String, String>>>> workspace = getDefaultTestWorkspace();
		for (Pair<String, List<Pair<String, String>>> project : workspace) {
			String projectName = project.getKey();
			if (projectName.endsWith(TestWorkspaceManager.MODULE_SELECTOR)) {
				List<Pair<String, String>> modulesPlusMyModule = new ArrayList<>(project.getValue());
				modulesPlusMyModule.add(moduleContents);
				try {
					ReflectExtensions reflectExtensions = new ReflectExtensions();
					reflectExtensions.set(project, "k", projectName.substring(0, projectName.length() - 1));
					reflectExtensions.set(project, "v", modulesPlusMyModule);
					moduleAdded = true;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

		if (!moduleAdded) {
			throw new IllegalStateException("No project selected. Use " + TestWorkspaceManager.MODULE_SELECTOR);
		}

		testWS(workspace, t);
		return;

	} else {
		ArrayList<Pair<String, String>> allModules = Lists.newArrayList(moduleContents);
		allModules.addAll(getDefaultTestProject());
		test(allModules, t);
	}
}
 
Example #5
Source File: SynchronizedGrammarConstraintProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public SynchronizedGrammarConstraintProvider() {
	try {
		new ReflectExtensions().set(this, "cache",
				new ValueWrappingMap<Grammar, SerializationContextMap<IConstraint>>(
						SynchronizedSerializationContextMap::from));
	} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
		throw new RuntimeException(e);
	}
}
 
Example #6
Source File: SynchronizedContextTypePDAProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public SynchronizedContextTypePDAProvider() {
	try {
		new ReflectExtensions().set(this, "cache",
				new ValueWrappingMap<Grammar, SerializationContextMap<Pda<ISerState, RuleCall>>>(
						SynchronizedSerializationContextMap::from));
	} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
		throw new RuntimeException(e);
	}
}
 
Example #7
Source File: UriValidatorBug406208Test.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testExtensionIsEncoded() throws Exception {
	UriValidator validator = new UriValidator();
	new ReflectExtensions().set(validator, "registry", this);
	Assert.assertTrue(validator.isPossiblyManaged(this));
}