EClassifier getClassifierFor(AbstractRule rule) { if (rule.getType() != null && rule.getType().getClassifier() != null) return rule.getType().getClassifier(); if (rule instanceof TerminalRule || rule instanceof ParserRule && DatatypeRuleUtil.isDatatypeRule((ParserRule) rule)) { return GrammarUtil.findEString(grammar); } return null; }
private EClassifierInfo findEClassifierInfo(AbstractRule rule) { final TypeRef typeRef = getOrComputeReturnType(rule); if (typeRef == null) throw new NullPointerException(); if (rule.getType() != typeRef) throw new IllegalStateException(); return eClassifierInfos.getInfo(typeRef); }
public static boolean isEObjectRuleCall(EObject grammarElement) { if (grammarElement instanceof RuleCall) { AbstractRule calledRule = ((RuleCall) grammarElement).getRule(); return calledRule != null && calledRule instanceof ParserRule && calledRule.getType().getClassifier() instanceof EClass; } return false; }
protected boolean isConsumingElement() { return element instanceof Assignment || (element instanceof RuleCall && ((RuleCall) element).getRule().getType().getClassifier() instanceof EClass) || element instanceof Action; }
public static boolean isDatatypeRuleCall(EObject grammarElement) { if (grammarElement instanceof RuleCall) { AbstractRule calledRule = ((RuleCall) grammarElement).getRule(); return calledRule != null && calledRule instanceof ParserRule && calledRule.getType().getClassifier() instanceof EDataType; } return false; }
public boolean isParserRuleCall() { return element instanceof RuleCall && ((RuleCall) element).getRule().getType().getClassifier() instanceof EClass; }
protected EObject createModelElement(AbstractRule rule) { return createModelElement(rule.getType().getClassifier(), currentNode); }
protected boolean filter(AbstractElement ele) { AbstractRule rule = GrammarUtil.containingRule(ele); if (rule == null || !(rule.getType().getClassifier() instanceof EClass)) return true; return builder.filter(ele); }
protected Digraph drawRule(AbstractRule rule, Digraph d) { if (rule.getType().getClassifier() instanceof EClass) drawAbstractElementTree(rule.getAlternatives(), d); return d; }
protected EObject createModelElementForParent(AbstractRule rule) { return createModelElement(rule.getType().getClassifier(), currentNode.getParent()); }
@Override public Boolean caseAssignment(Assignment object) { EClassifier wasType = currentType; if (currentType == null) { if (context.getType() != null) currentType = context.getType().getClassifier(); } if (object.getTerminal() != null) if (doSwitch(object.getTerminal())) return true; if (object == stopElement) return true; if (GrammarUtil.isOptionalCardinality(object)) currentType = getCompatibleType(currentType, wasType, object); return false; }
private boolean deriveTypeHierarchyFromOverridden(ParserRule rule, Grammar grammar) throws TransformationException { AbstractRule parentRule = GrammarUtil.findRuleForName(grammar, rule.getName()); if (parentRule != null && parentRule.getType() != null && parentRule != rule) { if (parentRule.getType().getClassifier() instanceof EDataType) throw new TransformationException(TransformationErrorCode.InvalidSupertype, "Cannot inherit from datatype rule and return another type.", rule.getType()); EClassifierInfo parentTypeInfo = eClassifierInfos.getInfoOrNull(parentRule.getType()); if (parentTypeInfo == null) throw new TransformationException(TransformationErrorCode.InvalidSupertype, "Cannot determine return type of overridden rule.", rule.getType()); addSuperType(rule, rule.getType(), parentTypeInfo); return true; } return false; }
@Override public String caseAbstractRule(AbstractRule object) { String classifier = object.getType().getClassifier().getName(); if (object.getName().equals(classifier)) return object.getName() + ":"; return object.getName() + " returns " + classifier + ":"; }
protected List<AbstractRule> getExportedRulesFromGrammar() { List<AbstractRule> _xblockexpression = null; { final HashSet<EClassifier> alreadyCollected = CollectionLiterals.<EClassifier>newHashSet(); final Function1<AbstractRule, Boolean> _function = (AbstractRule it) -> { return Boolean.valueOf((this.isExported(it) && alreadyCollected.add(it.getType().getClassifier()))); }; _xblockexpression = IterableExtensions.<AbstractRule>toList(IterableExtensions.<AbstractRule>filter(this.getGrammar().getRules(), _function)); } return _xblockexpression; }
/** * @since 2.14 */ protected List<AbstractRule> getDeprecatedRulesFromGrammar() { final HashSet<EClassifier> alreadyCollected = CollectionLiterals.<EClassifier>newHashSet(); final Function1<AbstractRule, Boolean> _function = (AbstractRule it) -> { return Boolean.valueOf((this.isDeprecated(it) && alreadyCollected.add(it.getType().getClassifier()))); }; return IterableExtensions.<AbstractRule>toList(IterableExtensions.<AbstractRule>filter(this.getGrammar().getRules(), _function)); }
@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; }
/** * @since 2.0 */ protected EClass getConstructedType(AbstractElement ele) { if (ele instanceof Action) return (EClass) ((Action) ele).getType().getClassifier(); if (GrammarUtil.containingAssignment(ele) != null) return (EClass) GrammarUtil.containingRule(ele).getType().getClassifier(); return null; }
public boolean checkCrossReferenceTerminal(RuleCall call) { if (call.getRule() != null && call.getRule().getType() != null) { EClassifier type = call.getRule().getType().getClassifier(); EDataType dataType = GrammarUtil.findEString(GrammarUtil.getGrammar(call)); if (dataType == null) dataType = EcorePackage.Literals.ESTRING; if (type != null && dataType != type) { error( "The rule '" + call.getRule().getName() + "' is not valid for a cross reference since it does not return "+ "an EString. You'll have to wrap it in a data type rule.", call, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); return true; } } return false; }
public List<T> getAllIncoming() { for (Adapter a : element.eResource().eAdapters()) if (a instanceof IsInitializedMarker && ((IsInitializedMarker) a).builder == builder) return getIncoming(); element.eResource().eAdapters().add(new IsInitializedMarker(builder)); for (EObject root : element.eResource().getContents()) if (root instanceof Grammar) for (AbstractRule rule : ((Grammar) root).getRules()) if (rule.getType().getClassifier() instanceof EClass) for (AbstractElement ele : EcoreUtil2.eAllOfType(rule, AbstractElement.class)) if (!builder.filter(ele)) builder.getState(ele).getOutgoing(); return getIncoming(); }