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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations