use of com.redhat.ceylon.model.loader.model.AnnotationTarget in project ceylon-compiler by ceylon.
the class ExpressionTransformer method isNaturalTarget.
/**
* Whether an annotation (with the given {@code annotationCtorDecl}
* annotation constructor) used on the given declaration ({@code useSite})
* should be added to the Java annotations of the given generated program
* elements ({@code target})
* @param annotationCtorDecl
* @param useSite
* @param target
* @return
*/
private boolean isNaturalTarget(// use site is either a Declaration, or a Package, or a Module,
Function annotationCtorDecl, // module imports
Object useSite, OutputElement target) {
EnumSet<AnnotationTarget> interopTargets;
if (annotationCtorDecl instanceof AnnotationProxyMethod) {
AnnotationProxyMethod annotationProxyMethod = (AnnotationProxyMethod) annotationCtorDecl;
if (annotationProxyMethod.getAnnotationTarget() == target) {
// Foo__WHATEVER, so honour the WHATEVER
return true;
}
interopTargets = annotationProxyMethod.getProxyClass().getAnnotationTarget();
} else {
interopTargets = null;
}
if (useSite instanceof Declaration) {
if (ModelUtil.isConstructor((Declaration) useSite)) {
if (useSite instanceof Functional) {
return target == OutputElement.CONSTRUCTOR;
} else if (useSite instanceof Value) {
return target == OutputElement.GETTER;
}
} else if (useSite instanceof Class) {
if (((Class) useSite).getParameterList() != null && interopTargets != null && interopTargets.contains(AnnotationTarget.CONSTRUCTOR) && !interopTargets.contains(AnnotationTarget.TYPE)) {
return target == OutputElement.CONSTRUCTOR;
}
return target == OutputElement.TYPE;
} else if (useSite instanceof Interface) {
return target == OutputElement.TYPE;
} else if (useSite instanceof Value) {
Value value = (Value) useSite;
TypeDeclaration decltype = typeFact().getValueDeclarationType().getDeclaration();
if (value.isParameter() && !value.isShared() && !(value.isCaptured() && value.isMember())) {
return target == OutputElement.PARAMETER;
} else if (annotationCtorDecl instanceof AnnotationProxyMethod) {
if (value.isLate() || value.isVariable()) {
return target == OutputElement.SETTER;
} else if (!value.isTransient()) {
return target == OutputElement.FIELD;
} else {
return target == OutputElement.GETTER;
}
} else {
return target == OutputElement.GETTER;
}
} else if (useSite instanceof Setter) {
return target == OutputElement.SETTER;
} else if (useSite instanceof Function) {
return target == OutputElement.METHOD;
} else if (useSite instanceof Constructor) {
return target == OutputElement.CONSTRUCTOR;
} else if (useSite instanceof TypeAlias) {
return target == OutputElement.TYPE;
}
} else if (useSite instanceof Package) {
return target == OutputElement.TYPE;
} else if (useSite instanceof Module) {
return target == OutputElement.TYPE;
} else if (useSite instanceof Tree.ImportModule) {
return target == OutputElement.FIELD;
}
throw new RuntimeException("" + useSite);
}
use of com.redhat.ceylon.model.loader.model.AnnotationTarget in project ceylon-compiler by ceylon.
the class ClassTransformer method transformAnnotationConstraints.
private List<JCAnnotation> transformAnnotationConstraints(Class klass) {
TypeDeclaration meta = (TypeDeclaration) typeFact().getLanguageModuleDeclaration("ConstrainedAnnotation");
Type constrainedType = klass.getType().getSupertype(meta);
EnumSet<AnnotationTarget> types = EnumSet.noneOf(AnnotationTarget.class);
if (constrainedType != null) {
Type programElement = constrainedType.getTypeArgumentList().get(2);
if (programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("InterfaceDeclaration")).getType()) || programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("ClassDeclaration")).getType()) || programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("ClassWithInitializerDeclaration")).getType()) || programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("ClassWithConstructorsDeclaration")).getType()) || programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("Package")).getType()) || programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("Module")).getType())) {
types.add(AnnotationTarget.TYPE);
}
if (programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("ValueDeclaration")).getType()) || programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("FunctionDeclaration")).getType())) {
types.add(AnnotationTarget.METHOD);
types.add(AnnotationTarget.PARAMETER);
}
if (programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("CallableConstructorDeclaration")).getType())) {
types.add(AnnotationTarget.CONSTRUCTOR);
}
if (programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("ValueConstructorDeclaration")).getType())) {
types.add(AnnotationTarget.METHOD);
}
if (programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("Import")).getType())) {
types.add(AnnotationTarget.FIELD);
}
if (programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("SetterDeclaration")).getType())) {
types.add(AnnotationTarget.METHOD);
}
if (programElement.covers(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("AliasDeclaration")).getType())) {
types.add(AnnotationTarget.TYPE);
}
}
return makeAtAnnotationTarget(types);
}
Aggregations