Java 类org.eclipse.xtext.CrossReference 实例源码

项目:n4js    文件:TokenTypeRewriter.java   
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
        ImmutableMap.Builder<AbstractElement, Integer> builder) {
    ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
            ga.getBindingIdentifierRule(),
            ga.getIdentifierNameRule(),
            ga.getIDENTIFIERRule());
    for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
        for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
            if (obj instanceof Assignment) {
                Assignment assignment = (Assignment) obj;
                AbstractElement terminal = assignment.getTerminal();
                int type = InternalN4JSParser.RULE_IDENTIFIER;
                if (terminal instanceof CrossReference) {
                    terminal = ((CrossReference) terminal).getTerminal();
                    type = IDENTIFIER_REF_TOKEN;
                }
                if (terminal instanceof RuleCall) {
                    AbstractRule calledRule = ((RuleCall) terminal).getRule();
                    if (identifierRules.contains(calledRule)) {
                        builder.put(assignment, type);
                    }
                }
            }
        }
    }
}
项目:OCCI-Studio    文件:OCCICrossReferenceSerializer.java   
@Override
public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node,
        Acceptor errors) {
    if (((InternalEObject) target).eProxyURI() != null) {
        if (((InternalEObject) target).eProxyURI().toString().startsWith("#")) {
            return super.serializeCrossRef(semanticObject, crossref, getEObjectfromEProxy(semanticObject, target),
                    node, errors);
        }
    }

    return super.serializeCrossRef(semanticObject, crossref, target, node, errors);

}
项目:xtext-extras    文件:BrokenConstructorCallAwareEObjectAtOffsetHelper.java   
@Override
protected EObject resolveCrossReferencedElement(INode node) {
    EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
    if (referenceOwner != null) {
        EReference crossReference = GrammarUtil.getReference((CrossReference) node.getGrammarElement(),
                referenceOwner.eClass());
        if (!crossReference.isMany()) {
            EObject resultOrProxy = (EObject) referenceOwner.eGet(crossReference);
            if (resultOrProxy != null && resultOrProxy.eIsProxy() && crossReference == XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR) {
                if (referenceOwner instanceof XConstructorCall) {
                    JvmIdentifiableElement linkedType = batchTypeResolver.resolveTypes(referenceOwner).getLinkedFeature((XConstructorCall)referenceOwner);
                    if (linkedType != null)
                        return linkedType;
                }
            } 
            return resultOrProxy;
        } else {
            return super.resolveCrossReferencedElement(node);
        }
    }
    return null;
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
protected ILocationData getLocationWithoutTypeArguments(XAbstractFeatureCall call) {
    final ICompositeNode startNode = NodeModelUtils.getNode(call);
    if (startNode != null) {
        List<INode> resultNodes = Lists.newArrayList();
        if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall) {
            boolean featureReferenceSeen = false;
            for (INode child : startNode.getChildren()) {
                if (featureReferenceSeen) {
                    resultNodes.add(child);
                } else {
                    EObject grammarElement = child.getGrammarElement();
                    if (grammarElement instanceof CrossReference) {
                        Assignment assignment = GrammarUtil.containingAssignment(grammarElement);
                        if (assignment != null && "feature".equals(assignment.getFeature())) {
                            featureReferenceSeen = true;
                            resultNodes.add(child);
                        }
                    }
                }
            }
        }
        return toLocationData(resultNodes);
    }
    return null;
}
项目:xtext-extras    文件:XbaseIdeContentProposalProvider.java   
protected void createReceiverProposals(final XExpression receiver, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(receiver);
  final LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
  if (((receiverType == null) || receiverType.isPrimitiveVoid())) {
    return;
  }
  final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
  IScope scope = null;
  final EObject currentModel = context.getCurrentModel();
  if ((currentModel != receiver)) {
    if (((currentModel instanceof XMemberFeatureCall) && 
      (((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver))) {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(((XAbstractFeatureCall) currentModel)), crossReference);
    } else {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
    }
  } else {
    scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
  }
  this.getCrossrefProposalProvider().lookupCrossReference(scope, crossReference, context, acceptor, this.featureDescriptionPredicate);
}
项目:xtext-extras    文件:XbaseIdeContentProposalProvider.java   
public void createProposals(final AbstractElement assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if (assignment instanceof Assignment) {
    _createProposals((Assignment)assignment, context, acceptor);
    return;
  } else if (assignment instanceof CrossReference) {
    _createProposals((CrossReference)assignment, context, acceptor);
    return;
  } else if (assignment instanceof Keyword) {
    _createProposals((Keyword)assignment, context, acceptor);
    return;
  } else if (assignment instanceof RuleCall) {
    _createProposals((RuleCall)assignment, context, acceptor);
    return;
  } else if (assignment != null) {
    _createProposals(assignment, context, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(assignment, context, acceptor).toString());
  }
}
项目:dsl-devkit    文件:ParseTreeUtil.java   
/**
 * Returns the source text assigned to the given feature of the given object. Does not work for multi-valued features. Optionally also converts the source
 * text using the corresponding value converter. Conversion is only performed for keywords, rule call or cross reference grammar rules.
 * <p>
 * This method does not perform a check to make sure the feature matches the given object.
 *
 * @param object
 *          the semantic object
 * @param feature
 *          the feature to be considered when parsing the parse tree model
 * @param convert
 *          {@code true} if the parsed string needs conversion using its value converter
 * @return the parsed string from the node model
 */
public static String getParsedStringUnchecked(final EObject object, final EStructuralFeature feature, final boolean convert) {
  INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(object, feature), null);
  if (node != null) {
    if (convert) {
      final LazyLinkingResource res = (LazyLinkingResource) object.eResource();
      EObject grammarElement = node.getGrammarElement();
      if (res != null && (grammarElement instanceof Keyword || grammarElement instanceof RuleCall || grammarElement instanceof CrossReference)) {
        final DefaultLinkingService linkingService = (DefaultLinkingService) res.getLinkingService();
        return linkingService.getCrossRefNodeAsString(node);
      }
    }
    // result may contain escape sequences or quotes
    return NodeModelUtils.getTokenText(node);
  }
  return null;
}
项目:xtext-core    文件:SequenceFeeder.java   
protected void acceptRuleCall(RuleCall rc, Object value, String token, int index, INode node) {
    CrossReference crossRef = GrammarUtil.containingCrossReference(rc);
    if (crossRef != null) {
        if (rc.getRule() instanceof ParserRule)
            sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index,
                    getCompositeNode(node));
        else if (rc.getRule() instanceof TerminalRule)
            sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, getLeafNode(node));
        else if (rc.getRule() instanceof EnumRule)
            sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, getCompositeNode(node));
    } else {
        if (rc.getRule() instanceof ParserRule) {
            AbstractRule rule = rc.getRule();
            if (rule.getType() != null && rule.getType().getClassifier() instanceof EClass)
                acceptEObjectRuleCall(rc, (EObject) value, getCompositeNode(node));
            else
                sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, getCompositeNode(node));
        } else if (rc.getRule() instanceof TerminalRule)
            sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, getLeafNode(node));
        else if (rc.getRule() instanceof EnumRule)
            sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, getCompositeNode(node));
    }
}
项目:xtext-core    文件:IdeCrossrefProposalProvider.java   
public void lookupCrossReference(final IScope scope, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor, final Predicate<IEObjectDescription> filter) {
  try {
    Iterable<IEObjectDescription> _queryScope = this.queryScope(scope, crossReference, context);
    for (final IEObjectDescription candidate : _queryScope) {
      {
        boolean _canAcceptMoreProposals = acceptor.canAcceptMoreProposals();
        boolean _not = (!_canAcceptMoreProposals);
        if (_not) {
          return;
        }
        boolean _apply = filter.apply(candidate);
        if (_apply) {
          final ContentAssistEntry entry = this.createProposal(candidate, crossReference, context);
          acceptor.accept(entry, this.proposalPriorities.getCrossRefPriority(candidate, entry));
        }
      }
    }
  } catch (final Throwable _t) {
    if (_t instanceof UnsupportedOperationException) {
      final UnsupportedOperationException uoe = (UnsupportedOperationException)_t;
      IdeCrossrefProposalProvider.LOG.error("Failed to create content assist proposals for cross-reference.", uoe);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
项目:xtext-core    文件:IdeContentProposalProvider.java   
protected void createProposals(final AbstractElement assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if (assignment instanceof Assignment) {
    _createProposals((Assignment)assignment, context, acceptor);
    return;
  } else if (assignment instanceof CrossReference) {
    _createProposals((CrossReference)assignment, context, acceptor);
    return;
  } else if (assignment instanceof Keyword) {
    _createProposals((Keyword)assignment, context, acceptor);
    return;
  } else if (assignment instanceof RuleCall) {
    _createProposals((RuleCall)assignment, context, acceptor);
    return;
  } else if (assignment != null) {
    _createProposals(assignment, context, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(assignment, context, acceptor).toString());
  }
}
项目:xtext-core    文件:AbstractFormattingConfig.java   
protected List<AbstractElement> getAbstractElements(EObject obj) {
    if (obj instanceof AbstractElement)
        return Collections.singletonList((AbstractElement) obj);
    if (obj instanceof AbstractRule) {
        AbstractRule rule = (AbstractRule) obj;
        if (rule.getType().getClassifier() instanceof EClass)
            return Collections.singletonList(rule.getAlternatives());
        List<AbstractElement> result = Lists.newArrayList();
        for (RuleCall rc : grammarAccess.findRuleCalls(rule)) {
            CrossReference cr = GrammarUtil.containingCrossReference(rc);
            result.add(cr == null ? rc : cr);
        }
        return result;
    }
    return null;
}
项目:xtext-core    文件:AbstractAntlrGrammarGenerator.java   
protected String _crossrefEbnf(final RuleCall it, final CrossReference ref, final boolean supportActions) {
  String _xblockexpression = null;
  {
    final AbstractRule rule = it.getRule();
    if ((rule instanceof ParserRule)) {
      ParserRule _originalElement = AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule)rule));
      boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(((AbstractRule) _originalElement));
      boolean _not = (!_isDatatypeRule);
      if (_not) {
        throw new IllegalStateException("crossrefEbnf is not supported for ParserRule that is not a datatype rule");
      }
    }
    _xblockexpression = this.crossrefEbnf(rule, it, ref, supportActions);
  }
  return _xblockexpression;
}
项目:n4js    文件:GrammarPrettyPrinter.java   
@Override
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref,
        EObject target, IScope scope, Acceptor errors) {
    if (target instanceof AbstractRule) {
        return ((AbstractRule) target).getName();
    }
    if (target instanceof ENamedElement) {
        return ((ENamedElement) target).getName();
    }
    return super.getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
项目:n4js    文件:N4JSLinker.java   
/**
 * Installs proxies for all non containment references and only if the node representing the EObject that contains
 * the cross reference has got leaf nodes (as a leaf node represents the cross reference).
 *
 * @param resource
 *            the N4JSResource
 * @param obj
 *            the EObject containing the cross reference
 * @param producer
 *            the error/warning producer
 * @param parentNode
 *            the node representing obj inside the node model
 */
private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer,
        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() + "'.");
            }
            createAndSetProxy(resource, obj, node, eRef, crossReference, producer);
            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(resource, obj, producer, (ICompositeNode) node, true);
            }
        }
    }
    if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
        installProxies(resource, obj, producer, parentNode.getParent(), dontCheckParent);
    }
}
项目:n4js    文件:N4JSLinker.java   
/**
 * Creates a proxy instance that will later on allow to lazily resolve the semantically referenced instance for the
 * given {@link CrossReference xref}.
 */
@SuppressWarnings("unchecked")
private void createAndSetProxy(N4JSResource resource, EObject obj, INode node, EReference eRef,
        CrossReference xref,
        IDiagnosticProducer diagnosticProducer) {
    final EObject proxy = createProxy(resource, obj, node, eRef, xref, diagnosticProducer);
    proxy.eSetDeliver(false);
    if (eRef.isMany()) {
        ((InternalEList<EObject>) obj.eGet(eRef, false)).addUnique(proxy);
    } else {
        obj.eSet(eRef, proxy);
    }
}
项目:xtext-core    文件:SequenceFeeder.java   
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);
}
项目:xtext-core    文件:ContentAssistFragment2.java   
private StringConcatenationClient assignmentTerminal(final AbstractElement alternatives, final StringConcatenationClient accessor) {
  if (alternatives instanceof Alternatives) {
    return _assignmentTerminal((Alternatives)alternatives, accessor);
  } else if (alternatives instanceof CrossReference) {
    return _assignmentTerminal((CrossReference)alternatives, accessor);
  } else if (alternatives instanceof RuleCall) {
    return _assignmentTerminal((RuleCall)alternatives, accessor);
  } else if (alternatives != null) {
    return _assignmentTerminal(alternatives, accessor);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(alternatives, accessor).toString());
  }
}
项目:xtext-core    文件:MatcherNFAProvider.java   
@Override
public boolean filter(AbstractElement grammarElement) {
    if (grammarElement instanceof CrossReference)
        return false;
    if (isContainedInCrossReference(grammarElement))
        return true;
    if (grammarElement instanceof Keyword)
        return false;
    if (grammarElement instanceof RuleCall)
        return false;
    return true;
}
项目:xtext-extras    文件:XbaseIdeCrossrefProposalProvider.java   
protected boolean hasIdRule(final CrossReference crossRef) {
  AbstractElement _terminal = crossRef.getTerminal();
  if ((_terminal instanceof RuleCall)) {
    AbstractElement _terminal_1 = crossRef.getTerminal();
    final String ruleName = ((RuleCall) _terminal_1).getRule().getName();
    return ((Objects.equal(ruleName, "IdOrSuper") || Objects.equal(ruleName, "ValidID")) || Objects.equal(ruleName, "FeatureCallID"));
  }
  return false;
}
项目:dsl-devkit    文件:AbstractScopingTest.java   
/**
 * Returns the referenced {@link EObject} pointed to by the cross reference.
 * <p>
 * <em>Note</em>: For implicit item traversal to work, a custom implementation must be provided by overriding this method.
 * </p>
 *
 * @param sourceTag
 *          the source tag
 * @param traverseImplicitItems
 *          If target of a reference is an implicit item and this parameter is set to true, the test will get and compare the original object from which this
 *          implicit item was created.
 * @param crossReference
 *          Cross reference to be resolved, must not be {@code null}
 * @return the referenced {@link EObject}, must not be {@code null}
 */
protected EObject getCrossReferencedObject(final int sourceTag, final boolean traverseImplicitItems, final CrossReference crossReference) {
  EObject context = getObjectForTag(sourceTag);
  if (crossReference == null) {
    throw new IllegalArgumentException(NLS.bind("Cross reference on object ''{0}'' could not be resolved.", context.toString())); //$NON-NLS-1$
  }
  // We only handle references in assignments
  Assignment assignment = EObjectUtil.eContainer(crossReference, Assignment.class);
  EObject sourceObject = null;
  String featureName = assignment.getFeature();
  EReference reference = (EReference) context.eClass().getEStructuralFeature(featureName);
  if (reference.isMany()) {
    Object featureValue = context.eGet(reference, false);
    assertTrue("List must be of type EObjectResolvingEList", featureValue instanceof EObjectResolvingEList); //$NON-NLS-1$
    @SuppressWarnings("unchecked")
    EObjectResolvingEList<? extends EObject> objects = (EObjectResolvingEList<? extends EObject>) context.eGet(reference, false);
    if (objects.size() == 1) {
      sourceObject = EcoreUtil.resolve(objects.get(0), context);
    } else {
      // TODO DSL-166: Handle this case when needed for tests.
      fail("Multiple references not supported yet"); //$NON-NLS-1$
    }
  } else {
    sourceObject = (EObject) context.eGet(reference, true);
  }
  assertNotNull("Bad test. Referenced object is null.", sourceObject); //$NON-NLS-1$
  return sourceObject;
}
项目:xtext-extras    文件:GrammarAccessUtil.java   
private static List<String> getSingleElementDescription(AbstractElement ele) {
    if (ele instanceof Keyword)
        return Collections.singletonList(((Keyword) ele).getValue());
    else if (ele instanceof Assignment)
        return Collections.singletonList(((Assignment) ele).getFeature());
    else if (ele instanceof RuleCall)
        return Collections.singletonList(((RuleCall) ele).getRule()
                .getName());
    else if (ele instanceof Action) {
        Action a = (Action) ele;
        ArrayList<String> r = new ArrayList<String>();
        if (a.getType() != null && a.getType().getClassifier() != null)
            r.add(a.getType().getClassifier().getName());
        if (a.getFeature() != null && !"".equals(a.getFeature()))
            r.add(a.getFeature());
        return r;
    } else if (ele instanceof CrossReference) {
        CrossReference cr = (CrossReference) ele;
        if (cr.getType() != null && cr.getType().getClassifier() != null)
            return Collections.singletonList(cr.getType().getClassifier()
                    .getName());
    } else if (ele instanceof EnumLiteralDeclaration) {
        EnumLiteralDeclaration decl = (EnumLiteralDeclaration) ele;
        return Collections.singletonList(decl.getEnumLiteral().getName());
    }
    return Collections.emptyList();
}
项目:xtext-core    文件:NodeSemanticRegion.java   
@Override
public EObject getGrammarElement() {
    EObject element = super.getGrammarElement();
    if (element instanceof CrossReference)
        return ((CrossReference) element).getTerminal();
    return element;
}
项目:xtext-core    文件:NodeModelBasedRegionAccessBuilder.java   
protected boolean include(INode node) {
    if (node instanceof ILeafNode) {
        return true;
    } else if (node instanceof ICompositeNode) {
        EObject element = node.getGrammarElement();
        return GrammarUtil.isDatatypeRuleCall(element) || element instanceof CrossReference
                || GrammarUtil.isEnumRuleCall(element);
    }
    return false;
}
项目:xtext-core    文件:AntlrContentAssistGrammarGenerator.java   
protected String _crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) {
  boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it));
  if (_isDatatypeRule) {
    return this._grammarAccessExtensions.ruleName(it);
  }
  String _name = it.getName();
  String _plus = (_name + " is not a datatype rule");
  throw new IllegalArgumentException(_plus);
}
项目:xtext-core    文件:CrossReferenceSerializer.java   
@Override
public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node,
        Acceptor errors) {
    if ((target == null || target.eIsProxy()) && node != null)
        return tokenUtil.serializeNode(node);

    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 null;
    }

    if (target != null && target.eIsProxy()) {
        target = handleProxy(target, semanticObject, ref);
    }

    if (target != null && node != null) {
        String text = linkingHelper.getCrossRefNodeAsString(node, true);
        QualifiedName qn = qualifiedNameConverter.toQualifiedName(text);
        URI targetURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(target);
        for (IEObjectDescription desc : scope.getElements(qn)) {
            if (targetURI.equals(desc.getEObjectURI()))
                return tokenUtil.serializeNode(node);
        }
    }

    return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
项目:xtext-core    文件:LazyLinker.java   
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);
    }
}
项目:xtext-core    文件:XtextParserTest.java   
@Test public void testParseCrossRef() throws Exception {
        Grammar model = (Grammar) getModel("grammar foo with org.eclipse.xtext.common.Terminals " +
                "generate foo 'bar' as boo " +
                "Model returns boo::Model : 'a' stuff+=Stuff*; " +
                "Stuff returns boo::Stuff : 'stuff' name=ID refersTo=[boo::Stuff];");
        AbstractRule rule = model.getRules().get(1);
        Group group = (Group) rule.getAlternatives();
        Assignment assignment = (Assignment) group.getElements().get(2);
        CrossReference reference = (CrossReference) assignment.getTerminal();
        assertEquals("boo", reference.getType().getMetamodel().getAlias());
//      assertWithXtend("'boo'", "eAllContents.typeSelect(xtext::CrossReference).first().type.metamodel.alias", model);
        assertEquals("Stuff", reference.getType().getClassifier().getName());
//      assertWithXtend("'Stuff'", "eAllContents.typeSelect(xtext::CrossReference).first().type.classifier.name", model);
    }
项目:xtext-core    文件:AntlrContentAssistGrammarGenerator.java   
protected String crossrefEbnf(final AbstractElement it, final CrossReference ref, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _crossrefEbnf((Alternatives)it, ref, supportActions);
  } else if (it instanceof RuleCall) {
    return _crossrefEbnf((RuleCall)it, ref, supportActions);
  } else if (it != null) {
    return _crossrefEbnf(it, ref, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, ref, supportActions).toString());
  }
}
项目:xtext-core    文件:MatcherNFAProvider.java   
protected boolean isContainedInCrossReference(EObject obj) {
    EObject cnt = obj.eContainer();
    if (cnt == null)
        return false;
    if (cnt instanceof CrossReference)
        return true;
    if (cnt instanceof Group)
        return false;
    return isContainedInCrossReference(cnt);
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkCrossReferenceNotInAlternatives(Alternatives alternatives) {
    int numOfCrossRefs = IterableExtensions.size(IterableExtensions.filter(alternatives.getElements(), CrossReference.class));
    if (numOfCrossRefs > 1) {
        String errorMessage = "Cross references using the pattern 'feature=([SomeClass|ID] | [SomeClass|STRING])' are not allowed."
                + " Use the pattern '(feature=[SomeClass|ID] | feature=[SomeClass|STRING])' instead.";
        error(errorMessage, alternatives, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, CROSS_REFERENCE_IN_ALTERNATIVES);
    }
}
项目:xtext-core    文件:CallHierarchyHelper.java   
@Override
public Boolean caseCrossReference(CrossReference object) {
    if (!checkFurther(object))
        return result;
    if (doSwitch(object.getTerminal()))
        return true;
    if (GrammarUtil.isMultipleCardinality(object)) {
        if (!checkFurther(object))
            return result;
        if (doSwitch(object.getTerminal()))
            return true;
    }
    return Boolean.FALSE;
}
项目:xtext-core    文件:AbstractParseTreeConstructor.java   
@Override
protected String serializeInternal(INode node) {
    if (type == null)
        return null;
    switch (type) {
        case CROSS_REFERENCE:
            String ref = crossRefSerializer.serializeCrossRef(eObjectConsumer.getEObject(),
                    (CrossReference) element, (EObject) value, node);
            if (ref == null) {
                Assignment ass = GrammarUtil.containingAssignment(element);
                throw new XtextSerializationException("Could not serialize cross reference from "
                        + EmfFormatter.objPath(eObjectConsumer.getEObject()) + "." + ass.getFeature() + " to "
                        + EmfFormatter.objPath((EObject) value));
            }
            return ref;
        case KEYWORD:
            return keywordSerializer.serializeAssignedKeyword(eObjectConsumer.getEObject(),
                    ((Keyword) element), value, node);
        case TERMINAL_RULE_CALL:
            return valueSerializer.serializeAssignedValue(eObjectConsumer.getEObject(), (RuleCall) element,
                    value, node);
        case ENUM_RULE_CALL:
            return enumLitSerializer.serializeAssignedEnumLiteral(eObjectConsumer.getEObject(),
                    (RuleCall) element, value, node);
        case PARSER_RULE_CALL:
            return null;
        case DATATYPE_RULE_CALL:
            return valueSerializer.serializeAssignedValue(eObjectConsumer.getEObject(), (RuleCall) element,
                    value, node);
        default:
            return null;
    }
}
项目:xtext-core    文件:TokenUtil.java   
public AbstractRule getTokenRule(INode node) {
    if (node == null)
        return null;
    EObject element = node.getGrammarElement();
    if (element instanceof AbstractRule)
        return (AbstractRule) element;
    if (element instanceof CrossReference)
        element = ((CrossReference) element).getTerminal();
    if (element instanceof RuleCall)
        return ((RuleCall) element).getRule();
    return null;
}
项目:n4js    文件:AbstractN4JSProposalProvider.java   
public void completeExportFromClause_ReexportedFrom(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}
项目:n4js    文件:AbstractN4JSProposalProvider.java   
public void completeImportDeclarationImpl_Module(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}
项目:n4js    文件:AbstractN4JSProposalProvider.java   
public void completeNamedImportSpecifier_ImportedElement(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}
项目:n4js    文件:AbstractN4JSProposalProvider.java   
public void completeDefaultImportSpecifier_ImportedElement(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}
项目:n4js    文件:AbstractN4JSProposalProvider.java   
public void completeLetIdentifierRef_Id(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}
项目:n4js    文件:AbstractN4JSProposalProvider.java   
public void completeContinueStatement_Label(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}
项目:n4js    文件:AbstractN4JSProposalProvider.java   
public void completeBreakStatement_Label(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}