private String getFQFeatureName(final AbstractRule r) { String _name = r.getName(); return ("_" + _name); }
@Override protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) { if (rule == null || rule.eIsProxy()) return Collections.emptyList(); String methodName = "entryRule" + rule.getName(); PolymorphicDispatcher<Collection<FollowElement>> dispatcher = new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser)); dispatcher.invoke(); return parser.getFollowElements(); }
/** * @throws IllegalArgumentException if the rule is not a datatype rule or does not fulfill * the pattern <pre>RuleName: 'keyword' | 'other';</pre> */ public void setRule(AbstractRule rule) { this.rule = rule; if (!GrammarUtil.isDatatypeRule(rule)) throw new IllegalArgumentException(rule.getName() + " is not a data type rule"); if (!(rule.getAlternatives() instanceof Alternatives) && !(rule.getAlternatives() instanceof Keyword)) { throw new IllegalArgumentException(rule.getName() + " is not a simple keyword nor an alternative"); } if (rule.getAlternatives() instanceof Keyword) { keywords = ImmutableSet.of(keywordToString((Keyword) rule.getAlternatives())); } else { Alternatives alternatives = (Alternatives) rule.getAlternatives(); ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for(AbstractElement element: alternatives.getElements()) { if (!(element instanceof Keyword)) { throw new IllegalArgumentException(rule.getName() + "'s body does not contain an alternative of keywords"); } builder.add(keywordToString((Keyword) element)); } keywords = builder.build(); } }
protected Digraph drawRule(AbstractRule rule, Digraph d) { if (rule.getType().getClassifier() instanceof EClass) drawAbstractElementTree(rule.getAlternatives(), d); return d; }
protected boolean doCreateProposals() { return rule != null && !rule.eIsProxy() && rule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) rule); } }
@Override public Boolean caseAbstractRule(AbstractRule object) { if (!validatedRules.add(object)) return Boolean.FALSE; ruleStack.add(object); Boolean result = object.getAlternatives() == null ? Boolean.FALSE : doSwitch(object.getAlternatives()); ruleStack.remove(object); return result; }
public List<Keyword> findKeywords(String... keywords) { Set<String> kwds = new HashSet<String>(Arrays.asList(keywords)); ArrayList<Keyword> r = new ArrayList<Keyword>(); for (AbstractRule ar : getRules()) { TreeIterator<EObject> i = ar.eAllContents(); while (i.hasNext()) { EObject o = i.next(); if (o instanceof Keyword) { Keyword k = (Keyword) o; if (kwds.contains(k.getValue())) r.add(k); } } } return r; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public AbstractRule getRule() { if (rule != null && rule.eIsProxy()) { InternalEObject oldRule = (InternalEObject)rule; rule = (AbstractRule)eResolveProxy(oldRule); if (rule != oldRule) { if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.RESOLVE, XtextPackage.RULE_CALL__RULE, oldRule, rule)); } } return rule; }
@Override public AbstractElement getRoot() { return GrammarUtil.containingRule(context).getAlternatives(); } }
protected List<AbstractElement> getAbstractElements(EObject obj) { if (obj instanceof AbstractElement) return Collections.singletonList((AbstractElement) obj); if (obj instanceof AbstractRule) { AbstractRule rule = (AbstractRule) obj; if (rule.getType().getClassifier() instanceof EClass) return Collections.singletonList(rule.getAlternatives()); List<AbstractElement> result = Lists.newArrayList(); for (RuleCall rc : grammarAccess.findRuleCalls(rule)) { CrossReference cr = GrammarUtil.containingCrossReference(rc); result.add(cr == null ? rc : cr); } return result; } return null; }
public List<RuleCall> findRuleCalls(AbstractRule... rules) { Set<AbstractRule> rls = new HashSet<AbstractRule>(Arrays.asList(rules)); ArrayList<RuleCall> r = new ArrayList<RuleCall>(); for (AbstractRule ar : getRules()) { TreeIterator<EObject> i = ar.eAllContents(); while (i.hasNext()) { EObject o = i.next(); if (o instanceof RuleCall) { RuleCall c = (RuleCall) o; if (rls.contains(c.getRule())) r.add(c); } } } return r; }
private void updateHiddenTokens(List<AbstractRule> hiddenTokens, Map<String, AbstractRule> rulePerName) { for (int i = 0; i < hiddenTokens.size(); i++) { AbstractRule hidden = hiddenTokens.get(i); AbstractRule overridden = rulePerName.get(hidden.getName()); if (overridden != null) hiddenTokens.set(i, overridden); } }
@Override protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) { if (rule == null || rule.eIsProxy()) return Collections.emptyList(); String methodName = "entryRule" + rule.getName(); PolymorphicDispatcher<Collection<FollowElement>> dispatcher = new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser)); dispatcher.invoke(); return parser.getFollowElements(); }
throw new IllegalArgumentException(rule.getName() + " is not a data type rule"); if (!(rule.getAlternatives() instanceof Alternatives)) { if (rule.getAlternatives() instanceof RuleCall) { delegateRule = ((RuleCall) rule.getAlternatives()).getRule(); keywords = Collections.emptySet(); return; throw new IllegalArgumentException(rule.getName() + " is not an alternative and not a rule call"); Alternatives alternatives = (Alternatives) rule.getAlternatives(); ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for(AbstractElement element: alternatives.getElements()) { } else if (element instanceof RuleCall) { if (delegateRule != null) throw new IllegalArgumentException(rule.getName() + "'s body does not contain an alternative of keywords and a single rule"); delegateRule = ((RuleCall) element).getRule(); } else { throw new IllegalArgumentException(rule.getName() + "'s body does not contain an alternative of keywords and a single rule");
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public AbstractRule getContext() { if (context != null && context.eIsProxy()) { InternalEObject oldContext = (InternalEObject)context; context = (AbstractRule)eResolveProxy(oldContext); if (context != oldContext) { if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.RESOLVE, TemplatesPackage.CODETEMPLATE__CONTEXT, oldContext, context)); } } return context; }
protected Result doInspect(RuleType rule) { visitedRules.add(rule); Result r = doSwitch(rule.getAlternatives()); return r; }
@Override public AbstractElement getCall(AbstractElement ele) { if (ele instanceof RuleCall && !GrammarUtil.isAssigned(ele) && ((RuleCall) ele).getRule().getType().getClassifier() instanceof EClass) return ((RuleCall) ele).getRule().getAlternatives(); return null; }
public List<Pair<Keyword, Keyword>> findKeywordPairs(String leftKw, String rightKw) { ArrayList<Pair<Keyword, Keyword>> pairs = new ArrayList<Pair<Keyword, Keyword>>(); for (AbstractRule ar : getRules()) if (ar instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) ar)) { Stack<Keyword> openings = new Stack<Keyword>(); TreeIterator<EObject> i = ar.eAllContents(); while (i.hasNext()) { EObject o = i.next(); if (o instanceof Keyword) { Keyword k = (Keyword) o; if (leftKw.equals(k.getValue())) openings.push(k); else if (rightKw.equals(k.getValue())) { if (openings.size() > 0) pairs.add(Tuples.create(openings.pop(), k)); } } } } return pairs; }