Search in sources :

Example 11 with CrossReference

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;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) CrossReference(org.eclipse.xtext.CrossReference) EReference(org.eclipse.emf.ecore.EReference)

Example 12 with CrossReference

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;
}
Also used : NodeIterator(org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) CrossReference(org.eclipse.xtext.CrossReference)

Example 13 with CrossReference

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;
}
Also used : CrossReference(org.eclipse.xtext.CrossReference) IScope(org.eclipse.xtext.scoping.IScope) EReference(org.eclipse.emf.ecore.EReference)

Example 14 with CrossReference

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;
}
Also used : Assignment(org.eclipse.xtext.Assignment) LeafNode(org.eclipse.xtext.nodemodel.LeafNode) CrossReference(org.eclipse.xtext.CrossReference)

Example 15 with CrossReference

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;
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) EObject(org.eclipse.emf.ecore.EObject) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) RuleCall(org.eclipse.xtext.RuleCall) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

CrossReference (org.eclipse.xtext.CrossReference)29 RuleCall (org.eclipse.xtext.RuleCall)13 EObject (org.eclipse.emf.ecore.EObject)12 AbstractRule (org.eclipse.xtext.AbstractRule)9 ParserRule (org.eclipse.xtext.ParserRule)8 EReference (org.eclipse.emf.ecore.EReference)7 Assignment (org.eclipse.xtext.Assignment)7 TypeRef (org.eclipse.xtext.TypeRef)7 Test (org.junit.Test)7 AbstractElement (org.eclipse.xtext.AbstractElement)6 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)6 INode (org.eclipse.xtext.nodemodel.INode)6 Action (org.eclipse.xtext.Action)5 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 TerminalRule (org.eclipse.xtext.TerminalRule)4 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)4 ArrayList (java.util.ArrayList)3 EClass (org.eclipse.emf.ecore.EClass)3 EnumRule (org.eclipse.xtext.EnumRule)3 Keyword (org.eclipse.xtext.Keyword)3