Search in sources :

Example 16 with XtendFile

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

the class ConstantExpressionsInterpreterTest method testConstants_WithStaticImport_01.

@Test
public void testConstants_WithStaticImport_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("import static test.Constants1.* ");
        _builder.newLine();
        _builder.append("import static MyConstants.*");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class C { ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val someString = STRING_CONSTANT+\'-\'+MY_CONST");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("class MyConstants {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("static val MY_CONST = STRING_CONSTANT");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
        Assert.assertEquals(((Constants1.STRING_CONSTANT + "-") + Constants1.STRING_CONSTANT), this.interpreter.evaluate(stringField.getInitialValue(), null));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 17 with XtendFile

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

the class ImportedNamesTest method testPrimitivesNotIncluded.

@Test
public void testPrimitivesNotIncluded() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import hubbabubba.*");
        _builder.newLine();
        _builder.append("import java.util.*");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class TestCase {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("String x;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int i;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("boolean b;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("char c;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("short s;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("long l;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("byte t;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("float f;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("double d;");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("List<Object> l;");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (x == i == b == c == s == l == t == f == d) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("println(\"never happens\")");
        _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.file(_builder.toString());
        final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
        final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
            return Boolean.valueOf(this.primitives.contains(it.getLastSegment()));
        };
        Assert.assertFalse(IterableExtensions.<QualifiedName>exists(description.getImportedNames(), _function));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 18 with XtendFile

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

the class ImportedNamesTest method testNestedTypesIncludedOnUnresolvedFeatures.

@Test
public void testNestedTypesIncludedOnUnresolvedFeatures() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val foo = types.StaticOuterClass.Unknown.StaticInnerClass.CONSTANT");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
        final Iterable<QualifiedName> importedNames = description.getImportedNames();
        final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
            String _string = it.toString();
            String _lowerCase = "types.StaticOuterClass$Unknown".toLowerCase();
            return Boolean.valueOf(Objects.equal(_string, _lowerCase));
        };
        Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 19 with XtendFile

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

the class ImportedNamesTest method testNestedTypesIncludedOnUnresolvedFeatures_02.

@Test
public void testNestedTypesIncludedOnUnresolvedFeatures_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.Unknown");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
        final Iterable<QualifiedName> importedNames = description.getImportedNames();
        final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
            String _string = it.toString();
            String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$Unknown".toLowerCase();
            return Boolean.valueOf(Objects.equal(_string, _lowerCase));
        };
        Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 20 with XtendFile

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

the class ImportedNamesTest method testExtendedInterfaces.

@Test
public void testExtendedInterfaces() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import java.util.List");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo implements List {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
        final Iterable<QualifiedName> importedNames = description.getImportedNames();
        final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
            return Boolean.valueOf(it.getLastSegment().equals("collection"));
        };
        Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) 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