Search in sources :

Example 1 with Annotation

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;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Module(org.eclipse.ceylon.model.typechecker.model.Module) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Annotation(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation)

Example 2 with Annotation

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());
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) OutputElement(org.eclipse.ceylon.model.loader.model.OutputElement) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Annotation(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation) Annotation(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation)

Example 3 with Annotation

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;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) OutputElement(org.eclipse.ceylon.model.loader.model.OutputElement) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Annotation(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

Annotation (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Annotation)3 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)2 OutputElement (org.eclipse.ceylon.model.loader.model.OutputElement)2 Type (org.eclipse.ceylon.model.typechecker.model.Type)2 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)2 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 Function (org.eclipse.ceylon.model.typechecker.model.Function)1 Module (org.eclipse.ceylon.model.typechecker.model.Module)1