use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class GrammarElementTitleSwitch method addCrossRef.
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 + "]";
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class LazyLinker method installProxies.
private void installProxies(EObject obj, IDiagnosticProducer producer, Multimap<EStructuralFeature.Setting, INode> settingsToLink, ICompositeNode parentNode, boolean dontCheckParent) {
final EClass eClass = obj.eClass();
if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0)
return;
for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) {
EObject grammarElement = node.getGrammarElement();
if (grammarElement instanceof CrossReference && hasLeafNodes(node)) {
producer.setNode(node);
CrossReference crossReference = (CrossReference) grammarElement;
final EReference eRef = GrammarUtil.getReference(crossReference, eClass);
if (eRef == null) {
ParserRule parserRule = GrammarUtil.containingParserRule(crossReference);
final String feature = GrammarUtil.containingAssignment(crossReference).getFeature();
throw new IllegalStateException("Couldn't find EReference for crossreference '" + eClass.getName() + "::" + feature + "' in parser rule '" + parserRule.getName() + "'.");
}
if (!eRef.isResolveProxies()) /*|| eRef.getEOpposite() != null see https://bugs.eclipse.org/bugs/show_bug.cgi?id=282486*/
{
final EStructuralFeature.Setting setting = ((InternalEObject) obj).eSetting(eRef);
settingsToLink.put(new SettingDelegate(setting), node);
} else {
createAndSetProxy(obj, node, eRef);
afterCreateAndSetProxy(obj, node, eRef, crossReference, producer);
}
} else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) {
RuleCall ruleCall = (RuleCall) grammarElement;
AbstractRule calledRule = ruleCall.getRule();
if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
installProxies(obj, producer, settingsToLink, (ICompositeNode) node, true);
}
}
}
if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
installProxies(obj, producer, settingsToLink, parentNode.getParent(), dontCheckParent);
}
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class NodeModelBasedRegionAccessBuilder method isEObjectRoot.
protected boolean isEObjectRoot(INode node) {
if (node instanceof ICompositeNode) {
ICompositeNode parent = node.getParent();
while (parent != null && GrammarUtil.isEObjectFragmentRuleCall(parent.getGrammarElement())) parent = parent.getParent();
if (parent == null)
return true;
INode root = parent;
while (root != null && !root.hasDirectSemanticElement()) root = root.getParent();
if (root == null)
return false;
EObject element = node.getGrammarElement();
if (GrammarUtil.isEObjectRuleCall(element) && !GrammarUtil.isEObjectFragmentRuleCall(element)) {
if (!parent.hasDirectSemanticElement())
return false;
BidiTreeIterator<INode> iterator = node.getAsTreeIterable().iterator();
iterator.next();
while (iterator.hasNext()) {
INode next = iterator.next();
if (next.hasDirectSemanticElement())
return true;
EObject ge = next.getGrammarElement();
if (ge instanceof Action)
return true;
if (ge instanceof RuleCall && GrammarUtil.isAssigned(ge) && ((RuleCall) ge).getRule().getType().getClassifier() instanceof EDataType)
return true;
if (ge instanceof CrossReference)
return true;
}
}
if (element instanceof Action) {
return parent.hasDirectSemanticElement();
}
}
return false;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class SequenceFeeder method getToken.
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);
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class XtextSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == XtextPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case XtextPackage.ACTION:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_AbstractTokenWithCardinality_Action(context, (Action) semanticObject);
return;
} else if (rule == grammarAccess.getActionRule()) {
sequence_Action(context, (Action) semanticObject);
return;
} else
break;
case XtextPackage.ALTERNATIVES:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_AbstractTokenWithCardinality_Alternatives(context, (Alternatives) semanticObject);
return;
} else if (rule == grammarAccess.getAssignableTerminalRule() || rule == grammarAccess.getParenthesizedAssignableElementRule() || rule == grammarAccess.getAssignableAlternativesRule() || action == grammarAccess.getAssignableAlternativesAccess().getAlternativesElementsAction_1_0()) {
sequence_AssignableAlternatives(context, (Alternatives) semanticObject);
return;
} else if (rule == grammarAccess.getEnumLiteralsRule()) {
sequence_EnumLiterals(context, (Alternatives) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_TerminalAlternatives_TerminalToken(context, (Alternatives) semanticObject);
return;
} else
break;
case XtextPackage.ANNOTATION:
sequence_Annotation(context, (Annotation) semanticObject);
return;
case XtextPackage.ASSIGNMENT:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_AbstractTokenWithCardinality_Assignment(context, (Assignment) semanticObject);
return;
} else if (rule == grammarAccess.getAssignmentRule()) {
sequence_Assignment(context, (Assignment) semanticObject);
return;
} else
break;
case XtextPackage.CHARACTER_RANGE:
if (rule == grammarAccess.getCharacterRangeRule()) {
sequence_CharacterRange(context, (CharacterRange) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_CharacterRange_TerminalToken(context, (CharacterRange) semanticObject);
return;
} else
break;
case XtextPackage.CONJUNCTION:
sequence_Conjunction(context, (Conjunction) semanticObject);
return;
case XtextPackage.CROSS_REFERENCE:
sequence_CrossReference(context, (CrossReference) semanticObject);
return;
case XtextPackage.DISJUNCTION:
sequence_Disjunction(context, (Disjunction) semanticObject);
return;
case XtextPackage.EOF:
if (rule == grammarAccess.getEOFRule()) {
sequence_EOF(context, (EOF) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_EOF_TerminalToken(context, (EOF) semanticObject);
return;
} else
break;
case XtextPackage.ENUM_LITERAL_DECLARATION:
sequence_EnumLiteralDeclaration(context, (EnumLiteralDeclaration) semanticObject);
return;
case XtextPackage.ENUM_RULE:
sequence_EnumRule(context, (EnumRule) semanticObject);
return;
case XtextPackage.GENERATED_METAMODEL:
sequence_GeneratedMetamodel(context, (GeneratedMetamodel) semanticObject);
return;
case XtextPackage.GRAMMAR:
sequence_Grammar(context, (Grammar) semanticObject);
return;
case XtextPackage.GROUP:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_AbstractTokenWithCardinality_ConditionalBranch_Group_PredicatedGroup(context, (Group) semanticObject);
return;
} else if (rule == grammarAccess.getPredicatedGroupRule()) {
sequence_PredicatedGroup(context, (Group) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_TerminalGroup_TerminalToken(context, (Group) semanticObject);
return;
} else
break;
case XtextPackage.KEYWORD:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_AbstractTokenWithCardinality_Keyword_PredicatedKeyword(context, (Keyword) semanticObject);
return;
} else if (rule == grammarAccess.getKeywordRule() || rule == grammarAccess.getAssignableTerminalRule() || rule == grammarAccess.getParenthesizedAssignableElementRule() || rule == grammarAccess.getAssignableAlternativesRule() || action == grammarAccess.getAssignableAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getCrossReferenceableTerminalRule() || rule == grammarAccess.getCharacterRangeRule() || action == grammarAccess.getCharacterRangeAccess().getCharacterRangeLeftAction_1_0()) {
sequence_Keyword(context, (Keyword) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_Keyword_TerminalToken(context, (Keyword) semanticObject);
return;
} else if (rule == grammarAccess.getPredicatedKeywordRule()) {
sequence_PredicatedKeyword(context, (Keyword) semanticObject);
return;
} else
break;
case XtextPackage.LITERAL_CONDITION:
sequence_LiteralCondition(context, (LiteralCondition) semanticObject);
return;
case XtextPackage.NAMED_ARGUMENT:
sequence_NamedArgument(context, (NamedArgument) semanticObject);
return;
case XtextPackage.NEGATED_TOKEN:
if (rule == grammarAccess.getAbstractNegatedTokenRule() || rule == grammarAccess.getNegatedTokenRule()) {
sequence_NegatedToken(context, (NegatedToken) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_NegatedToken_TerminalToken(context, (NegatedToken) semanticObject);
return;
} else
break;
case XtextPackage.NEGATION:
sequence_Negation(context, (Negation) semanticObject);
return;
case XtextPackage.PARAMETER:
sequence_Parameter(context, (Parameter) semanticObject);
return;
case XtextPackage.PARAMETER_REFERENCE:
sequence_ParameterReference(context, (ParameterReference) semanticObject);
return;
case XtextPackage.PARSER_RULE:
sequence_ParserRule_RuleNameAndParams(context, (ParserRule) semanticObject);
return;
case XtextPackage.REFERENCED_METAMODEL:
sequence_ReferencedMetamodel(context, (ReferencedMetamodel) semanticObject);
return;
case XtextPackage.RULE_CALL:
if (rule == grammarAccess.getAlternativesRule() || action == grammarAccess.getAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getConditionalBranchRule() || rule == grammarAccess.getUnorderedGroupRule() || action == grammarAccess.getUnorderedGroupAccess().getUnorderedGroupElementsAction_1_0() || rule == grammarAccess.getGroupRule() || action == grammarAccess.getGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getAbstractTokenRule() || rule == grammarAccess.getAbstractTokenWithCardinalityRule() || rule == grammarAccess.getAbstractTerminalRule() || rule == grammarAccess.getParenthesizedElementRule()) {
sequence_AbstractTokenWithCardinality_PredicatedRuleCall_RuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getPredicatedRuleCallRule()) {
sequence_PredicatedRuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getRuleCallRule() || rule == grammarAccess.getAssignableTerminalRule() || rule == grammarAccess.getParenthesizedAssignableElementRule() || rule == grammarAccess.getAssignableAlternativesRule() || action == grammarAccess.getAssignableAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getCrossReferenceableTerminalRule()) {
sequence_RuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalRuleCallRule()) {
sequence_TerminalRuleCall(context, (RuleCall) semanticObject);
return;
} else if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_TerminalRuleCall_TerminalToken(context, (RuleCall) semanticObject);
return;
} else
break;
case XtextPackage.TERMINAL_RULE:
sequence_TerminalRule(context, (TerminalRule) semanticObject);
return;
case XtextPackage.TYPE_REF:
sequence_TypeRef(context, (TypeRef) semanticObject);
return;
case XtextPackage.UNORDERED_GROUP:
sequence_AbstractTokenWithCardinality_UnorderedGroup(context, (UnorderedGroup) semanticObject);
return;
case XtextPackage.UNTIL_TOKEN:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_TerminalToken_UntilToken(context, (UntilToken) semanticObject);
return;
} else if (rule == grammarAccess.getAbstractNegatedTokenRule() || rule == grammarAccess.getUntilTokenRule()) {
sequence_UntilToken(context, (UntilToken) semanticObject);
return;
} else
break;
case XtextPackage.WILDCARD:
if (rule == grammarAccess.getTerminalAlternativesRule() || action == grammarAccess.getTerminalAlternativesAccess().getAlternativesElementsAction_1_0() || rule == grammarAccess.getTerminalGroupRule() || action == grammarAccess.getTerminalGroupAccess().getGroupElementsAction_1_0() || rule == grammarAccess.getTerminalTokenRule() || rule == grammarAccess.getTerminalTokenElementRule() || rule == grammarAccess.getParenthesizedTerminalElementRule()) {
sequence_TerminalToken_Wildcard(context, (Wildcard) semanticObject);
return;
} else if (rule == grammarAccess.getWildcardRule()) {
sequence_Wildcard(context, (Wildcard) semanticObject);
return;
} else
break;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations