Search in sources :

Example 6 with Annotation

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

the class AbstractTransformer method getLicenseAuthorsDocAnnotationArguments.

/** Returns a ListBuffer with assignment expressions for the doc, license and by arguments, as well as name,
     * to be used in an annotation which requires them (such as Module and Package) */
ListBuffer<JCExpression> getLicenseAuthorsDocAnnotationArguments(String name, java.util.List<Annotation> anns) {
    ListBuffer<JCExpression> authors = new ListBuffer<JCTree.JCExpression>();
    ListBuffer<JCExpression> res = new ListBuffer<JCExpression>();
    res.add(make().Assign(naming.makeUnquotedIdent("name"), make().Literal(name)));
    for (Annotation a : anns) {
        if (a.getPositionalArguments() != null && !a.getPositionalArguments().isEmpty()) {
            if (a.getName().equals("doc")) {
                res.add(make().Assign(naming.makeUnquotedIdent("doc"), make().Literal(a.getPositionalArguments().get(0))));
            } else if (a.getName().equals("license")) {
                res.add(make().Assign(naming.makeUnquotedIdent("license"), make().Literal(a.getPositionalArguments().get(0))));
            } else if (a.getName().equals("by")) {
                for (String author : a.getPositionalArguments()) {
                    authors.add(make().Literal(author));
                }
            }
        }
    }
    if (!authors.isEmpty()) {
        res.add(make().Assign(naming.makeUnquotedIdent("by"), make().NewArray(null, null, authors.toList())));
    }
    return res;
}
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)

Example 7 with Annotation

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

the class Util method getTags.

public static <T extends Referenceable & Annotated> List<String> getTags(T decl) {
    List<String> tags = new ArrayList<String>();
    Annotation tagged = Util.getAnnotation(decl.getUnit(), decl.getAnnotations(), "tagged");
    if (tagged != null) {
        tags.addAll(tagged.getPositionalArguments());
    }
    return tags;
}
Also used : ArrayList(java.util.ArrayList) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation)

Example 8 with Annotation

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

the class ModuleDoc method writeLicense.

private void writeLicense(Module module) throws IOException {
    Annotation annotation = Util.getAnnotation(module.getUnit(), module.getAnnotations(), "license");
    if (annotation == null)
        return;
    String license = annotation.getPositionalArguments().get(0);
    if (license == null || license.isEmpty())
        return;
    open("div class='license section'");
    around("span class='title'", "License: ");
    around("span class='value'", license);
    close("div");
}
Also used : Annotation(com.redhat.ceylon.model.typechecker.model.Annotation)

Example 9 with Annotation

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

the class CeylonDoc method writeBy.

protected final void writeBy(Object obj) throws IOException {
    List<Annotation> annotations;
    if (obj instanceof Declaration) {
        annotations = ((Declaration) obj).getAnnotations();
    } else if (obj instanceof Module) {
        annotations = ((Module) obj).getAnnotations();
    } else if (obj instanceof Package) {
        annotations = ((Package) obj).getAnnotations();
    } else {
        throw new IllegalArgumentException();
    }
    List<String> authors = new ArrayList<>();
    for (Annotation annotation : annotations) {
        if (annotation.getName().equals("by")) {
            for (String author : annotation.getPositionalArguments()) {
                authors.add(author);
            }
        }
    }
    if (!authors.isEmpty()) {
        open("div class='by section'");
        around("span class='title'", "By: ");
        around("span class='value'", Util.join(", ", authors));
        close("div");
    }
}
Also used : ArrayList(java.util.ArrayList) 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) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation)

Example 10 with Annotation

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

the class CeylonDocTool method warningMissingThrows.

protected void warningMissingThrows(Declaration d) {
    if (ignoreMissingThrows) {
        return;
    }
    final Scope scope = d.getScope();
    final PhasedUnit unit = getUnit(d);
    final Node node = getNode(d);
    if (scope == null || unit == null || unit.getUnit() == null || node == null || !(d instanceof FunctionOrValue)) {
        return;
    }
    List<Type> documentedExceptions = new ArrayList<Type>();
    for (Annotation annotation : d.getAnnotations()) {
        if (annotation.getName().equals("throws")) {
            String exceptionName = annotation.getPositionalArguments().get(0);
            Declaration exceptionDecl = scope.getMemberOrParameter(unit.getUnit(), exceptionName, null, false);
            if (exceptionDecl instanceof TypeDeclaration) {
                documentedExceptions.add(((TypeDeclaration) exceptionDecl).getType());
            }
        }
    }
    final List<Type> thrownExceptions = new ArrayList<Type>();
    node.visitChildren(new Visitor() {

        @Override
        public void visit(Tree.Throw that) {
            Expression expression = that.getExpression();
            if (expression != null) {
                thrownExceptions.add(expression.getTypeModel());
            } else {
                thrownExceptions.add(unit.getUnit().getExceptionType());
            }
        }

        @Override
        public void visit(Tree.Declaration that) {
        // the end of searching
        }
    });
    for (Type thrownException : thrownExceptions) {
        boolean isDocumented = false;
        for (Type documentedException : documentedExceptions) {
            if (thrownException.isSubtypeOf(documentedException)) {
                isDocumented = true;
                break;
            }
        }
        if (!isDocumented) {
            log.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
        }
    }
}
Also used : Visitor(com.redhat.ceylon.compiler.typechecker.tree.Visitor) SourceDeclarationVisitor(com.redhat.ceylon.compiler.java.loader.SourceDeclarationVisitor) Node(com.redhat.ceylon.compiler.typechecker.tree.Node) ArrayList(java.util.ArrayList) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) NothingType(com.redhat.ceylon.model.typechecker.model.NothingType) Type(com.redhat.ceylon.model.typechecker.model.Type) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Expression(com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

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