Search in sources :

Example 76 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class OverrideHelperTest method checkFindOverriddenOperation_01.

@Test
public void checkFindOverriddenOperation_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import java.util.List");
        _builder.newLine();
        _builder.append("import java.util.Map");
        _builder.newLine();
        _builder.append("import java.util.Set");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo extends Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override bar(List<Object> list, ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Map<Object, Object> map,");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("var List<Object> blabla = null");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Set<Object> set");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(") {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.bar(list, map, set)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void bar(List<Object> list, ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Map<Object, Object> map, ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Set<Object> set");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(") {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.fileWithErrors(_builder.toString());
        EObject _primaryJvmElement = this._iJvmModelAssociations.getPrimaryJvmElement(IterableExtensions.<XtendFunction>head(Iterables.<XtendFunction>filter(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers(), XtendFunction.class)));
        final JvmOperation operation = ((JvmOperation) _primaryJvmElement);
        Assert.assertNull(this.overrideHelper.findOverriddenOperation(operation));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 77 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class OverrideHelperTest method checkFindOverriddenOperation_04.

@Test
public void checkFindOverriddenOperation_04() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo implements Bar {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override bar(T<?> map) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("interface Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void bar(T<?> map)");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class T<E extends CharSequence> {}");
        _builder.newLine();
        final XtendFile xtendFile = this.file(_builder.toString());
        EObject _primaryJvmElement = this._iJvmModelAssociations.getPrimaryJvmElement(IterableExtensions.<XtendFunction>head(Iterables.<XtendFunction>filter(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers(), XtendFunction.class)));
        final JvmOperation operation = ((JvmOperation) _primaryJvmElement);
        Assert.assertNotNull(this.overrideHelper.findOverriddenOperation(operation));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 78 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class OverrideHelperTest method checkFindOverriddenOperation_05.

@Test
public void checkFindOverriddenOperation_05() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.append("class Foo implements int {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override bar(Map<?, ?> map) {}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.file(_builder.toString());
        EObject _primaryJvmElement = this._iJvmModelAssociations.getPrimaryJvmElement(IterableExtensions.<XtendFunction>head(Iterables.<XtendFunction>filter(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers(), XtendFunction.class)));
        final JvmOperation operation = ((JvmOperation) _primaryJvmElement);
        Assert.assertNull(this.overrideHelper.findOverriddenOperation(operation));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 79 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.

the class OverrideHelperTest method checkFindOverriddenOperation_02.

@Test
public void checkFindOverriddenOperation_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import java.util.List");
        _builder.newLine();
        _builder.append("import java.util.Map");
        _builder.newLine();
        _builder.append("import java.util.Set");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo extends Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override bar(List<Object> list, ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Map<Object, Object> map,");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Set<Object> set");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(") {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.bar(list, map, set)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void bar(List<Object> list, ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Map<Object, Object> map, ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Set<Object> set");
        _builder.newLine();
        _builder.append("\t");
        _builder.append(") {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.file(_builder.toString());
        EObject _primaryJvmElement = this._iJvmModelAssociations.getPrimaryJvmElement(IterableExtensions.<XtendFunction>head(Iterables.<XtendFunction>filter(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers(), XtendFunction.class)));
        final JvmOperation operation = ((JvmOperation) _primaryJvmElement);
        Assert.assertNotNull(this.overrideHelper.findOverriddenOperation(operation));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 80 with XtendTypeDeclaration

use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration 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)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)134 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)98 Test (org.junit.Test)91 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)77 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)34 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)12 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8