Search in sources :

Example 1 with AbstractDiagnostic

use of org.eclipse.xtext.diagnostics.AbstractDiagnostic 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 AbstractDiagnostic

use of org.eclipse.xtext.diagnostics.AbstractDiagnostic in project xtext-core by eclipse.

the class DiagnosticConverterImpl method convertResourceDiagnostic.

@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
    IssueImpl issue = new Issue.IssueImpl();
    issue.setSyntaxError(diagnostic instanceof XtextSyntaxDiagnostic);
    issue.setSeverity(severity);
    issue.setLineNumber(diagnostic.getLine());
    issue.setColumn(diagnostic.getColumn());
    issue.setMessage(diagnostic.getMessage());
    if (diagnostic instanceof org.eclipse.xtext.diagnostics.Diagnostic) {
        org.eclipse.xtext.diagnostics.Diagnostic xtextDiagnostic = (org.eclipse.xtext.diagnostics.Diagnostic) diagnostic;
        issue.setOffset(xtextDiagnostic.getOffset());
        issue.setLength(xtextDiagnostic.getLength());
    }
    if (diagnostic instanceof AbstractDiagnostic) {
        AbstractDiagnostic castedDiagnostic = (AbstractDiagnostic) diagnostic;
        issue.setUriToProblem(castedDiagnostic.getUriToProblem());
        issue.setCode(castedDiagnostic.getCode());
        issue.setData(castedDiagnostic.getData());
    }
    issue.setType(CheckType.FAST);
    acceptor.accept(issue);
}
Also used : XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) IssueImpl(org.eclipse.xtext.validation.Issue.IssueImpl) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic)

Example 3 with AbstractDiagnostic

use of org.eclipse.xtext.diagnostics.AbstractDiagnostic in project xtext-xtend by eclipse.

the class SuspiciousOverloadValidationTest method assertSuspicious.

protected void assertSuspicious(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.SUSPICIOUSLY_OVERLOADED_FEATURE, 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 Function1<XAbstractFeatureCall, Boolean> _function_2 = (XAbstractFeatureCall it) -> {
        return Boolean.valueOf(((!Objects.equal(it.eContainingFeature(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER)) && (it.getFeature() instanceof JvmOperation)));
    };
    final XAbstractFeatureCall featureCall = IteratorExtensions.<XAbstractFeatureCall>findLast(Iterators.<XAbstractFeatureCall>filter(block.eAllContents(), XAbstractFeatureCall.class), _function_2);
    final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
    Assert.assertTrue((linkingCandidate instanceof ISuspiciouslyOverloadedCandidate));
}
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) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) ISuspiciouslyOverloadedCandidate(org.eclipse.xtext.xbase.typesystem.computation.ISuspiciouslyOverloadedCandidate) 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 4 with AbstractDiagnostic

use of org.eclipse.xtext.diagnostics.AbstractDiagnostic in project xtext-xtend by eclipse.

the class SuspiciousOverloadValidationTest method assertSuspiciousInInnerClass.

protected void assertSuspiciousInInnerClass(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.SUSPICIOUSLY_OVERLOADED_FEATURE, 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 XtendClass innerType = ((XtendClass) _head_1);
    XtendMember _head_2 = IterableExtensions.<XtendMember>head(innerType.getMembers());
    final XtendFunction firstMember = ((XtendFunction) _head_2);
    XExpression _expression = firstMember.getExpression();
    final XBlockExpression block = ((XBlockExpression) _expression);
    final Function1<XAbstractFeatureCall, Boolean> _function_2 = (XAbstractFeatureCall it) -> {
        return Boolean.valueOf(((!Objects.equal(it.eContainingFeature(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER)) && (it.getFeature() instanceof JvmOperation)));
    };
    final XAbstractFeatureCall featureCall = IteratorExtensions.<XAbstractFeatureCall>findLast(Iterators.<XAbstractFeatureCall>filter(block.eAllContents(), XAbstractFeatureCall.class), _function_2);
    final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
    Assert.assertTrue((linkingCandidate instanceof ISuspiciouslyOverloadedCandidate));
}
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) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) ISuspiciouslyOverloadedCandidate(org.eclipse.xtext.xbase.typesystem.computation.ISuspiciouslyOverloadedCandidate) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) 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)

Aggregations

AbstractDiagnostic (org.eclipse.xtext.diagnostics.AbstractDiagnostic)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)3 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)3 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)3 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)3 XExpression (org.eclipse.xtext.xbase.XExpression)3 IFeatureLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)3 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 ISuspiciouslyOverloadedCandidate (org.eclipse.xtext.xbase.typesystem.computation.ISuspiciouslyOverloadedCandidate)2 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 XtextSyntaxDiagnostic (org.eclipse.xtext.resource.XtextSyntaxDiagnostic)1 IssueImpl (org.eclipse.xtext.validation.Issue.IssueImpl)1 IAmbiguousLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate)1