Search in sources :

Example 1 with Annotation

use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method writeThrows.

protected final void writeThrows(Declaration decl) throws IOException {
    boolean first = true;
    for (Annotation annotation : decl.getAnnotations()) {
        if (annotation.getName().equals("throws")) {
            String excType = annotation.getPositionalArguments().get(0);
            String excDesc = annotation.getPositionalArguments().size() == 2 ? annotation.getPositionalArguments().get(1) : null;
            if (first) {
                first = false;
                open("div class='throws section'");
                around("span class='title'", "Throws ");
                open("ul");
            }
            open("li");
            linkRenderer().to(excType).withinText(true).useScope(decl).write();
            if (excDesc != null) {
                write(Util.wikiToHTML(excDesc, linkRenderer().useScope(decl)));
            }
            close("li");
        }
    }
    if (!first) {
        close("ul");
        close("div");
    }
    tool.warningMissingThrows(decl);
}
Also used : Annotation(com.redhat.ceylon.model.typechecker.model.Annotation)

Example 2 with Annotation

use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.

the class CeylonDoc method getIcons.

protected final List<String> getIcons(Object obj) {
    List<String> icons = new ArrayList<String>();
    if (obj instanceof Declaration) {
        Declaration decl = (Declaration) obj;
        Annotation deprecated = Util.findAnnotation(decl, "deprecated");
        if (deprecated != null) {
            icons.add("icon-decoration-deprecated");
        }
        if (decl instanceof ClassOrInterface || decl instanceof Constructor) {
            if (decl instanceof Interface) {
                icons.add("icon-interface");
                if (Util.isEnumerated((ClassOrInterface) decl)) {
                    icons.add("icon-decoration-enumerated");
                }
            }
            if (decl instanceof Class) {
                Class klass = (Class) decl;
                if (klass.isAnonymous()) {
                    icons.add("icon-object");
                } else {
                    icons.add("icon-class");
                }
                if (klass.isAbstract()) {
                    icons.add("icon-decoration-abstract");
                }
                if (klass.isFinal() && !klass.isAnonymous() && !klass.isAnnotation()) {
                    icons.add("icon-decoration-final");
                }
                if (Util.isEnumerated(klass)) {
                    icons.add("icon-decoration-enumerated");
                }
            }
            if (decl instanceof Constructor) {
                icons.add("icon-class");
            }
            if (!decl.isShared()) {
                icons.add("icon-decoration-local");
            }
        }
        if (decl instanceof TypedDeclaration) {
            if (decl.isShared()) {
                icons.add("icon-shared-member");
            } else {
                icons.add("icon-local-member");
            }
            if (decl.isFormal()) {
                icons.add("icon-decoration-formal");
            }
            if (decl.isActual()) {
                Declaration refinedDeclaration = decl.getRefinedDeclaration();
                if (refinedDeclaration != null) {
                    if (refinedDeclaration.isFormal()) {
                        icons.add("icon-decoration-impl");
                    }
                    if (refinedDeclaration.isDefault()) {
                        icons.add("icon-decoration-over");
                    }
                }
            }
            if (((TypedDeclaration) decl).isVariable()) {
                icons.add("icon-decoration-variable");
            }
        }
        if (decl instanceof TypeAlias || decl instanceof NothingType) {
            icons.add("icon-type-alias");
        }
        if (decl.isAnnotation()) {
            icons.add("icon-decoration-annotation");
        }
    }
    if (obj instanceof Package) {
        Package pkg = (Package) obj;
        icons.add("icon-package");
        if (!pkg.isShared()) {
            icons.add("icon-decoration-local");
        }
    }
    if (obj instanceof ModuleImport) {
        ModuleImport moduleImport = (ModuleImport) obj;
        icons.add("icon-module");
        if (moduleImport.isExport()) {
            icons.add("icon-module-exported-decoration");
        }
        if (moduleImport.isOptional()) {
            icons.add("icon-module-optional-decoration");
        }
    }
    if (obj instanceof Module) {
        icons.add("icon-module");
    }
    return icons;
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) TypeAlias(com.redhat.ceylon.model.typechecker.model.TypeAlias) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) Class(com.redhat.ceylon.model.typechecker.model.Class) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) NothingType(com.redhat.ceylon.model.typechecker.model.NothingType)

Example 3 with Annotation

use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method writeDeprecated.

private void writeDeprecated(Declaration decl) throws IOException {
    Annotation deprecated = Util.findAnnotation(decl, "deprecated");
    if (deprecated != null) {
        open("div class='deprecated section'");
        String text = "<span class='title'>Deprecated: </span>";
        if (!deprecated.getPositionalArguments().isEmpty()) {
            String reason = deprecated.getPositionalArguments().get(0);
            if (reason != null) {
                text += reason;
            }
        }
        write(Util.wikiToHTML(text, linkRenderer().useScope(decl)));
        close("div");
    }
}
Also used : Annotation(com.redhat.ceylon.model.typechecker.model.Annotation)

Example 4 with Annotation

use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.

the class CeylonDocTool method docNothingType.

private void docNothingType(Package pkg) throws IOException {
    final Annotation nothingDoc = new Annotation();
    nothingDoc.setName("doc");
    nothingDoc.addPositionalArgment("The special type _Nothing_ represents: \n" + " - the intersection of all types, or, equivalently \n" + " - the empty set \n" + "\n" + "_Nothing_ is assignable to all other types, but has no instances. \n" + "A reference to a member of an expression of type _Nothing_ is always an error, since there can never be a receiving instance. \n" + "_Nothing_ is considered to belong to the module _ceylon.language_. However, it cannot be defined within the language. \n" + "\n" + "Because of the restrictions imposed by Ceylon's mixin inheritance model: \n" + "- If X and Y are classes, and X is not a subclass of Y, and Y is not a subclass of X, then the intersection type X&Y is equivalent to _Nothing_. \n" + "- If X is an interface, the intersection type X&Nothing is equivalent to _Nothing_. \n" + "- If X&lt;T&gt; is invariant in its type parameter T, and the distinct types A and B do not involve type parameters, then X&lt;A&gt;&X&lt;B&gt; is equivalent to _Nothing_. \n");
    NothingType nothingType = new NothingType(pkg.getUnit()) {

        @Override
        public List<Annotation> getAnnotations() {
            return Collections.singletonList(nothingDoc);
        }
    };
    doc(nothingType);
}
Also used : Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) NothingType(com.redhat.ceylon.model.typechecker.model.NothingType)

Example 5 with Annotation

use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeAtAnnotations.

List<JCAnnotation> makeAtAnnotations(java.util.List<Annotation> annotations) {
    if (!simpleAnnotationModels || annotations == null || annotations.isEmpty())
        return List.nil();
    long modifiers = 0;
    ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
    for (Annotation annotation : annotations) {
        if (isOmittedModelAnnotation(annotation)) {
            continue;
        }
        Long mask = getModelModifierMask(annotation);
        if (mask != null && mask != 0) {
            modifiers |= mask;
        } else {
            array.append(makeAtAnnotation(annotation));
        }
    }
    if (modifiers == 0 && array.isEmpty()) {
        return List.<JCAnnotation>nil();
    }
    List<JCExpression> annotationsAndMods = List.<JCExpression>nil();
    if (!array.isEmpty()) {
        annotationsAndMods = annotationsAndMods.prepend(make().Assign(naming.makeUnquotedIdent("value"), make().NewArray(null, null, array.toList())));
    }
    if (modifiers != 0L) {
        annotationsAndMods = annotationsAndMods.prepend(make().Assign(naming.makeUnquotedIdent("modifiers"), make().Literal(modifiers)));
    }
    return makeModelAnnotation(syms().ceylonAtAnnotationsType, annotationsAndMods);
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) LanguageAnnotation(com.redhat.ceylon.model.loader.LanguageAnnotation) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Aggregations

Annotation (com.redhat.ceylon.model.typechecker.model.Annotation)13 ArrayList (java.util.ArrayList)5 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)3 NothingType (com.redhat.ceylon.model.typechecker.model.NothingType)3 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)2 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)2 LanguageAnnotation (com.redhat.ceylon.model.loader.LanguageAnnotation)2 Module (com.redhat.ceylon.model.typechecker.model.Module)2 Package (com.redhat.ceylon.model.typechecker.model.Package)2 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)2 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)2 JCTree (com.sun.tools.javac.tree.JCTree)2 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)2 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)2 ListBuffer (com.sun.tools.javac.util.ListBuffer)2 SourceDeclarationVisitor (com.redhat.ceylon.compiler.java.loader.SourceDeclarationVisitor)1 Node (com.redhat.ceylon.compiler.typechecker.tree.Node)1 Expression (com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression)1 Visitor (com.redhat.ceylon.compiler.typechecker.tree.Visitor)1 Class (com.redhat.ceylon.model.typechecker.model.Class)1