use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testDeterministicExecutionOrder_01.
@Test
public void testDeterministicExecutionOrder_01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import myannotation.*");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("@_A @_B @_C String field");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("MyClass.xtend", _builder.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration myClass = it.getTypeLookup().findClass("MyClass");
Assert.assertEquals("field_A_B_C", IterableExtensions.head(myClass.getDeclaredFields()).getSimpleName());
};
this.assertProcessing(this.THREE_ANNOTATIONS, _mappedTo, _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testRemoveAnnotation.
@Test
public void testRemoveAnnotation() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(typeof(RemoveAnnotationProcessor))");
_builder.newLine();
_builder.append("annotation RemoveAnnotation{ }");
_builder.newLine();
_builder.append("class RemoveAnnotationProcessor extends AbstractClassProcessor {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(MutableClassDeclaration clazz, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annotationReference = clazz.findAnnotation(RemoveAnnotation.newTypeReference.type)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("clazz.removeAnnotation(annotationReference)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/RemoveAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("/**");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* MAKE ME LOWER CASE!");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("*/");
_builder_1.newLine();
_builder_1.append("@myannotation.RemoveAnnotation class MyClass {");
_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) -> {
final MutableClassDeclaration clazz = it.getTypeLookup().findClass("myusercode.MyClass");
Assert.assertEquals(1, IterableExtensions.size(clazz.getAnnotations()));
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testMarkReadAndInitialized2.
@Test
public void testMarkReadAndInitialized2() {
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/InitAnnotation.xtend", "\n\t\t\t\tpackage myannotation\n\t\t\t\t\n\t\t\t\timport java.util.List\n\t\t\t\timport org.eclipse.xtend.lib.macro.Active\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationContext\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationParticipant\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration\n\n\t\t\t\t@Active(InitProcessor)\n\t\t\t\tannotation Init { }\n\t\t\t\tclass InitProcessor implements TransformationParticipant<MutableFieldDeclaration> {\n\t\t\t\t\t\n\t\t\t\t\toverride doTransform(List<? extends MutableFieldDeclaration> annotatedTargetFields, extension TransformationContext context) {\n\t\t\t\t\t\tval ctor = annotatedTargetFields.head.declaringType.addConstructor [\n\t\t\t\t\t\t\tprimarySourceElement = declaringType\n\t\t\t\t\t\t\tbody = [\'\'\'\n\t\t\t\t\t\t\t\t�FOR f : annotatedTargetFields�\n\t\t\t\t\t\t\t\t\tthis.�f.simpleName� = \"foo\";\n\t\t\t\t\t\t\t\t�ENDFOR�\n\t\t\t\t\t\t\t\'\'\']\n\t\t\t\t\t\t]\n\t\t\t\t\t\tannotatedTargetFields.forEach [ field |\n\t\t\t\t\t\t\tfield.setFinal(true)\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t");
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myusercode");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@myannotation.Init String myField");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final Function1<Resource.Diagnostic, Boolean> _function_1 = (Resource.Diagnostic it_1) -> {
return Boolean.valueOf(it_1.getMessage().contains("myField may not have been initialized"));
};
IterableExtensions.<Resource.Diagnostic>exists(it.getXtendFile().eResource().getErrors(), _function_1);
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testAddDefaultConstructor.
@Test
public void testAddDefaultConstructor() {
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.TransformationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(typeof(AddConstructorProcessor))");
_builder.newLine();
_builder.append("annotation AddConstructor{ }");
_builder.newLine();
_builder.append("class AddConstructorProcessor extends AbstractClassProcessor {");
_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("clazz.addConstructor [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("body=[\'System.out.println(\"Hello World\");\']");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/AddConstructorAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@myannotation.AddConstructor class MyClass {");
_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) -> {
final MutableClassDeclaration clazz = it.getTypeLookup().findClass("myusercode.MyClass");
Assert.assertEquals(1, IterableExtensions.size(clazz.getDeclaredConstructors()));
Assert.assertTrue(IterableExtensions.isEmpty(IterableExtensions.head(clazz.getDeclaredConstructors()).getParameters()));
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testSetEmptyListAsAnnotationValue.
@Test
public void testSetEmptyListAsAnnotationValue() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_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.newLine();
_builder.append("@Active(MyAnnotationProcessor)");
_builder.newLine();
_builder.append("annotation MyAnnotation {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("annotation Values {");
_builder.newLine();
_builder.append("\t");
_builder.append("int[] intValue");
_builder.newLine();
_builder.append("\t");
_builder.append("long[] longValue");
_builder.newLine();
_builder.append("\t");
_builder.append("short[] shortValue");
_builder.newLine();
_builder.append("\t");
_builder.append("double[] doubleValue");
_builder.newLine();
_builder.append("\t");
_builder.append("float[] floatValue");
_builder.newLine();
_builder.append("\t");
_builder.append("byte[] byteValue");
_builder.newLine();
_builder.append("\t");
_builder.append("boolean[] booleanValue");
_builder.newLine();
_builder.append("\t");
_builder.append("char[] charValue");
_builder.newLine();
_builder.append("\t");
_builder.append("String[] stringValue");
_builder.newLine();
_builder.append("\t");
_builder.append("Class<?>[] classValue");
_builder.newLine();
_builder.append("\t");
_builder.append("Enum1[] enumValue");
_builder.newLine();
_builder.append("\t");
_builder.append("Annotation2[] annotationValue");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("enum Enum1 {}");
_builder.newLine();
_builder.append("annotation Annotation2 {}");
_builder.newLine();
_builder.newLine();
_builder.newLine();
_builder.append("class MyAnnotationProcessor extends AbstractClassProcessor {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(MutableClassDeclaration it, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("removeAnnotation(annotations.head)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("addAnnotation(Values.newAnnotationReference [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setIntValue(\'intValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setLongValue(\'longValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setShortValue(\'shortValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setDoubleValue(\'doubleValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setFloatValue(\'floatValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setByteValue(\'byteValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setBooleanValue(\'booleanValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setCharValue(\'charValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setStringValue(\'stringValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setClassValue(\'classValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setEnumValue(\'enumValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setAnnotationValue(\'annotationValue\', emptyList)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("])");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/MyAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import myannotation.*");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@MyAnnotation");
_builder_1.newLine();
_builder_1.append("class Foo {");
_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) -> {
final MutableClassDeclaration foo = it.getTypeLookup().findClass("myusercode.Foo");
final Type annotationType = it.getTypeLookup().findTypeGlobally("myannotation.Values");
final AnnotationReference values = foo.findAnnotation(annotationType);
Assert.assertEquals(0, ((List<Integer>) Conversions.doWrapArray(values.getIntArrayValue("intValue"))).size());
Assert.assertEquals(0, ((List<Long>) Conversions.doWrapArray(values.getLongArrayValue("longValue"))).size());
Assert.assertEquals(0, ((List<Short>) Conversions.doWrapArray(values.getShortArrayValue("shortValue"))).size());
Assert.assertEquals(0, ((List<Double>) Conversions.doWrapArray(values.getDoubleArrayValue("doubleValue"))).size());
Assert.assertEquals(0, ((List<Float>) Conversions.doWrapArray(values.getFloatArrayValue("floatValue"))).size());
Assert.assertEquals(0, ((List<Byte>) Conversions.doWrapArray(values.getByteArrayValue("byteValue"))).size());
Assert.assertEquals(0, ((List<Boolean>) Conversions.doWrapArray(values.getBooleanArrayValue("booleanValue"))).size());
Assert.assertEquals(0, ((List<Character>) Conversions.doWrapArray(values.getCharArrayValue("charValue"))).size());
Assert.assertEquals(0, ((List<String>) Conversions.doWrapArray(values.getStringArrayValue("stringValue"))).size());
Assert.assertEquals(0, ((List<TypeReference>) Conversions.doWrapArray(values.getClassArrayValue("classValue"))).size());
Assert.assertEquals(0, ((List<EnumerationValueDeclaration>) Conversions.doWrapArray(values.getEnumArrayValue("enumValue"))).size());
Assert.assertEquals(0, ((List<AnnotationReference>) Conversions.doWrapArray(values.getAnnotationArrayValue("annotationValue"))).size());
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Aggregations