use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation in project ceylon by eclipse.
the class ForcedCaptureVisitor method isForcedCapture.
private boolean isForcedCapture(Tree.TypedDeclaration that) {
if (that.getAnnotationList() == null)
return false;
for (Annotation anno : that.getAnnotationList().getAnnotations()) {
Type type = anno.getTypeModel();
if (type == null || !type.isClassOrInterface())
continue;
TypeDeclaration decl = type.getDeclaration();
if (decl == null)
continue;
Module module = ModelUtil.getModule(decl);
if (module == null)
continue;
if (module.getLanguageModule() == module)
continue;
// does not come from the language module
return true;
}
return false;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation in project ceylon by eclipse.
the class UnsupportedVisitor method interopAnnotationTargeting.
private void interopAnnotationTargeting(EnumSet<OutputElement> outputs, Tree.AnnotationList annotationList, Tree.Declaration annotated) {
OutputElement target = null;
// let's do them as they come. See https://github.com/ceylon/ceylon/issues/5751
if (annotated instanceof Tree.AttributeDeclaration) {
if (((Tree.AttributeDeclaration) annotated).getSpecifierOrInitializerExpression() instanceof Tree.LazySpecifierExpression)
target = OutputElement.METHOD;
else
target = OutputElement.FIELD;
}
Declaration useSite = annotated.getDeclarationModel();
List<Annotation> annotations = annotationList.getAnnotations();
for (Tree.Annotation annotation : annotations) {
Function annoCtorDecl = ((Function) ((Tree.BaseMemberExpression) annotation.getPrimary()).getDeclaration());
boolean addWarnings = true;
// only add warnings if we don't have a natural target to pick from
if (target != null) {
addWarnings = !AnnotationUtil.isNaturalTarget(annoCtorDecl, useSite, target);
}
AnnotationUtil.interopAnnotationTargeting(eeVisitor.isEeMode(useSite), outputs, annotation, true, addWarnings, annotated.getDeclarationModel());
}
AnnotationUtil.duplicateInteropAnnotation(eeVisitor.isEeMode(useSite), outputs, annotations, annotated.getDeclarationModel());
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation in project ceylon by eclipse.
the class AnnotationUtil method duplicateInteropAnnotation.
public static void duplicateInteropAnnotation(boolean isEe, EnumSet<OutputElement> outputs, List<Annotation> annotations, Declaration d) {
for (int i = 0; i < annotations.size(); i++) {
Tree.Annotation ann = annotations.get(i);
Type t = ann.getTypeModel();
EnumSet<OutputElement> mainTargets = interopAnnotationTargeting(isEe, outputs, ann, false, false, d);
if (t != null && mainTargets != null) {
TypeDeclaration td = t.getDeclaration();
if (!ModelUtil.isCeylonDeclaration(td)) {
for (int j = 0; j < i; j++) {
Tree.Annotation other = annotations.get(j);
Type ot = other.getTypeModel();
if (ot != null) {
TypeDeclaration otd = ot.getDeclaration();
if (otd.equals(td)) {
// check if they have the same targets (if not that's fine)
EnumSet<OutputElement> dupeTargets = interopAnnotationTargeting(isEe, outputs, other, false, false, d);
if (dupeTargets != null) {
EnumSet<OutputElement> sameTargets = intersection(mainTargets, dupeTargets);
if (!sameTargets.isEmpty()) {
ann.addError("duplicate annotation: there are multiple annotations of type '" + td.getName() + "' for targets: '" + sameTargets + "'");
break;
}
}
}
}
}
}
}
}
}
Aggregations