Search in sources :

Example 6 with RuleWithParameterValues

use of org.eclipse.xtext.xtext.RuleWithParameterValues in project xtext-core by eclipse.

the class FlattenedGrammarAccess method copyRuleStubs.

private ArrayList<AbstractRule> copyRuleStubs(final RuleNames names, final Map<RuleWithParameterValues, AbstractRule> origToCopy, final List<AbstractRule> rulesToCopy, final boolean discardTypeRef) {
    final ArrayList<AbstractRule> result = CollectionLiterals.<AbstractRule>newArrayList();
    for (final AbstractRule rule : rulesToCopy) {
        {
            String ruleName = names.getAntlrRuleName(rule);
            boolean _matched = false;
            if (rule instanceof ParserRule) {
                _matched = true;
                List<Parameter> params = ((ParserRule) rule).getParameters();
                boolean _isEmpty = params.isEmpty();
                if (_isEmpty) {
                    ParserRule copy = this.<ParserRule>copy(((ParserRule) rule));
                    copy.setName(ruleName);
                    copy.setFragment(((ParserRule) rule).isFragment());
                    copy.setWildcard(((ParserRule) rule).isWildcard());
                    if ((!discardTypeRef)) {
                        copy.setType(this.copyTypeRef(((ParserRule) rule).getType()));
                    }
                    this.attachTo(copy, rule, origToCopy);
                    result.add(copy);
                } else {
                    final Procedure2<Set<Parameter>, Integer> _function = (Set<Parameter> parameterConfig, Integer i) -> {
                        RuleWithParameterValues parameterValues = new RuleWithParameterValues(rule, parameterConfig);
                        ParserRule copy_1 = this.<ParserRule>copy(((ParserRule) rule));
                        copy_1.setName(names.getAntlrRuleName(rule, (i).intValue()));
                        copy_1.setFragment(((ParserRule) rule).isFragment());
                        copy_1.setWildcard(((ParserRule) rule).isWildcard());
                        if ((!discardTypeRef)) {
                            copy_1.setType(this.copyTypeRef(((ParserRule) rule).getType()));
                        }
                        origToCopy.put(parameterValues, copy_1);
                        parameterValues.attachToEmfObject(copy_1);
                        result.add(copy_1);
                    };
                    IterableExtensions.<Set<Parameter>>forEach(Sets.<Parameter>powerSet(ImmutableSet.<Parameter>copyOf(params)), _function);
                }
            }
            if (!_matched) {
                if (rule instanceof TerminalRule) {
                    _matched = true;
                    TerminalRule orig = ((TerminalRule) rule);
                    TerminalRule copy = this.<TerminalRule>copy(orig);
                    copy.setName(ruleName);
                    copy.setFragment(orig.isFragment());
                    this.attachTo(copy, orig, origToCopy);
                    result.add(copy);
                }
            }
            if (!_matched) {
                if (rule instanceof EnumRule) {
                    _matched = true;
                    EnumRule copy = this.<EnumRule>copy(((EnumRule) rule));
                    copy.setName(ruleName);
                    this.attachTo(copy, rule, origToCopy);
                    result.add(copy);
                }
            }
        }
    }
    return result;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EnumRule(org.eclipse.xtext.EnumRule) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Procedure2(org.eclipse.xtext.xbase.lib.Procedures.Procedure2) RuleWithParameterValues(org.eclipse.xtext.xtext.RuleWithParameterValues) Parameter(org.eclipse.xtext.Parameter) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

RuleWithParameterValues (org.eclipse.xtext.xtext.RuleWithParameterValues)6 AbstractRule (org.eclipse.xtext.AbstractRule)5 ParserRule (org.eclipse.xtext.ParserRule)3 RuleNames (org.eclipse.xtext.xtext.RuleNames)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 EList (org.eclipse.emf.common.util.EList)2 Parameter (org.eclipse.xtext.Parameter)2 RuleCall (org.eclipse.xtext.RuleCall)2 TerminalRule (org.eclipse.xtext.TerminalRule)2 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 EReference (org.eclipse.emf.ecore.EReference)1 AbstractElement (org.eclipse.xtext.AbstractElement)1 CompoundElement (org.eclipse.xtext.CompoundElement)1 Condition (org.eclipse.xtext.Condition)1 EnumRule (org.eclipse.xtext.EnumRule)1 Grammar (org.eclipse.xtext.Grammar)1