Java 类org.eclipse.xtext.linking.impl.IllegalNodeException 实例源码

项目:xtext-core    文件:XtextLinkingService.java   
private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException {
    final ICompositeNode parentNode = text.getParent();
    BidiIterator<INode> iterator = parentNode.getChildren().iterator();
    while(iterator.hasPrevious()) {
        INode child = iterator.previous();
        if (child instanceof ILeafNode) {
            ILeafNode leaf = (ILeafNode) child;
            if (text == leaf)
                return super.getLinkedObjects(context, ref, text);
            if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) {
                IScope scope = getScope(context, ref);
                return XtextMetamodelReferenceHelper.findBestMetamodelForType(
                        context, text.getText(), leaf.getText(), scope);
            }
        }
    }
    return Collections.emptyList();
}
项目:gama    文件:GamlLinkingService.java   
/**
 * Override default in order to supply a stub object. If the default implementation isn't able to resolve the link,
 * assume it to be a local resource.
 */
@Override
public List<EObject> getLinkedObjects(final EObject context, final EReference ref, final INode node)
        throws IllegalNodeException {
    final List<EObject> result = super.getLinkedObjects(context, ref, node);
    // If the default implementation resolved the link, return it
    if (null != result && !result.isEmpty()) { return result; }
    final String name = getCrossRefNodeAsString(node);
    if (GamlPackage.eINSTANCE.getTypeDefinition()
            .isSuperTypeOf(ref.getEReferenceType())) { return addSymbol(name, ref.getEReferenceType()); }
    if (GamlPackage.eINSTANCE.getVarDefinition().isSuperTypeOf(ref.getEReferenceType())) {
        if (name.startsWith("pref_"))
            return addSymbol(name, ref.getEReferenceType());
    }
    final GamlResource resource = (GamlResource) context.eResource();
    final IExecutionContext additionalContext = resource.getCache().getOrCreate(resource).get("linking");
    if (additionalContext != null) {
        if (additionalContext.hasLocalVar(name))
            return Collections.singletonList(create(name, ref.getEReferenceType()));
    }
    return Collections.EMPTY_LIST;
}
项目:DialogScriptDSL    文件:CustomLinkingDiagnosticMessageProvider.java   
public DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context) {
  EReference _reference = context.getReference();
  final EClass referenceType = _reference.getEReferenceType();
  String linkText = "";
  try {
    String _linkText = context.getLinkText();
    linkText = _linkText;
  } catch (final Throwable _t) {
    if (_t instanceof IllegalNodeException) {
      final IllegalNodeException e = (IllegalNodeException)_t;
      INode _node = e.getNode();
      String _text = _node.getText();
      linkText = _text;
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
  String _name = referenceType.getName();
  String _plus = ("Couldn\'t resolve reference to " + _name);
  String _plus_1 = (_plus + " \'");
  String _plus_2 = (_plus_1 + linkText);
  final String msg = (_plus_2 + "\'.");
  String _name_1 = referenceType.getName();
  DiagnosticMessage _diagnosticMessage = new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC, _name_1, linkText);
  return _diagnosticMessage;
}
项目:n4js    文件:ErrorAwareLinkingService.java   
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
    final EClass requiredType = ref.getEReferenceType();
    if (requiredType == null)
        return Collections.<EObject> emptyList();

    final String crossRefString = getCrossRefNodeAsString(context, ref, node);
    if (crossRefString != null && !crossRefString.equals("")) {
        final IScope scope = getScope(context, ref);
        QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
        IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
        if (IEObjectDescriptionWithError.isErrorDescription(eObjectDescription) && context.eResource() != null
                && !n4jsCore.isNoValidate(context.eResource().getURI())) {
            addError(context, node, IEObjectDescriptionWithError.getDescriptionWithError(eObjectDescription));
        } else if (eObjectDescription instanceof UnresolvableObjectDescription) {
            return Collections.<EObject> singletonList((EObject) context.eGet(ref, false));
        }
        if (eObjectDescription != null) {
            EObject candidate = eObjectDescription.getEObjectOrProxy();
            if (!candidate.eIsProxy() && candidate.eResource() == null) {
                // Error is necessary since EMF catches all exceptions in EcoreUtil#resolve
                throw new AssertionError("Found an instance without resource and without URI");
            }
            return Collections.singletonList(candidate);
        }
    }
    return Collections.emptyList();
}
项目:xtext-extras    文件:ScopeProviderAccess.java   
/**
 * Returns a bunch of descriptions most of which are actually {@link IIdentifiableElementDescription describing identifiables}. 
 * The provided iterable is never empty but it may contain a single {@link ErrorDescription error description}.
 * 
 * @return the available descriptions.
 */
public Iterable<IEObjectDescription> getCandidateDescriptions(XExpression expression, EReference reference, /* @Nullable */ EObject toBeLinked,
        IFeatureScopeSession session, IResolvedTypes types) throws IllegalNodeException {
    if (toBeLinked == null) {
        return Collections.emptyList();
    }
    if (!toBeLinked.eIsProxy()) {
        throw new IllegalStateException(expression + " was already linked to " + toBeLinked);
    }
    URI uri = EcoreUtil.getURI(toBeLinked);
    String fragment = uri.fragment();
    if (encoder.isCrossLinkFragment(expression.eResource(), fragment)) {
        INode node = encoder.getNode(expression, fragment);
        final EClass requiredType = reference.getEReferenceType();
        if (requiredType == null)
            return Collections.emptyList();

        final String crossRefString = linkingHelper.getCrossRefNodeAsString(node, true);
        if (crossRefString != null && !crossRefString.equals("")) {
            QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
            if (!qualifiedLinkName.isEmpty()) {
                final IScope scope = session.getScope(expression, reference, types);
                Iterable<IEObjectDescription> descriptions = scope.getElements(qualifiedLinkName);
                if (Iterables.isEmpty(descriptions)) {
                    INode errorNode = getErrorNode(expression, node);
                    if (errorNode != node) {
                        qualifiedLinkName = getErrorName(errorNode);
                    }
                    return Collections.<IEObjectDescription>singletonList(new ErrorDescription(getErrorNode(expression, node), qualifiedLinkName));
                }
                return descriptions;
            } else {
                return Collections.<IEObjectDescription>singletonList(new ErrorDescription(null /* followUp problem */));
            }
        }
        return Collections.emptyList();
    } else {
        throw new IllegalStateException(expression + " uses unsupported uri fragment " + uri);
    }
}
项目:xtext-core    文件:XtextLinkingService.java   
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
    if (ref == XtextPackage.eINSTANCE.getGrammar_UsedGrammars())
        return getUsedGrammar((Grammar) context, node);
    if (ref == XtextPackage.eINSTANCE.getTypeRef_Metamodel())
        return getLinkedMetaModel((TypeRef)context, ref, (ILeafNode) node);
    if (ref == XtextPackage.eINSTANCE.getAbstractMetamodelDeclaration_EPackage() && context instanceof GeneratedMetamodel)
        return createPackage((GeneratedMetamodel) context, (ILeafNode) node);
    if (ref == XtextPackage.eINSTANCE.getAbstractMetamodelDeclaration_EPackage() && context instanceof ReferencedMetamodel)
        return getPackage((ReferencedMetamodel)context, (ILeafNode) node);
    return super.getLinkedObjects(context, ref, node);
}
项目:xtext-core    文件:LazyLinkingResource.java   
/**
 * @since 2.3
 */
protected void createAndAddDiagnostic(Triple<EObject, EReference, INode> triple, IllegalNodeException ex) {
    if (isValidationDisabled())
        return;
    ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticMessageContext(triple);
    DiagnosticMessage message = linkingDiagnosticMessageProvider.getIllegalNodeMessage(context, ex);
    if (message != null) {
        List<Diagnostic> list = getDiagnosticList(message);
        Diagnostic diagnostic = createDiagnostic(triple, message);
        if (!list.contains(diagnostic))
            list.add(diagnostic);
    }
}
项目:xtext-core    文件:CrossRefTest.java   
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
    if (oneOffResult != null) {
        List<EObject> result = Lists.newArrayList(oneOffResult);
        oneOffResult = null;
        return result;
    }
    return super.getLinkedObjects(context, ref, node);
}
项目:CooperateModelingEnvironment    文件:CooperateLinkingService.java   
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
    if (getUnqualifiedNameReferences().contains(ref)) {
        final String crossRefString = getCrossRefNodeAsString(node);
        if (!Strings.isNullOrEmpty(crossRefString)) {
            final IScope scope = getScope(context, ref);
            QualifiedName qualifiedLinkName =  QualifiedName.create(crossRefString);
            IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
            if (eObjectDescription != null) {
                return Collections.singletonList(eObjectDescription.getEObjectOrProxy());                   
            }
        }
    }
    return super.getLinkedObjects(context, ref, node);
}
项目:sadlos2    文件:ErrorAddingLinkingService.java   
/**
 * @return the first element returned from the injected {@link IScopeProvider} which matches the text of the passed
 *         {@link INode node}
 */
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node)
        throws IllegalNodeException {
    final EClass requiredType = ref.getEReferenceType();
    if (requiredType == null)
        return Collections.<EObject> emptyList();

    final String crossRefString = getCrossRefNodeAsString(node);
    if (crossRefString != null && !crossRefString.equals("")) {
        if (logger.isDebugEnabled()) {
            logger.debug("before getLinkedObjects: node: '" + crossRefString + "'");
        }
        if (SadlASTUtils.isUnit(context)) {
            return Collections.emptyList();
        }
        final IScope scope = getScope(context, ref);
        QualifiedName qualifiedLinkName =  qualifiedNameConverter.toQualifiedName(crossRefString);
        IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
        if (logger.isDebugEnabled()) {
            logger.debug("after getLinkedObjects: node: '" + crossRefString + "' result: " + eObjectDescription);
        }
        if (eObjectDescription != null) {
            String errorMessage = eObjectDescription.getUserData(AMBIGUOUS_NAME_ERROR);
            if (errorMessage != null) {
                createAndAddDiagnostic(context.eResource(), node, errorMessage, eObjectDescription.getUserData(AMBIGUOUS_NAME_ALTERNATIVES));
            }
            List<EObject> results = Collections.singletonList(eObjectDescription.getEObjectOrProxy());
            return results;
        }
    }
    return Collections.emptyList();
}
项目:smaccm    文件:ResoluteLinkingService.java   
@Override
public List<EObject> getLinkedObjects(EObject context, EReference reference, INode node)
        throws IllegalNodeException {
    String name = getCrossRefNodeAsString(node);
    EObject e = getLinkedObject(context, reference, name);
    if (e != null) {
        return Collections.singletonList(e);
    }
    return super.getLinkedObjects(context, reference, node);
}
项目:xtext-extras    文件:UnresolvedFeatureCallTypeAwareMessageProvider.java   
@Override
public DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context) {
  String _xtrycatchfinallyexpression = null;
  try {
    _xtrycatchfinallyexpression = context.getLinkText();
  } catch (final Throwable _t) {
    if (_t instanceof IllegalNodeException) {
      final IllegalNodeException e = (IllegalNodeException)_t;
      _xtrycatchfinallyexpression = e.getNode().getText();
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
  String linkText = _xtrycatchfinallyexpression;
  if ((linkText == null)) {
    return null;
  }
  EObject contextObject = context.getContext();
  boolean _isStaticMemberCallTarget = this.isStaticMemberCallTarget(contextObject);
  if (_isStaticMemberCallTarget) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append(linkText);
    _builder.append(" cannot be resolved to a type.");
    return new DiagnosticMessage(_builder.toString(), Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC, 
      UnresolvedFeatureCallTypeAwareMessageProvider.TYPE_LITERAL);
  }
  if ((contextObject instanceof XAbstractFeatureCall)) {
    boolean _isOperation = ((XAbstractFeatureCall)contextObject).isOperation();
    boolean _not = (!_isOperation);
    if (_not) {
      return this.handleUnresolvedFeatureCall(context, ((XAbstractFeatureCall)contextObject), linkText);
    }
  }
  EClass referenceType = context.getReference().getEReferenceType();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append(linkText);
  _builder_1.append(" cannot be resolved");
  String _typeName = this.getTypeName(referenceType, context.getReference());
  _builder_1.append(_typeName);
  _builder_1.append(".");
  final String msg = _builder_1.toString();
  return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC, linkText);
}
项目:xtext-core    文件:LazyLinkingResource.java   
/**
 * @since 2.4
 */
protected EObject getEObject(String uriFragment, Triple<EObject, EReference, INode> triple) throws AssertionError {
    if (!resolving.add(triple))
        return handleCyclicResolution(triple);
    try {
        Set<String> unresolveableProxies = getUnresolvableURIFragments();
        if (unresolveableProxies.contains(uriFragment))
            return null;
        EReference reference = triple.getSecond();
        try {
            List<EObject> linkedObjects = getLinkingService().getLinkedObjects(
                    triple.getFirst(), 
                    reference,
                    triple.getThird());

            if (linkedObjects.isEmpty()) {
                if (isUnresolveableProxyCacheable(triple))
                    unresolveableProxies.add(uriFragment);
                createAndAddDiagnostic(triple);
                return null;
            }
            if (linkedObjects.size() > 1)
                throw new IllegalStateException("linkingService returned more than one object for fragment "
                        + uriFragment);
            EObject result = linkedObjects.get(0);
            if (!EcoreUtil2.isAssignableFrom(reference.getEReferenceType(), result.eClass())) {
                log.error("An element of type " + result.getClass().getName()
                        + " is not assignable to the reference " + reference.getEContainingClass().getName()
                        + "." + reference.getName());
                if (isUnresolveableProxyCacheable(triple))
                    unresolveableProxies.add(uriFragment);
                createAndAddDiagnostic(triple);
                return null;
            }
            // remove previously added error markers, since everything should be fine now
            unresolveableProxies.remove(uriFragment);
            removeDiagnostic(triple);
            return result;
        } catch (CyclicLinkingException e) {
            if (e.triple.equals(triple)) {
                log.error(e.getMessage(), e);
                if (isUnresolveableProxyCacheable(triple))
                    unresolveableProxies.add(uriFragment);
                createAndAddDiagnostic(triple);
                return null;
            } else {
                throw e;
            }
        }
    } catch (IllegalNodeException ex) {
        createAndAddDiagnostic(triple, ex);
        return null;
    } finally {
        resolving.remove(triple);
    }
}
项目:gama    文件:GamlLinkingErrorMessageProvider.java   
@Override
public DiagnosticMessage getIllegalNodeMessage(final ILinkingDiagnosticContext context,
        final IllegalNodeException ex) {
    final String message = ex.getMessage();
    return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
}
项目:smaccm    文件:AgreeLinkingService.java   
@Override
   public List<EObject> getLinkedObjects(EObject context, EReference reference, INode node)
           throws IllegalNodeException {
       String name = getCrossRefNodeAsString(node);
       //TODO This will have to be changed in the develop branch
       name = name.replaceAll("::", ".");

       if (context instanceof PropertyValue) {
           return findUnitLiteralAsList((Element) context, name);
       }

       if (context instanceof NestedDotID
               || context instanceof NodeEq
               || context instanceof SynchStatement
               || context instanceof RecordExpr
               || context instanceof RecordType
               || context instanceof GetPropertyExpr
               || context instanceof RecordUpdateExpr
               || context instanceof EventExpr
               || context instanceof OrderStatement
               || context instanceof ConnectionStatement) {

           //EObject e = findClassifier(context, reference, name);
        EObject e = getIndexedObject(context, reference, name);

           //hack to fix some strange linking behavior by osate
           if(e instanceof DataType){
            e = null;
           }
           if (e != null) {
               return Collections.singletonList(e);
           }

           // This code will only link to objects in the projects visible from the current project
           Iterable<IEObjectDescription> allObjectTypes = EMFIndexRetrieval
                   .getAllEObjectsOfTypeInWorkspace(context, reference.getEReferenceType());

        String contextProject = context.eResource().getURI().segment(1);
        List<String> visibleProjects = getVisibleProjects(contextProject);

        for (IEObjectDescription eod : allObjectTypes) {
            if (isVisible(eod, visibleProjects)) {
                EObject res = eod.getEObjectOrProxy();
                res = EcoreUtil.resolve(res, context.eResource().getResourceSet());
                if (res.eContainer() instanceof EnumStatement && res instanceof NamedID) {
                    // special code for AGREE enumerated types
                    if (((NamedID) res).getName().equals(name)) {
                        return Collections.singletonList(res);
                    }
                }
                if (sameName(eod, name)) {
                    if (!Aadl2Util.isNull(res)) {
                        return Collections.singletonList(res);
                    }
                }
            }
        }
    }

    return super.getLinkedObjects(context, reference, node);
}
项目:xtext-core    文件:ILinkingService.java   
/**
 * Returns all {@link EObject}s referenced by the given link text in the
 * given context. But does not set the references or modifies the passed
 * information somehow. The returned list might contain proxy instances.
 */
List<EObject> getLinkedObjects(EObject context, EReference reference, INode node) throws IllegalNodeException;
项目:xtext-core    文件:ILinkingDiagnosticMessageProvider.java   
DiagnosticMessage getIllegalNodeMessage(ILinkingDiagnosticContext context, IllegalNodeException ex);