Search in sources :

Example 1 with TwoParametersTestLanguageInjectorProvider

use of org.eclipse.xtext.ui.tests.editor.contentassist.tests.TwoParametersTestLanguageInjectorProvider 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);
    }
}
Also used : Arrays(java.util.Arrays) AbstractElement(org.eclipse.xtext.AbstractElement) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) FlattenedGrammarAccess(org.eclipse.xtext.xtext.FlattenedGrammarAccess) TwoParametersTestLanguageGrammarAccess(org.eclipse.xtext.ui.tests.editor.contentassist.services.TwoParametersTestLanguageGrammarAccess) Lists(com.google.common.collect.Lists) TwoParametersTestLanguageInjectorProvider(org.eclipse.xtext.ui.tests.editor.contentassist.tests.TwoParametersTestLanguageInjectorProvider) 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) InternalTwoParametersTestLanguageParser(org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.internal.InternalTwoParametersTestLanguageParser) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) Sets(com.google.common.collect.Sets) TwoParametersTestLanguageParser(org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.TwoParametersTestLanguageParser) 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) RuleNames(org.eclipse.xtext.xtext.RuleNames) AbstractElement(org.eclipse.xtext.AbstractElement) InternalTwoParametersTestLanguageParser(org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.internal.InternalTwoParametersTestLanguageParser) TwoParametersTestLanguageParser(org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.TwoParametersTestLanguageParser) Grammar(org.eclipse.xtext.Grammar) FlattenedGrammarAccess(org.eclipse.xtext.xtext.FlattenedGrammarAccess) TwoParametersTestLanguageGrammarAccess(org.eclipse.xtext.ui.tests.editor.contentassist.services.TwoParametersTestLanguageGrammarAccess) Injector(com.google.inject.Injector) TwoParametersTestLanguageInjectorProvider(org.eclipse.xtext.ui.tests.editor.contentassist.tests.TwoParametersTestLanguageInjectorProvider) 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 AbstractElement (org.eclipse.xtext.AbstractElement)1 Grammar (org.eclipse.xtext.Grammar)1 TwoParametersTestLanguageParser (org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.TwoParametersTestLanguageParser)1 InternalTwoParametersTestLanguageParser (org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.internal.InternalTwoParametersTestLanguageParser)1 TwoParametersTestLanguageGrammarAccess (org.eclipse.xtext.ui.tests.editor.contentassist.services.TwoParametersTestLanguageGrammarAccess)1 TwoParametersTestLanguageInjectorProvider (org.eclipse.xtext.ui.tests.editor.contentassist.tests.TwoParametersTestLanguageInjectorProvider)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