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);
}
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);
}
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;
}
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;
}
Aggregations