Search in sources :

Example 21 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class MetamodelGenerator method encodeAnnotations.

/**
 * Encodes all annotations as a map which is then stored under the
 * {@link #KEY_ANNOTATIONS} key in the specified map.
 * If the map is null, only the bitset annotations are calculated and returned.
 * @return The bitmask for the bitset annotations.
 */
public static int encodeAnnotations(List<Annotation> annotations, Object d, Map<String, Object> m) {
    List<Map<String, List<String>>> anns = m == null ? null : new ArrayList<Map<String, List<String>>>(annotations.size());
    int bits = 0;
    for (Annotation a : annotations) {
        String name = a.getName();
        int idx = "native".equals(name) ? -1 : annotationBits.indexOf(name);
        if (idx >= 0) {
            bits |= (1 << idx);
        } else if (anns != null) {
            List<String> args = a.getPositionalArguments();
            if (args == null) {
                args = Collections.emptyList();
            }
            anns.add(Collections.singletonMap(name, args));
        }
    }
    if (d instanceof Value && ((Value) d).isVariable()) {
        // Sometimes the value is not annotated, it only has a defined Setter
        bits |= (1 << annotationBits.indexOf("variable"));
    } else if (d instanceof org.eclipse.ceylon.model.typechecker.model.Class && ((org.eclipse.ceylon.model.typechecker.model.Class) d).isAbstract()) {
        bits |= (1 << annotationBits.indexOf("abstract"));
    } else if (d instanceof Constructor && ((Constructor) d).isAbstract()) {
        bits |= (1 << annotationBits.indexOf("abstract"));
    }
    if (bits > 0 && m != null) {
        String key = d instanceof Module ? "$mod-pa" : d instanceof org.eclipse.ceylon.model.typechecker.model.Package ? "$pkg-pa" : KEY_PACKED_ANNS;
        m.put(key, bits);
    }
    if (anns != null && m != null && !anns.isEmpty()) {
        String key = d instanceof Module ? "$mod-anns" : d instanceof org.eclipse.ceylon.model.typechecker.model.Package ? "$pkg-anns" : KEY_ANNOTATIONS;
        m.put(key, anns);
    }
    return bits;
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) List(java.util.List) Module(org.eclipse.ceylon.model.typechecker.model.Module) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation 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;
}
Also used : AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 23 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation 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);
    }
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 24 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class ClassOrPackageDoc method writeAliases.

protected final void writeAliases(Declaration decl) throws IOException {
    Annotation see = Util.getAnnotation(decl.getUnit(), decl.getAnnotations(), "aliased");
    if (see == null)
        return;
    open("div class='aliased section'");
    around("span class='title'", "Aliases: ");
    open("span class='value'");
    boolean first = true;
    for (String target : see.getPositionalArguments()) {
        if (!first) {
            write(", ");
        } else {
            first = false;
        }
        open("code class='signature'");
        String cssClass = decl instanceof TypeDeclaration ? "type-identifier" : "identifier";
        open("span class='" + cssClass + "'");
        write(target);
        close("span");
        close("code");
    }
    close("span");
    close("div");
}
Also used : TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 25 with Annotation

use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.

the class ClassOrPackageDoc method writeParameterAssertions.

private void writeParameterAssertions(Declaration decl, Map<Tree.Assertion, List<Tree.Condition>> parameterAssertions) throws IOException {
    if (parameterAssertions == null || parameterAssertions.isEmpty()) {
        return;
    }
    PhasedUnit pu = tool.getUnit(decl);
    open("div class='assertions' title='Parameter assertions'");
    open("ul");
    for (Tree.Assertion assertion : parameterAssertions.keySet()) {
        List<Annotation> annotations = new ArrayList<Annotation>();
        buildAnnotations(assertion.getAnnotationList(), annotations);
        String doc = Util.getRawDoc(decl.getUnit(), annotations);
        if (!Util.isEmpty(doc)) {
            open("li");
            write("<i class='icon-assertion'></i>");
            write(Util.wikiToHTML(doc, linkRenderer()));
            close("li");
        } else {
            for (Tree.Condition c : parameterAssertions.get(assertion)) {
                String sourceCode = getSourceCode(pu, c);
                open("li");
                write("<i class='icon-assertion'></i>");
                around("code", sourceCode);
                close("li");
            }
        }
    }
    close("ul");
    close("div");
}
Also used : ArrayList(java.util.ArrayList) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Aggregations

Annotation (org.eclipse.ceylon.model.typechecker.model.Annotation)30 ArrayList (java.util.ArrayList)10 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)7 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)6 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)6 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)5 List (java.util.List)4 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)4 Package (org.eclipse.ceylon.model.typechecker.model.Package)4 Value (org.eclipse.ceylon.model.typechecker.model.Value)4 HashMap (java.util.HashMap)3 Class (org.eclipse.ceylon.model.typechecker.model.Class)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)3 Map (java.util.Map)2 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)2 ExpressionVisitor.getRefinedMemberReference (org.eclipse.ceylon.compiler.typechecker.analyzer.ExpressionVisitor.getRefinedMemberReference)2 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)2