Search in sources :

Example 1 with ILinkingCandidate

use of org.eclipse.xtext.xbase.typesystem.computation.ILinkingCandidate 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);
    final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(file);
    ILinkingCandidate _switchResult = null;
    XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions());
    final XExpression featureOrConstructorCall = _last;
    boolean _matched = false;
    if (featureOrConstructorCall instanceof XAbstractFeatureCall) {
        _matched = true;
        _switchResult = resolvedTypes.getLinkingCandidate(((XAbstractFeatureCall) featureOrConstructorCall));
    }
    if (!_matched) {
        if (featureOrConstructorCall instanceof XConstructorCall) {
            _matched = true;
            _switchResult = resolvedTypes.getLinkingCandidate(((XConstructorCall) featureOrConstructorCall));
        }
    }
    if (!_matched) {
        String _valueOf = String.valueOf(featureOrConstructorCall.eClass().getName());
        throw new IllegalArgumentException(_valueOf);
    }
    final ILinkingCandidate linkingCandidate = _switchResult;
    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) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) Resource(org.eclipse.emf.ecore.resource.Resource) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) 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) ILinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.ILinkingCandidate)

Aggregations

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 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)1 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)1 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)1 IAmbiguousLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate)1 ILinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.ILinkingCandidate)1