use of org.eclipse.ceylon.model.loader.model.AnnotationProxyClass in project ceylon by eclipse.
the class AbstractModelLoader method getRepeatableContainer.
public Interface getRepeatableContainer(Class c) {
if (c instanceof AnnotationProxyClass) {
AnnotationMirror mirror = ((AnnotationProxyClass) c).iface.classMirror.getAnnotation("java.lang.annotation.Repeatable");
if (mirror != null) {
TypeMirror m = (TypeMirror) mirror.getValue();
Module module = findModuleForClassMirror(m.getDeclaredClass());
return (Interface) convertDeclaredTypeToDeclaration(module, m, DeclarationType.TYPE);
}
}
return null;
}
use of org.eclipse.ceylon.model.loader.model.AnnotationProxyClass in project ceylon by eclipse.
the class AbstractModelLoader method makeInteropAnnotation.
/**
* Creates extra members to be added to the {@code container} for annotation interop.
* For a Java declaration {@code @interface Annotation} we generate
* a model corresponding to:
* <pre>
* annotation class Annotation$Proxy(...) satisfies Annotation {
* // a `shared` class parameter for each method of Annotation
* }
* annotation JavaAnnotation javaAnnotation(...) => JavaAnnotation$Proxy(...);
* </pre>
*
* We also make a {@code *__method}, {@code *__field} etc version for each
* {@code @Target} program element
* @param iface The model of the annotation @interface
* @param container The container in which the generated members belong
* @return A list of members to add to the container
*/
public List<Declaration> makeInteropAnnotation(LazyInterface iface, Scope container) {
List<Declaration> declarations = new ArrayList<>();
AnnotationProxyClass klass = makeInteropAnnotationClass(iface, container);
AnnotationProxyMethod method = makeInteropAnnotationConstructor(iface, klass, null, container);
declarations.add(method);
for (OutputElement target : AnnotationTarget.outputTargets(klass)) {
declarations.add(makeInteropAnnotationConstructor(iface, klass, target, container));
}
declarations.add(klass);
return declarations;
}
use of org.eclipse.ceylon.model.loader.model.AnnotationProxyClass in project ceylon by eclipse.
the class AbstractModelLoader method makeInteropAnnotationClass.
/**
* <pre>
* annotation class Annotation$Proxy(...) satisfies Annotation {
* // a `shared` class parameter for each method of Annotation
* }
* </pre>
* @param iface The model of the annotation @interface
* @return The annotation class for the given interface
*/
public AnnotationProxyClass makeInteropAnnotationClass(LazyInterface iface, Scope scope) {
AnnotationProxyClass klass = new AnnotationProxyClass(this, iface);
klass.setContainer(scope);
klass.setScope(scope);
if (!(scope instanceof Package)) {
klass.setStatic(true);
}
klass.setName(iface.getName() + "$Proxy");
klass.setShared(iface.isShared());
klass.setAnnotation(true);
Annotation annotationAnnotation = new Annotation();
annotationAnnotation.setName("annotation");
klass.getAnnotations().add(annotationAnnotation);
klass.getSatisfiedTypes().add(iface.getType());
klass.setUnit(iface.getUnit());
klass.setScope(scope);
return klass;
}
use of org.eclipse.ceylon.model.loader.model.AnnotationProxyClass in project ceylon by eclipse.
the class AnnotationUtil method interopAnnotationTargeting.
/**
* Returns the set of output program elements that the given annotation
* could be applied to. If the {@code errors} flag is true then add
* warnings/errors to the tree about ambiguous/impossible targets.
*/
public static EnumSet<OutputElement> interopAnnotationTargeting(boolean isEe, EnumSet<OutputElement> outputs, Tree.Annotation annotation, boolean errors, boolean warnings, Declaration d) {
Declaration annoCtor = ((Tree.BaseMemberExpression) annotation.getPrimary()).getDeclaration();
if (annoCtor instanceof AnnotationProxyMethod) {
AnnotationProxyMethod proxyCtor = (AnnotationProxyMethod) annoCtor;
AnnotationProxyClass annoClass = proxyCtor.getProxyClass();
EnumSet<OutputElement> possibleTargets;
if (proxyCtor.getAnnotationTarget() != null) {
possibleTargets = EnumSet.of(proxyCtor.getAnnotationTarget());
} else {
possibleTargets = AnnotationTarget.outputTargets(annoClass);
}
EnumSet<OutputElement> actualTargets = possibleTargets.clone();
actualTargets.retainAll(outputs);
if (actualTargets.size() > 1) {
if (warnings) {
StringBuffer sb = new StringBuffer();
sb.append("ambiguous annotation target: ").append(annoCtor.getName());
sb.append(" could be applied to several targets, use one of ");
for (Iterator<OutputElement> iterator = actualTargets.iterator(); iterator.hasNext(); ) {
OutputElement x = iterator.next();
sb.append(Naming.getDisambigAnnoCtorName((Interface) ((AnnotationProxyMethod) annoCtor).getProxyClass().iface, x));
if (iterator.hasNext()) {
sb.append(", ");
}
}
sb.append(" to disambiguate");
annotation.addUsageWarning(Warning.ambiguousAnnotation, sb.toString(), Backend.Java);
}
checkForLateFieldAnnotation(isEe, annotation, d, annoCtor, possibleTargets, actualTargets);
return null;
} else if (actualTargets.size() == 0) {
if (errors) {
annotation.addError("no target for " + annoCtor.getName() + " annotation: @Target of @interface " + ((AnnotationProxyClass) annoClass).iface.getName() + " lists " + possibleTargets + " but annotated element tranforms to " + outputs, Backend.Java);
}
}
checkForLateFieldAnnotation(isEe, annotation, d, annoCtor, possibleTargets, actualTargets);
return actualTargets;
} else {
return null;
}
}
Aggregations