Search in sources :

Example 26 with Annotation

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

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(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 27 with Annotation

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

the class CeylonDoc method writeSee.

protected final <T extends Annotated & Referenceable> void writeSee(T decl) throws IOException {
    Annotation see = Util.getAnnotation(decl.getUnit(), decl.getAnnotations(), "see");
    if (see == null)
        return;
    open("div class='see section'");
    around("span class='title'", "See also ");
    open("span class='value'");
    boolean first = true;
    for (String target : see.getPositionalArguments()) {
        if (!first) {
            write(", ");
        } else {
            first = false;
        }
        // TODO: add 'identifier' or 'type-identitier' CSS class
        linkRenderer().to(target).withinText(true).useScope(decl).printAbbreviated(false).printTypeParameters(false).write();
    }
    close("span");
    close("div");
}
Also used : Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 28 with Annotation

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

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(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 29 with Annotation

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

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) {
            richLog.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
        }
    }
}
Also used : Visitor(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) AssertionVisitor(org.eclipse.ceylon.compiler.typechecker.util.AssertionVisitor) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) ArrayList(java.util.ArrayList) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Expression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 30 with Annotation

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

the class DocVisitor method retrieveDocs.

private boolean retrieveDocs(List<Annotation> annotations, String location) {
    boolean rval = false;
    for (Annotation ann : annotations) {
        if ("doc".equals(ann.getName()) && !ann.getPositionalArguments().isEmpty()) {
            String doc = ann.getPositionalArguments().get(0);
            if (doc.charAt(0) == '"' && doc.charAt(doc.length() - 1) == '"') {
                doc = doc.substring(1, doc.length() - 1);
            }
            int idx = docs.indexOf(doc);
            if (idx < 0) {
                idx = docs.size();
                docs.add(doc);
            }
            locs.put(location, idx);
            rval = true;
        }
    }
    return rval;
}
Also used : Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

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