Search in sources :

Example 16 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project activityinfo by bedatadriven.

the class DefaultUpdatingVisitor method updateDefaultStringAnnotation.

private void updateDefaultStringAnnotation(MethodDeclaration decl, String translated) {
    for (AnnotationExpr annotation : decl.getAnnotations()) {
        if (annotation.getName().getName().equals(defaultAnnotationName)) {
            updateAnnotationValue(annotation, translated);
            return;
        }
    }
    // If there is no annotation, add one
    SingleMemberAnnotationExpr defaultExpr = new SingleMemberAnnotationExpr(new NameExpr(defaultAnnotationName), new StringLiteralExpr(translated));
    decl.getAnnotations().add(defaultExpr);
}
Also used : SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr)

Example 17 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project activityinfo by bedatadriven.

the class InspectingVisitor method visit.

@Override
public void visit(MethodDeclaration n, Void arg) {
    ResourceClassTerm term = new ResourceClassTerm(AstEvaluator.parseTermKey(n));
    for (AnnotationExpr annotation : n.getAnnotations()) {
        if (annotation.getName().getName().equals(defaultValueAnnotation)) {
            term.setDefaultTranslation(AstEvaluator.parseAnnotationValue(annotation));
        } else if (annotation.getName().getName().equals("Meaning")) {
            term.setMeaning(AstEvaluator.parseAnnotationValue(annotation));
        }
    }
    if (termMap.containsKey(term.getKey())) {
        throw new RuntimeException("Duplicate key: " + term.getKey());
    }
    termMap.put(term.getKey(), term);
}
Also used : ResourceClassTerm(org.activityinfo.i18n.tools.model.ResourceClassTerm) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr)

Example 18 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project javaparser by javaparser.

the class CloneVisitor method visit.

@Override
public Node visit(UnionType _n, Object _arg) {
    List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
    List<ReferenceType> elements = visit(_n.getElements(), _arg);
    UnionType r = new UnionType(_n.getRange(), elements);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    r.setComment(comment);
    r.setAnnotations(annotations);
    return r;
}
Also used : Comment(com.github.javaparser.ast.comments.Comment) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) NormalAnnotationExpr(com.github.javaparser.ast.expr.NormalAnnotationExpr)

Example 19 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project javaparser by javaparser.

the class JavaParser method parseAnnotation.

/**
 * Parses the Java annotation contained in a {@link String} and returns a
 * {@link AnnotationExpr} that represents it.
 *
 * @param annotation
 *            {@link String} containing Java annotation
 * @return AnnotationExpr representing the Java annotation
 * @throws ParseException
 *             if the source code has parser errors
 */
public static AnnotationExpr parseAnnotation(final String annotation) {
    StringReader sr = new StringReader(annotation);
    AnnotationExpr ae = new ASTParser(sr).Annotation();
    sr.close();
    return ae;
}
Also used : AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) StringReader(java.io.StringReader) ASTParser(com.github.javaparser.ASTParser)

Aggregations

AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)19 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)11 MarkerAnnotationExpr (com.github.javaparser.ast.expr.MarkerAnnotationExpr)9 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)9 Comment (com.github.javaparser.ast.comments.Comment)5 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)5 Annotation (scenelib.annotations.Annotation)5 BlockComment (com.github.javaparser.ast.comments.BlockComment)4 LineComment (com.github.javaparser.ast.comments.LineComment)4 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)4 WildcardType (com.github.javaparser.ast.type.WildcardType)4 ReferenceType (com.github.javaparser.ast.type.ReferenceType)3 Type (com.github.javaparser.ast.type.Type)3 AField (scenelib.annotations.el.AField)3 AMethod (scenelib.annotations.el.AMethod)3 Parameter (com.github.javaparser.ast.body.Parameter)2 ReceiverParameter (com.github.javaparser.ast.body.ReceiverParameter)2 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)2 ArrayType (com.github.javaparser.ast.type.ArrayType)2