Search in sources :

Example 1 with IAmbiguousLinkingCandidate

use of org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate in project xtext-xtend by eclipse.

the class AmbiguityValidationTest method assertAmbiguous.

protected void assertAmbiguous(final CharSequence contents, final String... messageParts) {
    final XtendFile file = this.getParsedXtendFile(contents);
    final EList<Resource.Diagnostic> errors = file.eResource().getErrors();
    Assert.assertEquals(errors.toString(), 1, errors.size());
    Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(errors);
    final AbstractDiagnostic singleError = ((AbstractDiagnostic) _head);
    Assert.assertEquals(singleError.getMessage(), IssueCodes.AMBIGUOUS_FEATURE_CALL, singleError.getCode());
    final Function1<String, String> _function = (String it) -> {
        return Strings.toUnixLineSeparator(it);
    };
    final Consumer<String> _function_1 = (String it) -> {
        final String message = singleError.getMessage();
        boolean _contains = message.contains(it);
        boolean _not = (!_contains);
        if (_not) {
            Assert.assertEquals(it, message);
        }
    };
    ListExtensions.<String, String>map(((List<String>) Conversions.doWrapArray(messageParts)), _function).forEach(_function_1);
    final XtendTypeDeclaration firstType = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _head_1 = IterableExtensions.<XtendMember>head(firstType.getMembers());
    final XtendFunction firstMember = ((XtendFunction) _head_1);
    XExpression _expression = firstMember.getExpression();
    final XBlockExpression block = ((XBlockExpression) _expression);
    XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions());
    final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
    final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
    Assert.assertTrue((linkingCandidate instanceof IAmbiguousLinkingCandidate));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Resource(org.eclipse.emf.ecore.resource.Resource) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) IAmbiguousLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)

Example 2 with IAmbiguousLinkingCandidate

use of org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate in project xtext-xtend by eclipse.

the class XtendHyperlinkHelper method createHyperlinksForCrossRef.

@Override
protected void createHyperlinksForCrossRef(XtextResource resource, INode crossRefNode, IHyperlinkAcceptor acceptor) {
    EObject crossLinkedEObject = getEObjectAtOffsetHelper().getCrossReferencedElement(crossRefNode);
    if (crossLinkedEObject != null && !crossLinkedEObject.eIsProxy()) {
        EObject containedElementAt = getEObjectAtOffsetHelper().resolveContainedElementAt(resource, crossRefNode.getOffset());
        if (containedElementAt instanceof XAbstractFeatureCall) {
            XAbstractFeatureCall casted = (XAbstractFeatureCall) containedElementAt;
            if (casted.getFeature() == crossLinkedEObject) {
                IFeatureLinkingCandidate candidate = getBatchTypeResolver().resolveTypes(casted).getLinkingCandidate(casted);
                if (candidate instanceof IAmbiguousLinkingCandidate) {
                    createMultipleLinks(resource, crossRefNode, ((IAmbiguousLinkingCandidate) candidate).getAlternatives(), acceptor);
                } else if (candidate instanceof ISuspiciouslyOverloadedCandidate) {
                    ISuspiciouslyOverloadedCandidate castedCandidate = (ISuspiciouslyOverloadedCandidate) candidate;
                    createMultipleLinks(resource, crossRefNode, Lists.newArrayList(castedCandidate.getChosenCandidate(), castedCandidate.getRejectedCandidate()), acceptor);
                }
            }
        } else if (containedElementAt instanceof XConstructorCall) {
            XConstructorCall casted = (XConstructorCall) containedElementAt;
            if (casted.getConstructor() == crossLinkedEObject) {
                IConstructorLinkingCandidate candidate = getBatchTypeResolver().resolveTypes(casted).getLinkingCandidate(casted);
                if (candidate instanceof IAmbiguousLinkingCandidate) {
                    createMultipleLinks(resource, crossRefNode, ((IAmbiguousLinkingCandidate) candidate).getAlternatives(), acceptor);
                }
            }
        }
    }
    super.createHyperlinksForCrossRef(resource, crossRefNode, acceptor);
}
Also used : ISuspiciouslyOverloadedCandidate(org.eclipse.xtext.xbase.typesystem.computation.ISuspiciouslyOverloadedCandidate) IConstructorLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IConstructorLinkingCandidate) IAmbiguousLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate) EObject(org.eclipse.emf.ecore.EObject) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) IFeatureLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)

Aggregations

XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2 IAmbiguousLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate)2 IFeatureLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)2 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1 AbstractDiagnostic (org.eclipse.xtext.diagnostics.AbstractDiagnostic)1 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)1 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 IConstructorLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IConstructorLinkingCandidate)1 ISuspiciouslyOverloadedCandidate (org.eclipse.xtext.xbase.typesystem.computation.ISuspiciouslyOverloadedCandidate)1