Search in sources :

Example 1 with Annotation

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

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("label")) {
                res.add(make().Assign(naming.makeUnquotedIdent("label"), 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(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) LanguageAnnotation(org.eclipse.ceylon.model.loader.LanguageAnnotation)

Example 2 with Annotation

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

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(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) LanguageAnnotation(org.eclipse.ceylon.model.loader.LanguageAnnotation) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)

Example 3 with Annotation

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

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(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Class(org.eclipse.ceylon.model.typechecker.model.Class) 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) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType)

Example 4 with Annotation

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

the class CeylonDoc method writeSince.

protected final <T extends Annotated & Referenceable> void writeSince(T decl) throws IOException {
    Annotation see = Util.getAnnotation(decl.getUnit(), decl.getAnnotations(), "since");
    if (see == null)
        return;
    open("div class='since section'");
    around("span class='title'", "Since ");
    open("span class='value'");
    boolean first = true;
    for (String version : see.getPositionalArguments()) {
        if (!first) {
            write(", ");
        } else {
            first = false;
        }
        write(version);
    }
    close("span");
    close("div");
}
Also used : Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 5 with Annotation

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

the class CeylonDocTool method docNothingType.

private void docNothingType(Package pkg) throws IOException {
    final Annotation nothingDoc = new Annotation();
    nothingDoc.setName("doc");
    nothingDoc.addPositionalArgument("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(org.eclipse.ceylon.model.typechecker.model.Annotation) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType)

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