use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class AssignmentFinder method findValidAssignmentsForCrossRef.
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;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class EmitterNodeIterator method next.
@Override
public INode next() {
INode result;
if (!next.isEmpty()) {
result = next.get(0);
next.remove(0);
} else
result = null;
if (next.isEmpty())
while (iterator.hasNext()) {
INode next = iterator.next();
if (next.getOffset() >= end)
break;
if (include(next)) {
if (!passAbsorber && isAbsorber(next))
break;
if (allowHidden && next instanceof ICompositeNode && (GrammarUtil.isDatatypeRuleCall(next.getGrammarElement()) || GrammarUtil.isEnumRuleCall(next.getGrammarElement()) || next.getGrammarElement() instanceof CrossReference)) {
NodeIterator ni = new NodeIterator(next);
while (ni.hasNext()) {
INode next2 = ni.next();
if (next2 instanceof ILeafNode && ((ILeafNode) next2).isHidden())
this.next.add(next2);
else
break;
}
}
iterator.prune();
this.next.add(next);
return result;
}
}
return result;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class CrossReferenceSerializer method isValid.
@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;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class LazyLinkerTest method newCrossReferenceAssignmentNode.
private INode newCrossReferenceAssignmentNode(final String feature) {
final LeafNode leafNode = new LeafNode();
final Assignment assignment = XtextFactory.eINSTANCE.createAssignment();
assignment.setFeature(feature);
final CrossReference crossReference = XtextFactory.eINSTANCE.createCrossReference();
assignment.setTerminal(crossReference);
leafNode.basicSetGrammarElement(crossReference);
return leafNode;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class PartialSerializer method updateSingleValue.
protected SerializationStrategy updateSingleValue(EObject object, EStructuralFeature feature, IAstRegion region) {
Preconditions.checkArgument(!feature.isMany());
Object value = object.eGet(feature);
EObject grammarElement = region.getGrammarElement();
if (feature instanceof EAttribute) {
if (grammarElement instanceof RuleCall) {
RuleCall rc = (RuleCall) grammarElement;
String newValue = valueSerializer.serializeAssignedValue(object, rc, value, null, errorAcceptor);
if (newValue != null) {
return new ReplaceRegionStrategy((ISemanticRegion) region, newValue);
}
}
return null;
} else if (feature instanceof EReference) {
if (((EReference) feature).isContainment()) {
IEObjectRegion reg = (IEObjectRegion) region;
EObject newEObject = (EObject) object.eGet(feature);
ISerializationContext newContext = getSerializationContext(newEObject);
ISerializationContext oldContext = getSerializationContext(reg);
if (!oldContext.equals(newContext)) {
return null;
}
return new SerializeRecursiveStrategy(reg, newEObject, newContext);
} else {
CrossReference cr = GrammarUtil.containingCrossReference(grammarElement);
if (cr != null) {
EObject target = (EObject) value;
String newValue = crossRefSerializer.serializeCrossRef(object, cr, target, null, errorAcceptor);
if (newValue != null) {
return new ReplaceRegionStrategy((ISemanticRegion) region, newValue);
}
}
}
return null;
}
return null;
}
Aggregations