use of org.eclipse.xtend.lib.macro.declaration.AnnotationReference in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testAnnotationValueSetting_1.
@Test
public void testAnnotationValueSetting_1() {
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.*");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.*");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(ConfigurableAnnotationProcessor)");
_builder.newLine();
_builder.append("annotation ConfigurableAnnotation {");
_builder.newLine();
_builder.append("\t");
_builder.append("BlackOrWhite color");
_builder.newLine();
_builder.append("\t");
_builder.append("BlackOrWhite[] colors");
_builder.newLine();
_builder.append("\t");
_builder.append("Class<?> type");
_builder.newLine();
_builder.append("\t");
_builder.append("Class<?>[] types");
_builder.newLine();
_builder.append("\t");
_builder.append("SomeAnnotation annotation");
_builder.newLine();
_builder.append("\t");
_builder.append("SomeAnnotation[] annotations");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("annotation SomeAnnotation {");
_builder.newLine();
_builder.append("\t");
_builder.append("boolean value");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("enum BlackOrWhite {");
_builder.newLine();
_builder.append("\t");
_builder.append("BLACK, WHITE");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class ConfigurableAnnotationProcessor extends AbstractClassProcessor {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val anno = annotatedClass.annotations.head");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val someAnnotationType = findTypeGlobally(SomeAnnotation)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val enumType = findTypeGlobally(\'myannotation.BlackOrWhite\') as EnumerationTypeDeclaration");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val white = enumType.findDeclaredValue(\'WHITE\')");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val black = enumType.findDeclaredValue(\'BLACK\')");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val existingValue = anno.getValue(\'color\')");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (existingValue != white)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new AssertionError(\"color\")");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annoWithColor = annotatedClass.addAnnotation(newAnnotationReference(anno) [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setEnumValue(\'color\', black)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("])");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.removeAnnotation(anno)");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val existingColorsValue = annoWithColor.getValue(\'colors\') as Object[]");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (existingColorsValue.get(0) != white && existingColorsValue.get(1) != black && existingColorsValue.length != 2)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new AssertionError(\"colors\")");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annoWithColors = annotatedClass.addAnnotation(newAnnotationReference(annoWithColor) [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setEnumValue(\'colors\', black, white)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("])");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.removeAnnotation(annoWithColor)");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val existingType = annoWithColors.getValue(\'type\')");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (existingType != string)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new AssertionError(\"type\")");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annoWithType = annotatedClass.addAnnotation(newAnnotationReference(annoWithColors) [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setClassValue(\'type\', annotatedClass.newTypeReference)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("])");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.removeAnnotation(annoWithColors)");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val existingTypes = annoWithType.getValue(\'types\') as Object[]");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (existingTypes.get(0) != primitiveInt && existingTypes.get(1) != annotatedClass.newTypeReference && existingTypes.length != 2)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new AssertionError(\"types\")");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annoWithTypes = annotatedClass.addAnnotation(newAnnotationReference(annoWithType) [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setClassValue(\'types\', primitiveBoolean)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("])");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.removeAnnotation(annoWithType)");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annotationReference = annoWithTypes.getAnnotationValue(\'annotation\')");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (someAnnotationType != annotationReference.annotationTypeDeclaration)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new AssertionError(\"someAnnotationType != annotationReference.annotationTypeDeclaration\")");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annoWithAnnotation = annotatedClass.addAnnotation(newAnnotationReference(annoWithTypes) [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setAnnotationValue(\'annotation\', ");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("newAnnotationReference(someAnnotationType) [");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("setBooleanValue(\'value\', false)");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append(")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("])");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.removeAnnotation(annoWithTypes)");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val annotationReferences = annoWithAnnotation.getAnnotationArrayValue(\'annotations\')");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (annotationReferences.size != 2)");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new AssertionError(\"annotationReferences.size != 2\")");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotationReferences.forEach [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("if (someAnnotationType != annotationTypeDeclaration)");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("throw new AssertionError(\"someAnnotationType != annotationTypeDeclaration\")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.addAnnotation(newAnnotationReference(annoWithAnnotation) [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("setAnnotationValue(\'annotations\', ");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("newAnnotationReference(someAnnotationType) [");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("setBooleanValue(\'value\', false)");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("],");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("newAnnotationReference(someAnnotationType) [");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("setBooleanValue(\'value\', false)");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append(")");
_builder.newLine();
_builder.append("\t\t");
_builder.append("])");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedClass.removeAnnotation(annoWithAnnotation)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/ConfigurableAnnotation.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("@ConfigurableAnnotation(");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("color=BlackOrWhite.WHITE, ");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("colors=#[BlackOrWhite.WHITE, BlackOrWhite.BLACK], ");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("type = String, ");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("types=#[Integer, MyClass],");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("annotation=@SomeAnnotation(true),");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("annotations=#[@SomeAnnotation(true), @SomeAnnotation(true)]");
_builder_1.newLine();
_builder_1.append(")");
_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 clazz = it.getTypeLookup().findClass("myusercode.MyClass");
Type _findTypeGlobally = it.getTypeLookup().findTypeGlobally("myannotation.BlackOrWhite");
final EnumerationTypeDeclaration colorEnum = ((EnumerationTypeDeclaration) _findTypeGlobally);
final Type annotationType = it.getTypeLookup().findTypeGlobally("myannotation.ConfigurableAnnotation");
final AnnotationReference annotation = clazz.findAnnotation(annotationType);
Assert.assertEquals(colorEnum.findDeclaredValue("BLACK"), annotation.getValue("color"));
Object _value = annotation.getValue("colors");
final Object[] colors = ((Object[]) _value);
Assert.assertEquals(2, colors.length);
Assert.assertEquals(colorEnum.findDeclaredValue("BLACK"), colors[0]);
Assert.assertEquals(colorEnum.findDeclaredValue("WHITE"), colors[1]);
Assert.assertEquals(it.getTypeReferenceProvider().newTypeReference(clazz), annotation.getValue("type"));
final TypeReference[] types = annotation.getClassArrayValue("types");
Assert.assertEquals(1, types.length);
Assert.assertEquals(it.getTypeReferenceProvider().getPrimitiveBoolean(), types[0]);
final Type someAnnotationType = it.getTypeLookup().findTypeGlobally("myannotation.SomeAnnotation");
final AnnotationReference annotationValue = annotation.getAnnotationValue("annotation");
Assert.assertNotNull(annotationValue);
Assert.assertEquals(someAnnotationType, annotationValue.getAnnotationTypeDeclaration());
Assert.assertFalse(annotationValue.getBooleanValue("value"));
final AnnotationReference[] annotationsValue = annotation.getAnnotationArrayValue("annotations");
Assert.assertNotNull(annotationsValue);
Assert.assertEquals(2, ((List<AnnotationReference>) Conversions.doWrapArray(annotationsValue)).size());
final Consumer<AnnotationReference> _function_1 = (AnnotationReference it_1) -> {
Assert.assertEquals(someAnnotationType, annotationValue.getAnnotationTypeDeclaration());
Assert.assertFalse(annotationValue.getBooleanValue("value"));
};
((List<AnnotationReference>) Conversions.doWrapArray(annotationsValue)).forEach(_function_1);
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtend.lib.macro.declaration.AnnotationReference in project xtext-xtend by eclipse.
the class CheckMutableInterfaceDeclarationProcessor method doTransform.
@Override
public void doTransform(final List<? extends MutableInterfaceDeclaration> annotatedTargetElements, @Extension final TransformationContext context) {
for (final MutableInterfaceDeclaration annotatedTargetElement : annotatedTargetElements) {
{
final Procedure1<String> _function = (String identifier) -> {
annotatedTargetElement.addTypeParameter(identifier).remove();
};
MutableAssert.assertValidJavaIdentifier("name", _function);
final Procedure0 _function_1 = () -> {
annotatedTargetElement.addTypeParameter("T", ((TypeReference[]) null));
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "upperBounds cannot be null", _function_1);
final Procedure0 _function_2 = () -> {
annotatedTargetElement.addTypeParameter("T", new TypeReference[] { null });
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "upperBounds cannot contain null", _function_2);
annotatedTargetElement.addTypeParameter("T", ((TypeReference[]) Conversions.unwrapArray(CollectionLiterals.<TypeReference>emptyList(), TypeReference.class))).remove();
final Procedure0 _function_3 = () -> {
annotatedTargetElement.setExtendedInterfaces(null);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "superinterfaces cannot be null", _function_3);
final Procedure0 _function_4 = () -> {
annotatedTargetElement.setExtendedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList((TypeReference) null)));
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "superinterfaces cannot contain null", _function_4);
annotatedTargetElement.setExtendedInterfaces(CollectionLiterals.<TypeReference>emptyList());
final Procedure1<AnnotationReferenceBuildContext> _function_5 = (AnnotationReferenceBuildContext it) -> {
final Procedure0 _function_6 = () -> {
it.set(null, null);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_6);
final Procedure0 _function_7 = () -> {
it.set(null, "foo");
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_7);
final Procedure0 _function_8 = () -> {
String[] _xblockexpression = null;
{
final String[] array = { "foo" };
_xblockexpression = array;
}
it.set(null, _xblockexpression);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_8);
final Procedure0 _function_9 = () -> {
it.set(null, Boolean.valueOf(true));
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_9);
final Procedure0 _function_10 = () -> {
it.set(null, ((boolean[]) ((boolean[]) Conversions.unwrapArray(Collections.<Boolean>unmodifiableList(CollectionLiterals.<Boolean>newArrayList(Boolean.valueOf(true))), boolean.class))));
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_10);
final Procedure0 _function_11 = () -> {
it.set(null, Integer.valueOf(0));
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_11);
final Procedure0 _function_12 = () -> {
it.set(null, ((int[]) ((int[]) Conversions.unwrapArray(Collections.<Integer>unmodifiableList(CollectionLiterals.<Integer>newArrayList(Integer.valueOf(0))), int.class))));
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_12);
final Procedure0 _function_13 = () -> {
String[] _xblockexpression = null;
{
final String[] array = { "foo" };
_xblockexpression = array;
}
it.set("doesNotExist", _xblockexpression);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "The annotation property \'doesNotExist\' is not declared on the annotation type \'java.lang.Deprecated\'.", _function_13);
};
final AnnotationReference annotationReference = annotatedTargetElement.addAnnotation(context.newAnnotationReference(Deprecated.class, _function_5));
annotatedTargetElement.removeAnnotation(annotationReference);
final Procedure1<AnnotationReferenceBuildContext> _function_6 = (AnnotationReferenceBuildContext it) -> {
String[] _xblockexpression = null;
{
final String[] array = { "foo" };
_xblockexpression = array;
}
it.set("value", _xblockexpression);
final Procedure0 _function_7 = () -> {
int[] _xblockexpression_1 = null;
{
final int[] array = { 1 };
_xblockexpression_1 = array;
}
it.set("value", _xblockexpression_1);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "int[] is not applicable at this location. Expected java.lang.String[]", _function_7);
};
final AnnotationReference otherAnnotationReference = annotatedTargetElement.addAnnotation(context.newAnnotationReference(SuppressWarnings.class, _function_6));
annotatedTargetElement.removeAnnotation(otherAnnotationReference);
final Procedure1<AnnotationReferenceBuildContext> _function_7 = (AnnotationReferenceBuildContext it) -> {
it.set("validators", new TypeReference[0]);
it.set("validators", context.newTypeReference(String.class));
final Procedure0 _function_8 = () -> {
it.set("validators", new String[0]);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "java.lang.String[] is not applicable at this location. Expected org.eclipse.xtend.lib.macro.declaration.TypeReference[]", _function_8);
final Procedure0 _function_9 = () -> {
it.set("validators", new Object[0]);
};
MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot set annotation values of type java.lang.Object[]", _function_9);
};
final AnnotationReference composedChecksReference = annotatedTargetElement.addAnnotation(context.newAnnotationReference(ComposedChecks.class, _function_7));
annotatedTargetElement.removeAnnotation(composedChecksReference);
}
}
}
use of org.eclipse.xtend.lib.macro.declaration.AnnotationReference in project xtext-xtend by eclipse.
the class CompilationUnitImpl method translateAnnotationValue.
public Object translateAnnotationValue(final JvmAnnotationValue value, final boolean isArray) {
Pair<List<?>, Class<?>> _switchResult = null;
boolean _matched = false;
if (value instanceof JvmCustomAnnotationValue) {
if ((((JvmCustomAnnotationValue) value).getValues().isEmpty() && isArray)) {
_matched = true;
List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
Class<?> _arrayComponentType = this.toArrayComponentType(this.findExpectedType(value));
_switchResult = Pair.<List<?>, Class<?>>of(_emptyList, _arrayComponentType);
}
}
if (!_matched) {
if (value instanceof JvmCustomAnnotationValue) {
_matched = true;
final JvmTypeReference expectedType = this.findExpectedType(value);
final Function1<XExpression, Object> _function = (XExpression it) -> {
return this.evaluate(it, expectedType);
};
final Object result = IterableExtensions.<Object>head(IterableExtensions.<XExpression, Object>map(Iterables.<XExpression>filter(((JvmCustomAnnotationValue) value).getValues(), XExpression.class), _function));
return this.translateAnnotationValue(result, expectedType, isArray);
}
}
if (!_matched) {
if (value instanceof JvmTypeAnnotationValue) {
_matched = true;
final Function1<JvmTypeReference, TypeReference> _function = (JvmTypeReference it) -> {
return this.toTypeReference(it);
};
List<TypeReference> _map = ListExtensions.<JvmTypeReference, TypeReference>map(((JvmTypeAnnotationValue) value).getValues(), _function);
_switchResult = Pair.<List<?>, Class<?>>of(_map, TypeReference.class);
}
}
if (!_matched) {
if (value instanceof JvmAnnotationAnnotationValue) {
_matched = true;
final Function1<JvmAnnotationReference, AnnotationReference> _function = (JvmAnnotationReference it) -> {
return this.toAnnotationReference(it);
};
List<AnnotationReference> _map = ListExtensions.<JvmAnnotationReference, AnnotationReference>map(((JvmAnnotationAnnotationValue) value).getValues(), _function);
_switchResult = Pair.<List<?>, Class<?>>of(_map, AnnotationReference.class);
}
}
if (!_matched) {
if (value instanceof JvmStringAnnotationValue) {
_matched = true;
EList<String> _values = ((JvmStringAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, String.class);
}
}
if (!_matched) {
if (value instanceof JvmBooleanAnnotationValue) {
_matched = true;
EList<Boolean> _values = ((JvmBooleanAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, boolean.class);
}
}
if (!_matched) {
if (value instanceof JvmIntAnnotationValue) {
_matched = true;
EList<Integer> _values = ((JvmIntAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, int.class);
}
}
if (!_matched) {
if (value instanceof JvmByteAnnotationValue) {
_matched = true;
EList<Byte> _values = ((JvmByteAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, byte.class);
}
}
if (!_matched) {
if (value instanceof JvmCharAnnotationValue) {
_matched = true;
EList<Character> _values = ((JvmCharAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, char.class);
}
}
if (!_matched) {
if (value instanceof JvmDoubleAnnotationValue) {
_matched = true;
EList<Double> _values = ((JvmDoubleAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, double.class);
}
}
if (!_matched) {
if (value instanceof JvmEnumAnnotationValue) {
_matched = true;
final Function1<JvmEnumerationLiteral, NamedElement> _function = (JvmEnumerationLiteral it) -> {
return this.toNamedElement(it);
};
List<NamedElement> _map = ListExtensions.<JvmEnumerationLiteral, NamedElement>map(((JvmEnumAnnotationValue) value).getValues(), _function);
_switchResult = Pair.<List<?>, Class<?>>of(_map, EnumerationValueDeclaration.class);
}
}
if (!_matched) {
if (value instanceof JvmFloatAnnotationValue) {
_matched = true;
EList<Float> _values = ((JvmFloatAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, float.class);
}
}
if (!_matched) {
if (value instanceof JvmLongAnnotationValue) {
_matched = true;
EList<Long> _values = ((JvmLongAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, long.class);
}
}
if (!_matched) {
if (value instanceof JvmShortAnnotationValue) {
_matched = true;
EList<Short> _values = ((JvmShortAnnotationValue) value).getValues();
_switchResult = Pair.<List<?>, Class<?>>of(_values, short.class);
}
}
if (!_matched) {
List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
_switchResult = Pair.<List<?>, Class<?>>of(_emptyList, Object.class);
}
final Pair<List<?>, Class<?>> result = _switchResult;
if (isArray) {
return this.toArrayOfType(result.getKey(), result.getValue());
} else {
return IterableExtensions.head(result.getKey());
}
}
use of org.eclipse.xtend.lib.macro.declaration.AnnotationReference in project xtext-xtend by eclipse.
the class JvmAnnotationTargetImpl method addAnnotation.
public AnnotationReference addAnnotation(final AnnotationReference annotationReference) {
AnnotationReference _xblockexpression = null;
{
this.checkMutable();
Preconditions.checkArgument((annotationReference != null), "annotationReference cannot be null");
AnnotationReference _xifexpression = null;
if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
AnnotationReference _xblockexpression_1 = null;
{
final JvmAnnotationReference jvmAnnotationReference = EcoreUtil2.<JvmAnnotationReference>cloneWithProxies(((JvmAnnotationReferenceImpl) annotationReference).getDelegate());
EList<JvmAnnotationReference> _annotations = this.getDelegate().getAnnotations();
_annotations.add(jvmAnnotationReference);
_xblockexpression_1 = this.getCompilationUnit().toAnnotationReference(jvmAnnotationReference);
}
_xifexpression = _xblockexpression_1;
} else {
StringConcatenation _builder = new StringConcatenation();
_builder.append(annotationReference);
_builder.append(" is not annotation reference");
throw new IllegalArgumentException(_builder.toString());
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
use of org.eclipse.xtend.lib.macro.declaration.AnnotationReference in project xtext-xtend by eclipse.
the class JvmMemberDeclarationImpl method setDeprecated.
public void setDeprecated(final boolean deprecated) {
this.checkMutable();
if (deprecated) {
T _delegate = this.getDelegate();
_delegate.setDeprecated(true);
this.addAnnotation(this.getCompilationUnit().getAnnotationReferenceProvider().newAnnotationReference(Deprecated.class));
} else {
T _delegate_1 = this.getDelegate();
_delegate_1.setDeprecated(false);
final AnnotationReference existingReference = this.findAnnotation(this.getCompilationUnit().getTypeLookup().findTypeGlobally(Deprecated.class));
if ((existingReference != null)) {
this.removeAnnotation(existingReference);
}
}
}
Aggregations