Search in sources :

Example 1 with N4JSInjectorProvider

use of org.eclipse.n4js.N4JSInjectorProvider 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);
    }
}
Also used : N4JSInjectorProvider(org.eclipse.n4js.N4JSInjectorProvider) Arrays(java.util.Arrays) AbstractElement(org.eclipse.xtext.AbstractElement) N4JSInjectorProvider(org.eclipse.n4js.N4JSInjectorProvider) N4JSParser(org.eclipse.n4js.ui.contentassist.antlr.N4JSParser) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) FlattenedGrammarAccess(org.eclipse.xtext.xtext.FlattenedGrammarAccess) Lists(com.google.common.collect.Lists) InternalN4JSParser(org.eclipse.n4js.ui.contentassist.antlr.internal.InternalN4JSParser) Map(java.util.Map) RuleNames(org.eclipse.xtext.xtext.RuleNames) RuleFilter(org.eclipse.xtext.xtext.RuleFilter) Method(java.lang.reflect.Method) Parameterized(org.junit.runners.Parameterized) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) Set(java.util.Set) N4JSGrammarAccess(org.eclipse.n4js.services.N4JSGrammarAccess) Test(org.junit.Test) Sets(com.google.common.collect.Sets) Injector(com.google.inject.Injector) List(java.util.List) Grammar(org.eclipse.xtext.Grammar) ReflectExtensions(org.eclipse.xtext.xbase.lib.util.ReflectExtensions) Assert(org.junit.Assert) Collections(java.util.Collections) ReflectExtensions(org.eclipse.xtext.xbase.lib.util.ReflectExtensions) N4JSGrammarAccess(org.eclipse.n4js.services.N4JSGrammarAccess) RuleNames(org.eclipse.xtext.xtext.RuleNames) AbstractElement(org.eclipse.xtext.AbstractElement) Grammar(org.eclipse.xtext.Grammar) FlattenedGrammarAccess(org.eclipse.xtext.xtext.FlattenedGrammarAccess) Injector(com.google.inject.Injector) RuleFilter(org.eclipse.xtext.xtext.RuleFilter) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Injector (com.google.inject.Injector)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 N4JSInjectorProvider (org.eclipse.n4js.N4JSInjectorProvider)1 N4JSGrammarAccess (org.eclipse.n4js.services.N4JSGrammarAccess)1 N4JSParser (org.eclipse.n4js.ui.contentassist.antlr.N4JSParser)1 InternalN4JSParser (org.eclipse.n4js.ui.contentassist.antlr.internal.InternalN4JSParser)1 AbstractElement (org.eclipse.xtext.AbstractElement)1 Grammar (org.eclipse.xtext.Grammar)1 ReflectExtensions (org.eclipse.xtext.xbase.lib.util.ReflectExtensions)1 FlattenedGrammarAccess (org.eclipse.xtext.xtext.FlattenedGrammarAccess)1 RuleFilter (org.eclipse.xtext.xtext.RuleFilter)1 RuleNames (org.eclipse.xtext.xtext.RuleNames)1