Search in sources :

Example 81 with XtendFile

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

the class ValidationBug433213Test method test_05.

@Test
public void test_05() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def m2() {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t\t\t");
        _builder.append("def T m3() {}");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        XExpression _expression_1 = m2.getExpression();
        final XBlockExpression body2 = ((XBlockExpression) _expression_1);
        XExpression _head_3 = IterableExtensions.<XExpression>head(body2.getExpressions());
        final AnonymousClass anon2 = ((AnonymousClass) _head_3);
        XtendMember _head_4 = IterableExtensions.<XtendMember>head(anon2.getMembers());
        final XtendFunction m3 = ((XtendFunction) _head_4);
        final JvmTypeReference returnType = m3.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } 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) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 82 with XtendFile

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

the class ValidationBug433213Test method test_02.

@Test
public void test_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def T m2() {}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        final JvmTypeReference returnType = m2.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } 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) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 83 with XtendFile

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

the class ValidationBug434409Test method test_02.

@Test
public void test_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class UnreachableCode {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m(Object x) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val y = switch (x) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("String: throw new RuntimeException()");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("Integer: return \"foo\"");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("default: return \"bar\"");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        this.helper.assertError(file, XtendPackage.Literals.XTEND_VARIABLE_DECLARATION, IssueCodes.UNREACHABLE_CODE, "the var");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 84 with XtendFile

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

the class ValidationBug434409Test method test_06.

@Test
public void test_06() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class UnreachableCode {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m(Object x) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val Object y = if (x == \"bar\") {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("return \"asdf\"");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("} else {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("return \"foo\"");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        this.helper.assertError(file, XtendPackage.Literals.XTEND_VARIABLE_DECLARATION, IssueCodes.UNREACHABLE_CODE, "Dead code: The variable y will never be assigned.");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 85 with XtendFile

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

the class ValidationBug434409Test method test_01.

@Test
public void test_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class UnreachableCode {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m(Object x) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val y = if (x == \"bar\") {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("return \"asdf\"");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("} else {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("return \"foo\"");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        this.helper.assertError(file, XtendPackage.Literals.XTEND_VARIABLE_DECLARATION, IssueCodes.UNREACHABLE_CODE, "Dead code: The variable y will never be assigned.");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

XtendFile (org.eclipse.xtend.core.xtend.XtendFile)855 Test (org.junit.Test)782 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)372 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)229 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)182 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)126 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)119 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)98 XExpression (org.eclipse.xtext.xbase.XExpression)82 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)64 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)62 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)62 EObject (org.eclipse.emf.ecore.EObject)50 Resource (org.eclipse.emf.ecore.resource.Resource)47 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)46 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)42 XtextResource (org.eclipse.xtext.resource.XtextResource)34 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)29 XtendField (org.eclipse.xtend.core.xtend.XtendField)23 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)21