Search in sources :

Example 71 with CompilationUnitImpl

use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.

the class AbstractReusableActiveAnnotationTests method testIntroduceNewTypeAndWorkWithIt.

@Test
public void testIntroduceNewTypeAndWorkWithIt() {
    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.RegisterGlobalsContext");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.RegisterGlobalsParticipant");
    _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.TransformationParticipant");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(typeof(NewTypesAddingAnnotationProcessor))");
    _builder.newLine();
    _builder.append("annotation NewTypesAddingAnnotation { }");
    _builder.newLine();
    _builder.append("class NewTypesAddingAnnotationProcessor implements RegisterGlobalsParticipant<ClassDeclaration>, TransformationParticipant<MutableClassDeclaration> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doRegisterGlobals(List<? extends ClassDeclaration> sourceClasses, RegisterGlobalsContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("for (clazz : sourceClasses) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("context.registerClass(clazz.qualifiedName+\"Derived\")");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doTransform(List<? extends MutableClassDeclaration> classes, extension TransformationContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("classes.forEach [ ele |");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("val cl = context.findClass(ele.qualifiedName+\"Derived\")");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("cl.extendedClass = newTypeReference(ele)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("]");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/NewTypesAddingAnnotation.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package myusercode");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@myannotation.NewTypesAddingAnnotation");
    _builder_1.newLine();
    _builder_1.append("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 declaredClass = it.getTypeLookup().findClass("myusercode.MyClass");
        Assert.assertNotNull(declaredClass);
        final MutableClassDeclaration clazz = it.getTypeLookup().findClass("myusercode.MyClassDerived");
        Assert.assertNotNull(clazz);
        Assert.assertEquals(declaredClass.getQualifiedName(), clazz.getExtendedClass().getType().getQualifiedName());
    };
    this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Also used : CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 72 with CompilationUnitImpl

use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.

the class AbstractReusableActiveAnnotationTests method testBug441081.

@Test
public void testBug441081() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package bug441081");
    _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.MutableClassDeclaration");
    _builder.newLine();
    _builder.newLine();
    _builder.append("interface GenericInterface {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <T> T m()");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(Bug441081Processor)");
    _builder.newLine();
    _builder.append("annotation Bug441081 {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Bug441081Processor extends AbstractClassProcessor {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("annotatedClass.implementedInterfaces = annotatedClass.implementedInterfaces + #[findTypeGlobally(GenericInterface).newTypeReference]");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("annotatedClass.addMethod(\"m\") [");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("returnType = addTypeParameter(\"T\", object).newTypeReference");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("body = \'");
    _builder.append("\'\'return null;\'");
    _builder.append("\'\'");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("primarySourceElement = annotatedClass");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("]");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("bug441081/Bug441081.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import bug441081.Bug441081");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@Bug441081");
    _builder_1.newLine();
    _builder_1.append("class Bug441081Client {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("Bug441081Client.xtend", _builder_1.toString());
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
        final MutableClassDeclaration c = it.getTypeLookup().findClass("Bug441081Client");
        Type _type = c.findDeclaredMethod("m").getReturnType().getType();
        final TypeParameterDeclaration typeParam = ((TypeParameterDeclaration) _type);
        Assert.assertFalse(IterableExtensions.isEmpty(typeParam.getUpperBounds()));
        this.validator.assertNoIssues(it.getXtendFile());
    };
    this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) TypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration) MutableTypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 73 with CompilationUnitImpl

use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.

the class AbstractReusableActiveAnnotationTests method testValidateLater.

@Test
public void testValidateLater() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package myannotation");
    _builder.newLine();
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.lib.macro.AbstractFieldProcessor");
    _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.MutableFieldDeclaration");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(ValidateLaterProcessor)");
    _builder.newLine();
    _builder.append("annotation ValidateLater {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class ValidateLaterProcessor extends AbstractFieldProcessor {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doTransform(MutableFieldDeclaration it, extension TransformationContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("validateLater[ |");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("if (type == primitiveBoolean)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("addWarning(\"The type was inferred and boolean\")");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("]");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/ValidateLater.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("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("@ValidateLater val foo = true");
    _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 cls = it.getTypeLookup().findClass("myusercode.Foo");
        final List<? extends Problem> problems = it.getProblemSupport().getProblems(IterableExtensions.head(cls.getDeclaredFields()));
        Assert.assertEquals(1, problems.size());
        Assert.assertEquals("The type was inferred and boolean", problems.get(0).getMessage());
    };
    this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Also used : CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) Problem(org.eclipse.xtend.lib.macro.services.Problem) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 74 with CompilationUnitImpl

use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.

the class AbstractReusableActiveAnnotationTests method testInferredTypeReferences.

@Test
public void testInferredTypeReferences() {
    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.append("Class<?> value");
    _builder.newLine();
    _builder.append("}");
    _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("for (field : declaredFields) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("addMethod(field.simpleName) [");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("returnType = field.type");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("body = [\'return 1;\']");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("]");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val myAnnotation = findAnnotation(MyAnnotation.findTypeGlobally)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val type = myAnnotation.getClassValue(\"value\").type as ClassDeclaration");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("for (field : type.declaredFields) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("addMethod(field.simpleName) [");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("returnType = field.type");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("body = [\'return 1;\']");
    _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.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(Bar)");
    _builder_1.newLine();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("val y = 1");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Bar {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("val x = 1");
    _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 MutableClassDeclaration bar = it.getTypeLookup().findClass("myusercode.Bar");
        this.assertSameType(foo.findDeclaredField("y").getType(), foo.findDeclaredMethod("y").getReturnType());
        this.assertSameType(bar.findDeclaredField("x").getType(), foo.findDeclaredMethod("x").getReturnType());
    };
    this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Also used : CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 75 with CompilationUnitImpl

use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.

the class AbstractReusableActiveAnnotationTests method testAnnotationValueSetting_AsExpression.

@Ignore("Setting annotation values of type Expression is not possible")
@Test
public void testAnnotationValueSetting_AsExpression() {
    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.MutableClassDeclaration");
    _builder.newLine();
    _builder.newLine();
    _builder.newLine();
    _builder.append("@Active(MoveAnnotationValuesProcessor)");
    _builder.newLine();
    _builder.append("annotation MoveValues {}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class MoveAnnotationValuesProcessor extends AbstractClassProcessor {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val classAnnotation = annotatedClass.annotations.head");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val field = annotatedClass.declaredFields.head");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val fieldAnnotation = field.annotations.head");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("field.removeAnnotation(fieldAnnotation)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("field.addAnnotation(fieldAnnotation.annotationTypeDeclaration.qualifiedName.newAnnotationReference [");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'booleanValue\', classAnnotation.getExpression(\'booleanValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'intValue\', classAnnotation.getExpression(\'intValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'longValue\', classAnnotation.getExpression(\'longValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'stringValue\', classAnnotation.getExpression(\'stringValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'booleanArrayValue\', classAnnotation.getExpression(\'booleanArrayValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'intArrayValue\', classAnnotation.getExpression(\'intArrayValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'longArrayValue\', classAnnotation.getExpression(\'longArrayValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'stringArrayValue\', classAnnotation.getExpression(\'stringArrayValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'typeValue\', classAnnotation.getExpression(\'typeValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'typeArrayValue\', classAnnotation.getExpression(\'typeArrayValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'annotation2Value\', classAnnotation.getExpression(\'annotation2Value\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'annotation2ArrayValue\', classAnnotation.getExpression(\'annotation2ArrayValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'enumValue\', classAnnotation.getExpression(\'enumValue\'))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("set(\'enumArrayValue\', classAnnotation.getExpression(\'enumArrayValue\'))");
    _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/MoveValues.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package myusercode");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import test.Annotation");
    _builder_1.newLine();
    _builder_1.append("import test.Annotation2");
    _builder_1.newLine();
    _builder_1.append("import myannotation.MoveValues");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@Annotation(");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("intValue = 2 / 2 + 2 * 3 - 4 % 1,");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("longValue = 42 + 4 + 6 * 42 - 4 / 45,");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("stringValue = \'foo\' + \'baz\',");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("booleanValue = true,");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("booleanArrayValue = #[true, false],");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("intArrayValue = #[ -1, 34 + 45, 2 - 6 ],");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("longArrayValue = #[42, 5 * -3],");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("stringArrayValue = #[\'foo\', \'bla\' + \'buzz\'],");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("typeValue = String,");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("typeArrayValue = #[String, Integer],");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("annotation2Value = @Annotation2(\'foo\' + \'wuppa\'),");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("annotation2ArrayValue = #[@Annotation2, @Annotation2(\'foo\'+\'wuppa\')],");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("enumValue = test.Enum1.YELLOW,");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("enumArrayValue = #[test.Enum1.YELLOW, test.Enum1.RED]");
    _builder_1.newLine();
    _builder_1.append(")");
    _builder_1.newLine();
    _builder_1.append("@MoveValues ");
    _builder_1.newLine();
    _builder_1.append("class UserCode {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("@Annotation() String 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 clazz = it.getTypeLookup().findClass("myusercode.UserCode");
        final AnnotationReference annoRef = IterableExtensions.head(IterableExtensions.head(clazz.getDeclaredFields()).getAnnotations());
        Assert.assertEquals(Integer.valueOf((((2 / 2) + (2 * 3)) - (4 % 1))), annoRef.getValue("intValue"));
        Assert.assertEquals(Long.valueOf(((long) (((42 + 4) + (6 * 42)) - (4 / 45)))), annoRef.getValue("longValue"));
        Assert.assertEquals("foobaz", annoRef.getValue("stringValue"));
        Object _value = annoRef.getValue("booleanValue");
        Assert.assertTrue((((Boolean) _value)).booleanValue());
        Object _value_1 = annoRef.getValue("booleanArrayValue");
        final boolean[] bools = ((boolean[]) _value_1);
        Assert.assertTrue(bools[0]);
        Assert.assertFalse(bools[1]);
        Object _value_2 = annoRef.getValue("intArrayValue");
        Assert.assertArrayEquals(new int[] { (-1), (34 + 45), (2 - 6) }, ((int[]) _value_2));
        Object _value_3 = annoRef.getValue("typeArrayValue");
        final TypeReference[] type = ((TypeReference[]) _value_3);
        Assert.assertEquals(it.getTypeReferenceProvider().newTypeReference(Integer.class), type[1]);
        Object _value_4 = annoRef.getValue("annotation2Value");
        final AnnotationReference anno = ((AnnotationReference) _value_4);
        Assert.assertEquals("foowuppa", anno.getValue("value"));
        Object _value_5 = annoRef.getValue("annotation2ArrayValue");
        final AnnotationReference[] annoArray = ((AnnotationReference[]) _value_5);
        Assert.assertEquals("HUBBA BUBBA!", annoArray[0].getValue("value"));
        Object _value_6 = annoRef.getValue("enumValue");
        final EnumerationValueDeclaration enum1 = ((EnumerationValueDeclaration) _value_6);
        Assert.assertEquals("YELLOW", enum1.getSimpleName());
        Object _value_7 = annoRef.getValue("enumArrayValue");
        final EnumerationValueDeclaration[] enumArray = ((EnumerationValueDeclaration[]) _value_7);
        Assert.assertEquals("YELLOW", IterableExtensions.<EnumerationValueDeclaration>head(((Iterable<EnumerationValueDeclaration>) Conversions.doWrapArray(enumArray))).getSimpleName());
    };
    this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Also used : CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) EObject(org.eclipse.emf.ecore.EObject) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) EnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration) MutableEnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableEnumerationValueDeclaration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)139 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)130 Test (org.junit.Test)128 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)90 MutableMethodDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration)21 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)17 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)15 EObject (org.eclipse.emf.ecore.EObject)13 Resource (org.eclipse.emf.ecore.resource.Resource)11 MutableInterfaceDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration)11 Type (org.eclipse.xtend.lib.macro.declaration.Type)10 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 List (java.util.List)9 AnnotationTypeDeclaration (org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration)9 ClassDeclaration (org.eclipse.xtend.lib.macro.declaration.ClassDeclaration)9 Element (org.eclipse.xtend.lib.macro.declaration.Element)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)9 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 AccessibleObject (java.lang.reflect.AccessibleObject)7