use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.
the class AbstractModelLoader method getJavaAnnotationExtendedType.
private Type getJavaAnnotationExtendedType(ClassOrInterface klass, ClassMirror classMirror) {
TypeDeclaration constrainedAnnotation = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CONSTRAINED_ANNOTATION_TYPE, klass, DeclarationType.TYPE);
AnnotationMirror target = classMirror.getAnnotation("java.lang.annotation.Target");
Set<Type> types = new HashSet<Type>();
if (target != null) {
@SuppressWarnings("unchecked") List<String> values = (List<String>) target.getValue();
for (String value : values) {
switch(value) {
case "TYPE":
TypeDeclaration decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_OR_INTERFACE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_ALIAS_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "ANNOTATION_TYPE":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_OR_INTERFACE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "CONSTRUCTOR":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CONSTRUCTOR_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
if (!values.contains("TYPE")) {
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_WITH_INIT_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
}
break;
case "METHOD":
// method annotations may be applied to shared members which are turned into getter methods
case "PARAMETER":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_FUNCTION_OR_VALUE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "FIELD":
case "LOCAL_VARIABLE":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_VALUE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "PACKAGE":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_PACKAGE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
default:
}
}
}
Module module = ModelUtil.getModuleContainer(klass);
Type annotatedType;
if (types.size() == 1)
annotatedType = types.iterator().next();
else if (types.isEmpty()) {
TypeDeclaration decl;
if (target == null) {
// default is anything
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_ANNOTATED_TYPE, klass, DeclarationType.TYPE);
} else {
// we either had an empty set which means cannot be used as annotation in Java (only as annotation member)
// or that we only had unmappable targets
decl = typeFactory.getNothingDeclaration();
}
annotatedType = decl.getType();
} else {
List<Type> list = new ArrayList<Type>(types.size());
list.addAll(types);
annotatedType = union(list, getUnitForModule(module));
}
Type constrainedType = constrainedAnnotation.appliedType(null, Arrays.asList(klass.getType(), getOptionalType(klass.getType(), module), annotatedType));
return constrainedType;
}
use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.
the class AbstractModelLoader method makeToplevelAttribute.
protected LazyValue makeToplevelAttribute(ClassMirror classMirror, boolean isNativeHeader) {
LazyValue value = new LazyValue(classMirror, this);
AnnotationMirror objectAnnotation = classMirror.getAnnotation(CEYLON_OBJECT_ANNOTATION);
if (objectAnnotation == null) {
manageNativeBackend(value, classMirror, isNativeHeader);
} else {
manageNativeBackend(value, getGetterMethodMirror(value, value.classMirror, true), isNativeHeader);
}
return value;
}
use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.
the class AbstractModelLoader method checkBinaryCompatibility.
private void checkBinaryCompatibility(ClassMirror classMirror) {
// let's not report it twice
if (binaryCompatibilityErrorRaised)
return;
AnnotationMirror annotation = classMirror.getAnnotation(CEYLON_CEYLON_ANNOTATION);
if (annotation == null)
// Java class, no check
return;
Integer major = (Integer) annotation.getValue("major");
if (major == null)
major = 0;
Integer minor = (Integer) annotation.getValue("minor");
if (minor == null)
minor = 0;
if (!Versions.isJvmBinaryVersionSupported(major.intValue(), minor.intValue())) {
logError("Ceylon class " + classMirror.getQualifiedName() + " was compiled by an incompatible version of the Ceylon compiler" + "\nThe class was compiled using " + major + "." + minor + "." + "\nThis compiler supports " + Versions.JVM_BINARY_MAJOR_VERSION + "." + Versions.JVM_BINARY_MINOR_VERSION + "." + "\nPlease try to recompile your module using a compatible compiler." + "\nBinary compatibility will only be supported after Ceylon 1.2.");
binaryCompatibilityErrorRaised = true;
}
}
use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.
the class AbstractModelLoader method setAnnotations.
private void setAnnotations(Annotated annotated, AnnotatedMirror classMirror, boolean isNativeHeader) {
if (classMirror.getAnnotation(CEYLON_ANNOTATIONS_ANNOTATION) != null) {
// If the class has @Annotations then use it (in >=1.2 only ceylon.language does)
Long mods = (Long) getAnnotationValue(classMirror, CEYLON_ANNOTATIONS_ANNOTATION, "modifiers");
if (mods != null) {
// If there is a modifiers value then use it to load the modifiers
for (LanguageAnnotation mod : LanguageAnnotation.values()) {
if (mod.isModifier()) {
if ((mod.mask & mods) != 0) {
annotated.getAnnotations().addAll(mod.makeFromCeylonAnnotation(null));
}
}
}
}
// Load anything else the long way, reading the @Annotation(name=...)
List<AnnotationMirror> annotations = getAnnotationArrayValue(classMirror, CEYLON_ANNOTATIONS_ANNOTATION);
if (annotations != null) {
for (AnnotationMirror annotation : annotations) {
annotated.getAnnotations().add(readModelAnnotation(annotation));
}
}
} else {
// according to the presence of @Shared$annotation etc
for (LanguageAnnotation mod : LanguageAnnotation.values()) {
if (classMirror.getAnnotation(mod.annotationType) != null) {
annotated.getAnnotations().addAll(mod.makeFromCeylonAnnotation(classMirror.getAnnotation(mod.annotationType)));
}
}
// but the typechecker wants them on the Class model.
if ((annotated instanceof Class) && ((Class) annotated).isAnonymous()) {
Class clazz = (Class) annotated;
Declaration objectValue = clazz.getContainer().getDirectMember(clazz.getName(), null, false);
if (objectValue != null) {
annotated.getAnnotations().addAll(objectValue.getAnnotations());
}
}
}
boolean hasCeylonDeprecated = false;
for (Annotation a : annotated.getAnnotations()) {
if (a.getName().equals("deprecated")) {
hasCeylonDeprecated = true;
break;
}
}
// and doesn't already have the ceylon annotation
if (classMirror.getAnnotation(JAVA_DEPRECATED_ANNOTATION) != null) {
if (!hasCeylonDeprecated) {
Annotation modelAnnotation = new Annotation();
modelAnnotation.setName("deprecated");
modelAnnotation.getPositionalArguments().add("");
annotated.getAnnotations().add(modelAnnotation);
hasCeylonDeprecated = true;
}
}
if (annotated instanceof Declaration && !((Declaration) annotated).getNativeBackends().none()) {
// Do nothing :
// it has already been managed when in the makeLazyXXX() function
} else {
manageNativeBackend(annotated, classMirror, isNativeHeader);
}
}
use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.
the class ReflectionUtils method getAnnotations.
public static Map<String, AnnotationMirror> getAnnotations(Annotation[] annotations) {
if (annotations.length == 0)
return Collections.<String, AnnotationMirror>emptyMap();
Map<String, AnnotationMirror> map = new HashMap<String, AnnotationMirror>();
for (int i = annotations.length - 1; i >= 0; i--) {
Annotation annotation = annotations[i];
map.put(annotation.annotationType().getName(), new ReflectionAnnotation(annotation));
}
return map;
}
Aggregations