use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class ActiveAnnotationsRuntimeTest method testDetectOrphanedElements2.
@Test
public void testDetectOrphanedElements2() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.ClassDeclaration");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.RegisterGlobalsContext");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(EvilProcessor)");
_builder.newLine();
_builder.append("annotation EvilAnnotation {}");
_builder.newLine();
_builder.newLine();
_builder.append("class EvilProcessor extends AbstractClassProcessor {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doRegisterGlobals(ClassDeclaration clazz, extension RegisterGlobalsContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("registerClass(clazz.qualifiedName+\'.Inner\')");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(MutableClassDeclaration clazz, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("findClass(clazz.qualifiedName+\'.Inner\').primarySourceElement = clazz");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/EvilAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import myannotation.EvilAnnotation");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@EvilAnnotation");
_builder_1.newLine();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Comparable<String> p = new Comparable<String>() {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("override compareTo(String other) { 42 }");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
this.validator.assertNoWarnings(it.getXtendFile(), XtendPackage.Literals.XTEND_FILE, IssueCodes.ORPHAN_ELEMENT);
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class TypeLookupImplTest method testFindUpstreamType.
@Test
public void testFindUpstreamType() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass {}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertNull(it.getTypeLookup().findUpstreamType("foo.MyClass"));
Assert.assertNotNull(it.getTypeLookup().findUpstreamType("java.lang.String"));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class TypeLookupImplTest method testFindSourceType.
@Test
public void testFindSourceType() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.append("import org.eclipse.xtend.core.tests.macro.declaration.AddNestedTypes");
_builder.newLine();
_builder.newLine();
_builder.append("@AddNestedTypes class MyClass {}");
_builder.newLine();
_builder.append("@AddNestedTypes enum MyEnum {}");
_builder.newLine();
_builder.append("@AddNestedTypes interface MyInterface {}");
_builder.newLine();
_builder.append("@AddNestedTypes annotation MyAnnotation {}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertNotNull(it.getTypeLookup().findSourceClass("foo.MyClass"));
Assert.assertNotNull(it.getTypeLookup().findSourceInterface("foo.MyInterface"));
Assert.assertNotNull(it.getTypeLookup().findSourceEnumerationType("foo.MyEnum"));
Assert.assertNotNull(it.getTypeLookup().findSourceAnnotationType("foo.MyAnnotation"));
Assert.assertNull(it.getTypeLookup().findSourceClass("foo.MyClass.NestedClass"));
Assert.assertNull(it.getTypeLookup().findSourceInterface("foo.MyClass.NestedInterface"));
Assert.assertNull(it.getTypeLookup().findSourceEnumerationType("foo.MyClass.NestedEnumerationType"));
Assert.assertNull(it.getTypeLookup().findSourceAnnotationType("foo.MyClass.NestedAnnotationType"));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class DeclarationsTest method testOverriddenMethodFromSource.
@Test
public void testOverriddenMethodFromSource() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package p");
_builder.newLine();
_builder.newLine();
_builder.append("abstract class C extends java.util.AbstractList<String> implements I {");
_builder.newLine();
_builder.append("\t");
_builder.append("override add(String s);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("interface I {");
_builder.newLine();
_builder.append("\t");
_builder.append("def boolean add(String s)");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertEquals("p", it.getPackageName());
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration clazz = ((ClassDeclaration) _head);
Assert.assertEquals("p.C", clazz.getQualifiedName());
final MethodDeclaration add = IterableExtensions.head(clazz.getDeclaredMethods());
final Iterable<? extends MethodDeclaration> allOverridden = add.getOverriddenOrImplementedMethods();
Assert.assertEquals(2, IterableExtensions.size(allOverridden));
final MethodDeclaration listAdd = IterableExtensions.head(allOverridden);
Assert.assertEquals("add", listAdd.getSimpleName());
Assert.assertEquals("E", IterableExtensions.head(listAdd.getParameters()).getType().getSimpleName());
final MethodDeclaration intfAdd = IterableExtensions.last(allOverridden);
Assert.assertEquals("add", intfAdd.getSimpleName());
Assert.assertEquals("String", IterableExtensions.head(intfAdd.getParameters()).getType().getSimpleName());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class DeclarationsTest method testTypeReferences.
@Test
public void testTypeReferences() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final TypeReference anyType = it.getTypeReferenceProvider().getAnyType();
Assert.assertTrue(anyType.isAnyType());
final TypeReference stringType = it.getTypeReferenceProvider().getString();
final TypeReference charsequenceType = it.getTypeReferenceProvider().newTypeReference(CharSequence.class.getName());
Assert.assertTrue(charsequenceType.isAssignableFrom(stringType));
Assert.assertTrue(stringType.isAssignableFrom(anyType));
Assert.assertFalse(stringType.isAssignableFrom(charsequenceType));
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveBoolean(), "java.lang.Boolean");
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveInt(), "java.lang.Integer");
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveLong(), "java.lang.Long");
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveShort(), "java.lang.Short");
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveChar(), "java.lang.Character");
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveByte(), "java.lang.Byte");
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveFloat(), "java.lang.Float");
this.checkPrimitive(it.getTypeReferenceProvider().getPrimitiveDouble(), "java.lang.Double");
final TypeReference primitiveVoid = it.getTypeReferenceProvider().getPrimitiveVoid();
Assert.assertTrue(primitiveVoid.isVoid());
final TypeReference listOfStringType = it.getTypeReferenceProvider().getList(it.getTypeReferenceProvider().getString());
final TypeReference setOfString = it.getTypeReferenceProvider().getSet(IterableExtensions.<TypeReference>head(listOfStringType.getActualTypeArguments()));
Assert.assertEquals("List<String>", listOfStringType.toString());
Assert.assertEquals("String", IterableExtensions.<TypeReference>head(listOfStringType.getActualTypeArguments()).toString());
Assert.assertEquals("Set<String>", setOfString.toString());
Assert.assertEquals("String", IterableExtensions.<TypeReference>head(setOfString.getActualTypeArguments()).toString());
Assert.assertEquals("Set<?>", it.getTypeReferenceProvider().getSet(it.getTypeReferenceProvider().newWildcardTypeReference()).toString());
Assert.assertEquals("Set<? extends List<String>>", it.getTypeReferenceProvider().getSet(it.getTypeReferenceProvider().newWildcardTypeReference(listOfStringType)).toString());
Assert.assertEquals("Set<? super List<String>>", it.getTypeReferenceProvider().getSet(it.getTypeReferenceProvider().newWildcardTypeReferenceWithLowerBound(listOfStringType)).toString());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
Aggregations