use of org.eclipse.xtext.xbase.lib.util.ReflectExtensions in project xtext-eclipse by eclipse.
the class ParametersContentAssistParserSanityTest method methodNames.
/**
* Returns test data.
*/
@Parameters(name = "{0}")
public static Collection<Object[]> methodNames() {
try {
TwoParametersTestLanguageInjectorProvider injectorProvider = new TwoParametersTestLanguageInjectorProvider();
try {
injectorProvider.setupRegistry();
Injector injector = injectorProvider.getInjector();
DummyParser dummyParser = new DummyParser();
TwoParametersTestLanguageGrammarAccess grammarAccess = injector.getInstance(TwoParametersTestLanguageGrammarAccess.class);
RuleNames ruleNames = RuleNames.getRuleNames(grammarAccess.getGrammar(), false);
RuleFilter ruleFilter = new RuleFilter();
ruleFilter.setDiscardUnreachableRules(true);
FlattenedGrammarAccess flattened = new FlattenedGrammarAccess(ruleNames, ruleFilter);
Grammar flattenedGrammar = flattened.getFlattenedGrammar();
dummyParser.setGrammarAccess(grammarAccess);
dummyParser.setNameMappings(new TwoParametersTestLanguageParser.NameMappings(grammarAccess));
dummyParser.getRuleName(null);
Map<AbstractElement, String> nameMappings = new ReflectExtensions().get(dummyParser.getNameMappings(), "mappings");
List<String> methodNames = Lists.newArrayList(nameMappings.values());
Collections.sort(methodNames);
Set<String> flattenedRuleNames = Sets.newHashSet(Lists.transform(flattenedGrammar.getRules(), r -> r.getName()));
return Lists.transform(methodNames, (s) -> new Object[] { s, flattenedRuleNames });
} finally {
injectorProvider.restoreRegistry();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.xtext.xbase.lib.util.ReflectExtensions in project xtext-eclipse by eclipse.
the class UriValidatorBug406208Test method testExtensionIsEncoded.
@Test
public void testExtensionIsEncoded() throws Exception {
UriValidator validator = new UriValidator();
new ReflectExtensions().set(validator, "registry", this);
Assert.assertTrue(validator.isPossiblyManaged(this));
}
use of org.eclipse.xtext.xbase.lib.util.ReflectExtensions in project n4js by eclipse.
the class ContentAssistParserSanityTest method methodNames.
/**
* Returns test data.
*/
@Parameters(name = "{0}")
public static Collection<Object[]> methodNames() {
try {
N4JSInjectorProvider injectorProvider = new N4JSInjectorProvider();
Injector injector = injectorProvider.getInjector();
DummyParser dummyParser = new DummyParser();
N4JSGrammarAccess grammarAccess = injector.getInstance(N4JSGrammarAccess.class);
RuleNames ruleNames = RuleNames.getRuleNames(grammarAccess.getGrammar(), false);
RuleFilter ruleFilter = new RuleFilter();
ruleFilter.setDiscardUnreachableRules(true);
FlattenedGrammarAccess flattened = new FlattenedGrammarAccess(ruleNames, ruleFilter);
Grammar flattenedGrammar = flattened.getFlattenedGrammar();
dummyParser.setGrammarAccess(grammarAccess);
injectorProvider.restoreRegistry();
dummyParser.getRuleName(null);
Map<AbstractElement, String> nameMappings = new ReflectExtensions().get(dummyParser, "nameMappings");
List<String> methodNames = Lists.newArrayList(nameMappings.values());
Collections.sort(methodNames);
Set<String> flattenedRuleNames = Sets.newHashSet(Lists.transform(flattenedGrammar.getRules(), r -> r.getName()));
return Lists.transform(methodNames, (s) -> new Object[] { s, flattenedRuleNames });
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.xtext.xbase.lib.util.ReflectExtensions in project xtext-eclipse by eclipse.
the class ProjectOpenedOrClosedListener method scheduleRemoveProjectJobIfNecessary.
/**
* @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);
}
}
Aggregations