Search in sources :

Example 36 with Assignment

use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.

the class NodeModelUtils method findNodesForFeature.

private static List<INode> findNodesForFeature(EObject semanticElement, INode node, EStructuralFeature structuralFeature) {
    List<INode> result = Lists.newArrayList();
    String featureName = structuralFeature.getName();
    BidiTreeIterator<INode> iterator = node.getAsTreeIterable().iterator();
    while (iterator.hasNext()) {
        INode child = iterator.next();
        EObject grammarElement = child.getGrammarElement();
        if (grammarElement != null) {
            if (grammarElement instanceof Action) {
                Action action = (Action) grammarElement;
                if (child.getSemanticElement() == semanticElement) {
                    child = iterator.next();
                    if (featureName.equals(action.getFeature())) {
                        result.add(child);
                    }
                } else {
                    // navigate the action's left side (first child) until we find an assignment (a rule call)
                    // the assignment will tell us about the feature to which we assigned
                    // the semantic object that has been created by the action
                    INode firstChild = ((ICompositeNode) child).getFirstChild();
                    while (firstChild.getGrammarElement() instanceof Action) {
                        firstChild = ((ICompositeNode) firstChild).getFirstChild();
                    }
                    EObject firstChildGrammarElement = firstChild.getGrammarElement();
                    Assignment assignment = GrammarUtil.containingAssignment(firstChildGrammarElement);
                    if (assignment != null && featureName.equals(assignment.getFeature())) {
                        result.add(child);
                    }
                }
                iterator.prune();
            } else if (child != node) {
                Assignment assignment = GrammarUtil.containingAssignment(grammarElement);
                if (assignment != null) {
                    if (featureName.equals(assignment.getFeature())) {
                        result.add(child);
                    }
                    iterator.prune();
                }
            }
        }
    }
    return result;
}
Also used : Assignment(org.eclipse.xtext.Assignment) INode(org.eclipse.xtext.nodemodel.INode) Action(org.eclipse.xtext.Action) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 37 with Assignment

use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.

the class NodeModelBasedRegionAccessBuilder method findGrammarElement.

protected EObject findGrammarElement(INode node, EObject obj) {
    INode current = node;
    String feature = obj.eContainingFeature().getName();
    while (current != null) {
        EObject grammarElement = current.getGrammarElement();
        Assignment assignment = GrammarUtil.containingAssignment(grammarElement);
        if (assignment != null && feature.equals(assignment.getFeature()))
            return grammarElement;
        if (grammarElement instanceof Action) {
            Action action = (Action) grammarElement;
            if (feature.equals(action.getFeature()))
                return grammarElement;
            else if (current == node && current instanceof ICompositeNode) {
                INode child = ((ICompositeNode) current).getFirstChild();
                while (child instanceof ICompositeNode) {
                    EObject grammarElement2 = child.getGrammarElement();
                    Assignment assignment2 = GrammarUtil.containingAssignment(grammarElement2);
                    if (assignment2 != null && feature.equals(assignment2.getFeature()))
                        return grammarElement2;
                    // if (child.hasDirectSemanticElement() && child.getSemanticElement() != obj)
                    // break;
                    child = ((ICompositeNode) child).getFirstChild();
                }
            }
        }
        if (current.hasDirectSemanticElement() && current.getSemanticElement() != obj)
            return null;
        current = current.getParent();
    }
    return null;
}
Also used : Assignment(org.eclipse.xtext.Assignment) INode(org.eclipse.xtext.nodemodel.INode) Action(org.eclipse.xtext.Action) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 38 with Assignment

use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.

the class SequenceFeeder method accept.

public void accept(Keyword keyword, Object value, ILeafNode node) {
    Assignment ass = getAssignment(keyword);
    EStructuralFeature feature = getFeature(ass.getFeature());
    assertIndex(feature);
    assertValue(feature, value);
    String token = getToken(keyword, value, node);
    acceptKeyword(ass, keyword, value, token, ISemanticSequenceAcceptor.NO_INDEX, node);
}
Also used : Assignment(org.eclipse.xtext.Assignment) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 39 with Assignment

use of org.eclipse.xtext.Assignment 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);
}
Also used : Assignment(org.eclipse.xtext.Assignment) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference)

Example 40 with Assignment

use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.

the class SequenceFeeder method accept.

public void accept(Keyword keyword, Object value, int index) {
    Assignment ass = getAssignment(keyword);
    EStructuralFeature feature = getFeature(ass.getFeature());
    assertIndex(feature, index);
    assertValue(feature, value);
    ILeafNode node = getLeafNode(feature, index, index, value);
    String token = getToken(keyword, value, node);
    acceptKeyword(ass, keyword, value, token, index, node);
}
Also used : Assignment(org.eclipse.xtext.Assignment) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Aggregations

Assignment (org.eclipse.xtext.Assignment)60 EObject (org.eclipse.emf.ecore.EObject)27 Test (org.junit.Test)25 RuleCall (org.eclipse.xtext.RuleCall)22 Grammar (org.eclipse.xtext.Grammar)21 AbstractElement (org.eclipse.xtext.AbstractElement)15 ParserRule (org.eclipse.xtext.ParserRule)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 Action (org.eclipse.xtext.Action)13 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)12 AbstractRule (org.eclipse.xtext.AbstractRule)12 Group (org.eclipse.xtext.Group)11 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)9 Alternatives (org.eclipse.xtext.Alternatives)8 CrossReference (org.eclipse.xtext.CrossReference)7 ArrayList (java.util.ArrayList)6 EClass (org.eclipse.emf.ecore.EClass)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)6 NamedArgument (org.eclipse.xtext.NamedArgument)6 LiteralCondition (org.eclipse.xtext.LiteralCondition)5