public static boolean isAssignedAction(EObject e) { return e instanceof Action && ((Action) e).getFeature() != null; }
public static boolean isUnassignedAction(EObject e) { return e instanceof Action && ((Action) e).getFeature() == null; }
protected void assertAction(Action action) { if (action.getFeature() == null) throw new RuntimeException("Only assigned actions are allowed."); }
public String getFeature() { return getGrammarElement().getFeature(); }
@Override public Boolean caseAction(Action object) { assignedFeatures = newMultimap(); if (GrammarUtil.isMultipleAssignment(object)) return null; if (object.getFeature() == null) return Boolean.FALSE; checkAssignment(object, object.getFeature()); return Boolean.FALSE; }
@Override public Iterable<AbstractElement> getStarts(AbstractElement root) { Set<AbstractElement> result = Sets.newLinkedHashSet(); for (Action act : GrammarUtil.containedActions(root)) if (act.getFeature() != null) result.add(act); for (AbstractElement ele : super.getStarts(root)) if (ele == null) result.add(null); else if (!GrammarUtil.isAssignedAction(ele)) result.add(ele); return result; }
@Override public Iterable<AbstractElement> getStarts(AbstractElement root) { Set<AbstractElement> result = Sets.newLinkedHashSet(); for (Action act : GrammarUtil.containedActions(root)) if (act.getFeature() != null) result.add(act); for (AbstractElement ele : super.getStarts(root)) if (ele == null) { } else if (actionCtx == ele) { result.add(null); } else if (!GrammarUtil.isAssignedAction(ele)) result.add(ele); return result; }
@Check public void checkUnassignedActionAfterAssignment(final Action action) { if (action.getFeature() == null) { checkCurrentMustBeUnassigned(action); } }
protected String getFeatureName() { if (element instanceof Action) return ((Action) element).getFeature(); Assignment ass = GrammarUtil.containingAssignment(element); if (ass != null) return ass.getFeature(); return null; }
public void consumeAction(Action action, boolean isMany) { if (log.isDebugEnabled()) { log.debug("consumeAction(type = " + action.getType().getClassifier().getName() + ", feature = " + action.getFeature() + ", isMany = " + isMany + ")"); } delegate.consumeAction(action, isMany); }
/** * @since 2.0 */ public static boolean containsAssignedAction(ParserRule rule) { TreeIterator<EObject> ti = rule.eAllContents(); while (ti.hasNext()) { EObject obj = ti.next(); if (obj instanceof Action && ((Action) obj).getFeature() != null) return true; } return false; }
@Override public Xtext2EcoreInterpretationContext caseAction(Action object) { try { TypeRef actionTypeRef = object.getType(); EClassifierInfo actionType = findOrCreateEClassifierInfo(actionTypeRef, null, true); EClassifierInfo currentCompatibleType = context.getCurrentCompatibleType(); Xtext2EcoreInterpretationContext ctx = context.spawnContextWithReferencedType(actionType, object); if (object.getFeature() != null) ctx.addFeature(object.getFeature(), currentCompatibleType, GrammarUtil.isMultipleAssignment(object), true, object); return ctx; } catch (TransformationException e) { reportError(e); } return context; }
public List<IConstraintContext> getConstraints(Grammar context) { List<IConstraintContext> result = cache.get(context); if (result == null) { result = Lists.newArrayList(); for (ParserRule parserRule : GrammarUtil.allParserRules(context)) if (parserRule.getType().getClassifier() instanceof EClass) { result.add(getConstraints(parserRule)); for (Action action : GrammarUtil.containedActions(parserRule)) if (action.getFeature() != null) result.add(getConstraints(action)); } filterDuplicateConstraintsAndSetNames(context, result); cache.put(context, result); } return result; }
protected void populateTypes(Map<TreeConstState, List<TreeConstState>> map) { typesDirty = false; List<TreeConstState> origins = map.get(this); if (origins != null) for (TreeConstState origin : origins) { Set<TypeRef> t = types; if (origin.getGrammarElement() instanceof Action && ((Action) origin.getGrammarElement()).getFeature() != null) t = Collections.emptySet(); else if (t.contains(null) && origin.isConsumingElement()) { t = Sets.newLinkedHashSet(t); t.remove(null); if (origin.getGrammarElement() instanceof Assignment) t.add(GrammarUtil.containingRule(origin.getGrammarElement()).getType()); } if (origin.getTypes().addAll(t) || origin.typesDirty) origin.populateTypes(map); } }
public void accept(Action action, EObject child, int indexInNonTransient) { assertAction(action); EStructuralFeature ref = getFeature(action.getFeature()); assertIndex(ref, indexInNonTransient); ICompositeNode node = getCompositeNode(ref, 0, indexInNonTransient, child); acceptAction(action, child, node); }
protected EObject forceCreateModelElementAndSet(Action action, EObject value) { EObject result = semanticModelBuilder.create(action.getType().getClassifier()); semanticModelBuilder.set(result, action.getFeature(), value, null /* ParserRule */, currentNode); insertCompositeNode(action); associateNodeWithAstElement(currentNode, result); return result; }
protected EObject forceCreateModelElementAndAdd(Action action, EObject value) { EObject result = semanticModelBuilder.create(action.getType().getClassifier()); semanticModelBuilder.add(result, action.getFeature(), value, null /* ParserRule */, currentNode); insertCompositeNode(action); associateNodeWithAstElement(currentNode, result); return result; }
public void accept(Action action, EObject child) { assertAction(action); EStructuralFeature ref = getFeature(action.getFeature()); ICompositeNode node = ref.isMany() ? getCompositeNode(ref, 0, 0, child) : getCompositeNode(ref, child); acceptAction(action, child, node); }
protected boolean ruleContainsAssignedAction(AbstractRule rule, Set<AbstractRule> visited) { if (!visited.add(rule)) return false; TreeIterator<EObject> i = rule.eAllContents(); while (i.hasNext()) { EObject o = i.next(); if (o instanceof Action && ((Action) o).getFeature() != null) return true; else if (o instanceof Assignment) i.prune(); else if (o instanceof RuleCall && isParserRule(((RuleCall) o).getRule())) { if (ruleContainsAssignedAction(((RuleCall) o).getRule(), visited)) return true; } } return false; }
@Override public String caseAction(Action object) { String f = object.getFeature(); String o = object.getOperator(); o = (o == null) ? "" : o; String result; if (showActionAsRuleCall && f != null) { result = f + o + new Context2NameFunction().apply(object) + card(object); } else { String t = object.getType() != null && object.getType().getClassifier() != null ? object.getType() .getClassifier().getName() : "null"; t = (t == null) ? "" : t; f = (f == null) ? "" : "." + f; result = "{" + t + f + o + "}" + card(object); } return addQualified(result, object); }