Search in sources :

Example 61 with XtendTypeDeclaration

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

the class XtendHoverSignatureProviderTest method testAnnotationReference.

@Test
public void testAnnotationReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("@Foo");
        _builder.newLine();
        _builder.append("class Bar {}");
        _builder.newLine();
        _builder.append("annotation Foo { }");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final JvmType in = IterableExtensions.<XAnnotation>head(((XtendClass) _head).getAnnotations()).getAnnotationType();
        Assert.assertEquals("Foo", this.signatureProvider.getSignature(in));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 62 with XtendTypeDeclaration

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

the class XtendHoverSignatureProviderTest method testAutcastExpressions_3.

@Test
public void testAutcastExpressions_3() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo(CharSequence c) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (c instanceof String) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("c.substring(1, 1)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("switch(c){");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("String : c.length");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(((XtendClass) _head).getMembers());
        final XtendFunction func = ((XtendFunction) _head_1);
        Assert.assertEquals("CharSequence c - foo(CharSequence)", this.signatureProvider.getSignature(IterableExtensions.<XtendParameter>head(func.getParameters())));
        XExpression _expression = func.getExpression();
        final XBlockExpression block = ((XBlockExpression) _expression);
        XExpression _head_2 = IterableExtensions.<XExpression>head(block.getExpressions());
        final XIfExpression ifexpr = ((XIfExpression) _head_2);
        final XExpression then = ifexpr.getThen();
        XExpression _head_3 = IterableExtensions.<XExpression>head(((XBlockExpression) then).getExpressions());
        final XExpression target = ((XMemberFeatureCall) _head_3).getMemberCallTarget();
        Assert.assertEquals("String c", this.signatureProvider.getSignature(target));
        XExpression _get = block.getExpressions().get(1);
        final XSwitchExpression switchExpr = ((XSwitchExpression) _get);
        XExpression _then = IterableExtensions.<XCasePart>head(switchExpr.getCases()).getThen();
        final XExpression expr = ((XMemberFeatureCall) _then).getMemberCallTarget();
        Assert.assertEquals("String c", this.signatureProvider.getSignature(expr));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 63 with XtendTypeDeclaration

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

the class AccessRestrictionInWorkspaceTest method testDiscouragedReferenceInReexportedProject.

@Test
public void testDiscouragedReferenceInReexportedProject() {
    try {
        final XtendFile xtendFile = this.parse(IResourcesSetupUtil.createFile("thirdProject/src/Dummy.xtend", "class D { discouraged.B b }"));
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        this._validationTestHelper.assertWarning(c, TypesPackage.Literals.JVM_TYPE_REFERENCE, IssueCodes.DISCOURAGED_REFERENCE, "Discouraged access: The type B is not accessible", "on required project firstProject");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 64 with XtendTypeDeclaration

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

the class AccessRestrictionInWorkspaceTest method testForbiddenReferenceInSameProject.

@Test
public void testForbiddenReferenceInSameProject() {
    try {
        final XtendFile xtendFile = this.parse(IResourcesSetupUtil.createFile("firstProject/src/Dummy.xtend", "class D { restricted.A a }"));
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        this._validationTestHelper.assertNoError(c, IssueCodes.DISCOURAGED_REFERENCE);
        this._validationTestHelper.assertNoError(c, IssueCodes.FORBIDDEN_REFERENCE);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 65 with XtendTypeDeclaration

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

the class AccessRestrictionInWorkspaceTest method testExportedByOtherProject.

@Test
public void testExportedByOtherProject() {
    try {
        final XtendFile xtendFile = this.parse(IResourcesSetupUtil.createFile("secondProject/src/Dummy.xtend", "class D { allowed.C c }"));
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        this._validationTestHelper.assertNoError(c, IssueCodes.DISCOURAGED_REFERENCE);
        this._validationTestHelper.assertNoError(c, IssueCodes.FORBIDDEN_REFERENCE);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

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