Java Code Examples for org.eclipse.xtext.GrammarUtil#containingCrossReference()
The following examples show how to use
org.eclipse.xtext.GrammarUtil#containingCrossReference() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SequenceFeeder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void acceptRuleCall(RuleCall rc, Object value, String token, int index, INode node) { CrossReference crossRef = GrammarUtil.containingCrossReference(rc); if (crossRef != null) { if (rc.getRule() instanceof ParserRule) sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index, getCompositeNode(node)); else if (rc.getRule() instanceof TerminalRule) sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, getLeafNode(node)); else if (rc.getRule() instanceof EnumRule) sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, getCompositeNode(node)); } else { if (rc.getRule() instanceof ParserRule) { AbstractRule rule = rc.getRule(); if (rule.getType() != null && rule.getType().getClassifier() instanceof EClass) acceptEObjectRuleCall(rc, (EObject) value, getCompositeNode(node)); else sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, getCompositeNode(node)); } else if (rc.getRule() instanceof TerminalRule) sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, getLeafNode(node)); else if (rc.getRule() instanceof EnumRule) sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, getCompositeNode(node)); } }
Example 2
Source File: CrossReferenceSerializer.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public boolean isValid(EObject semanticObject, CrossReference crossref, EObject target, INode node, Acceptor errors) { if ((target == null || target.eIsProxy()) && node != null) { CrossReference crossrefFromNode = GrammarUtil.containingCrossReference(node.getGrammarElement()); return crossref == crossrefFromNode; } final EReference ref = GrammarUtil.getReference(crossref, semanticObject.eClass()); final IScope scope = scopeProvider.getScope(semanticObject, ref); if (scope == null) { if (errors != null) errors.accept(diagnostics.getNoScopeFoundDiagnostic(semanticObject, crossref, target)); return false; } if (target != null && target.eIsProxy()) { target = handleProxy(target, semanticObject, ref); } return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors) != null; }
Example 3
Source File: AbstractFormattingConfig.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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; }
Example 4
Source File: GrammarElementTitleSwitch.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String addCrossRef(String result, AbstractElement ele) { if (!showAssignment) return result; CrossReference cr = GrammarUtil.containingCrossReference(ele); if (cr == null) return result; String name = cr.getType() != null && cr.getType().getClassifier() != null ? cr.getType().getClassifier() .getName() : "null"; return "[" + name + "|" + result + "]"; }
Example 5
Source File: SequenceFeeder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void acceptKeyword(Assignment ass, Keyword keyword, Object value, String token, int index, ILeafNode node) { CrossReference crossRef = GrammarUtil.containingCrossReference(keyword); if (crossRef != null) sequenceAcceptor.acceptAssignedCrossRefKeyword(keyword, token, (EObject) value, index, node); else sequenceAcceptor.acceptAssignedKeyword(keyword, token, value, index, node); }
Example 6
Source File: SequenceFeeder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String getToken(Keyword keyword, Object value, ILeafNode node) { CrossReference crossRef = GrammarUtil.containingCrossReference(keyword); if (crossRef != null) return provider.crossRefSerializer.serializeCrossRef(semanticObject, crossRef, (EObject) value, node, errorAcceptor); return provider.keywordSerializer.serializeAssignedKeyword(semanticObject, keyword, value, node, errorAcceptor); }
Example 7
Source File: SequenceFeeder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String getToken(RuleCall rc, Object value, INode node) { CrossReference crossRef = GrammarUtil.containingCrossReference(rc); Assignment assignment = GrammarUtil.containingAssignment(rc); if (crossRef != null) return provider.crossRefSerializer.serializeCrossRef(semanticObject, crossRef, (EObject) value, node, errorAcceptor); else if (GrammarUtil.isEObjectRuleCall(rc) || GrammarUtil.isBooleanAssignment(assignment)) return null; else if (GrammarUtil.isEnumRuleCall(rc)) return provider.enumLiteralSerializer.serializeAssignedEnumLiteral(semanticObject, rc, value, node, errorAcceptor); else return provider.valueSerializer.serializeAssignedValue(semanticObject, rc, value, node, errorAcceptor); }
Example 8
Source File: AssignmentFinder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected Set<AbstractElement> findValidAssignmentsForCrossRef(EObject semanticObj, Iterable<AbstractElement> assignedElements, EObject value, INode node) { Set<AbstractElement> result = Sets.newLinkedHashSet(); for (AbstractElement ass : assignedElements) { CrossReference crossref = GrammarUtil.containingCrossReference(ass); EReference eref = GrammarUtil.getReference(crossref, semanticObj.eClass()); if (EcoreUtil2.isAssignableFrom(eref.getEReferenceType(), value.eClass()) && crossRefSerializer.isValid(semanticObj, crossref, value, node, null)) result.add(ass); } return result; }
Example 9
Source File: NodeModelSemanticSequencer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void createSequence(ISerializationContext context, EObject semanticObject) { SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject); while (ni.hasNext()) { Triple<INode, AbstractElement, EObject> node = ni.next(); if (node.getSecond() instanceof RuleCall) { RuleCall rc = (RuleCall) node.getSecond(); TypeRef ruleType = rc.getRule().getType(); if (ruleType == null || ruleType.getClassifier() instanceof EClass) acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst()); else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) { EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(), semanticObject.eClass()); acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst()); } else { String strVal = NodeModelUtils.getTokenText(node.getFirst()); Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()), node.getFirst()); acceptSemantic(semanticObject, rc, val, node.getFirst()); } } else if (node.getSecond() instanceof Keyword) acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst()); else if (node.getSecond() instanceof Action) { acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst()); } } }