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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations