Search in sources :

Example 11 with JCAnnotation

use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project com.revolsys.open by revolsys.

the class DocumentationProcessor method process.

@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
    if (this.elementUtils != null) {
        final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Documentation.class);
        for (final Element element : elements) {
            String docComment = this.elementUtils.getDocComment(element);
            if (docComment != null) {
                docComment = docComment.trim();
                if (docComment.length() > 0) {
                    final JCModifiers modifiers = getModifiers(element);
                    for (final JCAnnotation annotation : modifiers.annotations) {
                        if (annotation.type.toString().equals(Documentation.class.getName())) {
                            boolean hasValue = false;
                            final JCLiteral commentLiteral = this.maker.Literal(docComment);
                            for (final JCExpression arg : annotation.args) {
                                if (arg instanceof JCAssign) {
                                    final JCAssign assign = (JCAssign) arg;
                                    final JCExpression lhs = assign.lhs;
                                    if (lhs instanceof JCIdent) {
                                        final JCIdent ident = (JCIdent) lhs;
                                        if (ident.name.contentEquals("value")) {
                                            assign.rhs = commentLiteral;
                                            hasValue = true;
                                        }
                                    }
                                }
                            }
                            if (!hasValue) {
                                final ClassSymbol classSymbol = (ClassSymbol) ((JCIdent) annotation.annotationType).sym;
                                MethodSymbol valueMethod = null;
                                for (final Symbol symbol : classSymbol.members_field.getElementsByName(this.names.value)) {
                                    valueMethod = (MethodSymbol) symbol;
                                }
                                final JCAssign valueArg = this.maker.Assign(this.maker.Ident(valueMethod), commentLiteral);
                                annotation.args = annotation.args.append(valueArg);
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : JCIdent(com.sun.tools.javac.tree.JCTree.JCIdent) JCAssign(com.sun.tools.javac.tree.JCTree.JCAssign) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) Symbol(com.sun.tools.javac.code.Symbol) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) Documentation(com.revolsys.open.compiler.annotation.Documentation) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) JCModifiers(com.sun.tools.javac.tree.JCTree.JCModifiers) JCLiteral(com.sun.tools.javac.tree.JCTree.JCLiteral) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 12 with JCAnnotation

use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.

the class ExpressionTransformer method transformAnonymousAnnotation.

public void transformAnonymousAnnotation(Tree.AnonymousAnnotation annotation, Map<Class, ListBuffer<JCAnnotation>> annos) {
    Type docType = ((TypeDeclaration) typeFact().getLanguageModuleDeclaration("DocAnnotation")).getType();
    JCAnnotation docAnnotation = at(annotation).Annotation(makeJavaType(docType, JT_ANNOTATION), List.<JCExpression>of(make().Assign(naming.makeUnquotedIdent("description"), transform(annotation.getStringLiteral()))));
    putAnnotation(annos, docAnnotation, (Class) docType.getDeclaration());
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 13 with JCAnnotation

use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.

the class ParameterDefinitionBuilder method build.

public JCVariableDecl build() {
    if (built) {
        throw new BugException("already built");
    }
    built = true;
    ListBuffer<JCAnnotation> annots = ListBuffer.lb();
    if (Annotations.includeModel(annotationFlags)) {
        annots.appendList(gen.makeAtName(name));
        if (functionalParameterName != null) {
            annots.appendList(gen.makeAtFunctionalParameter(functionalParameterName));
        }
        if (sequenced) {
            annots.appendList(gen.makeAtSequenced());
        }
        if (defaulted) {
            annots.appendList(gen.makeAtDefaulted());
        }
        if (typeAnnos != null) {
            annots.appendList(typeAnnos);
        }
    }
    if (Annotations.includeUser(annotationFlags) && userAnnotations != null) {
        annots.appendList(userAnnotations.toList());
    }
    if (Annotations.includeModel(annotationFlags)) {
        if (modelAnnotations != null) {
            annots.appendList(modelAnnotations.toList());
        }
    }
    if (Annotations.includeIgnore(annotationFlags)) {
        annots = annots.appendList(gen.makeAtIgnore());
    }
    Name name = gen.names().fromString(Naming.quoteParameterName(getJavaParameterName()));
    return gen.make().VarDef(gen.make().Modifiers(modifiers | Flags.PARAMETER, annots.toList()), name, type, null);
}
Also used : JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) Name(com.sun.tools.javac.util.Name)

Example 14 with JCAnnotation

use of com.sun.tools.javac.tree.JCTree.JCAnnotation 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)

Example 15 with JCAnnotation

use of com.sun.tools.javac.tree.JCTree.JCAnnotation in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeReifiedTypeParameterVarDecl.

JCVariableDecl makeReifiedTypeParameterVarDecl(TypeParameter param, boolean isCompanion) {
    String descriptorName = naming.getTypeArgumentDescriptorName(param);
    long flags = PRIVATE;
    if (!isCompanion)
        flags |= FINAL;
    List<JCAnnotation> annotations = makeAtIgnore();
    JCVariableDecl localVar = make().VarDef(make().Modifiers(flags, annotations), names().fromString(descriptorName), makeTypeDescriptorType(), null);
    return localVar;
}
Also used : JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl)

Aggregations

JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)53 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)32 ListBuffer (com.sun.tools.javac.util.ListBuffer)17 Name (com.sun.tools.javac.util.Name)16 JCTree (com.sun.tools.javac.tree.JCTree)15 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)15 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)13 JavacNode (lombok.javac.JavacNode)13 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)12 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)11 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)10 JCAssign (com.sun.tools.javac.tree.JCTree.JCAssign)8 JavacTreeMaker (lombok.javac.JavacTreeMaker)8 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)6 Type (com.redhat.ceylon.model.typechecker.model.Type)5 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)5 JCNewArray (com.sun.tools.javac.tree.JCTree.JCNewArray)5 ArrayList (java.util.ArrayList)5 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)4 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)4