private ModifiersTree addAnnotation( String annotationFqn , TreeMaker maker,ModifiersTree modifiers ) { AnnotationTree newAnnotation = maker.Annotation( maker.QualIdent(annotationFqn) , Collections.<ExpressionTree>emptyList()); if (modifiers != null) { modifiers = maker.addModifiersAnnotation(modifiers, newAnnotation); } return modifiers; }
newModifiersTree = make.addModifiersAnnotation(newModifiersTree, newTree); wc.rewrite(modifiers, newModifiersTree);
return make.addModifiersAnnotation((ModifiersTree) modifiers, newAnnotation); } else if (modifiers.getKind() == Kind.COMPILATION_UNIT) { return make.addPackageAnnotation((CompilationUnitTree) modifiers, newAnnotation);
/** * Adds an annotation to a variable. This is equivalent to {@link TreeMaker#addModifiersAnnotation}, * but it creates and returns a new <code>VariableTree, not a new <code>ModifiersTree</code>. * * @param variableTree the variable to add the annotation to; cannot be null. * @param annotationTree the annotation to add; cannot be null. * @return a new variable annotated with the new annotation; never null. */ public VariableTree addAnnotation(VariableTree variableTree, AnnotationTree annotationTree) { Parameters.notNull("variableTree", variableTree); // NOI18N Parameters.notNull("annotationTree", annotationTree); // NOI18N TreeMaker make = getTreeMaker(); return make.Variable( make.addModifiersAnnotation(variableTree.getModifiers(), annotationTree), variableTree.getName(), variableTree.getType(), variableTree.getInitializer()); }
/** * Adds an annotation to a class. This is equivalent to {@link TreeMaker#addModifiersAnnotation}, * but it creates and returns a new <code>ClassTree, not a new <code>ModifiersTree</code>. * * @param classTree the class to add the annotation to; cannot be null. * @param annotationTree the annotation to add; cannot be null. * @return a new class annotated with the new annotation; never null. */ @SuppressWarnings("unchecked") // NOI18N public ClassTree addAnnotation(ClassTree classTree, AnnotationTree annotationTree) { Parameters.notNull("classTree", classTree); // NOI18N Parameters.notNull("annotationTree", annotationTree); // NOI18N TreeMaker make = getTreeMaker(); return make.Class( make.addModifiersAnnotation(classTree.getModifiers(), annotationTree), classTree.getSimpleName(), classTree.getTypeParameters(), classTree.getExtendsClause(), (List<ExpressionTree>)classTree.getImplementsClause(), classTree.getMembers()); }
mt = make.addModifiersAnnotation(prototype.getModifiers(), make.Annotation(make.Identifier("Override"), Collections.<ExpressionTree>emptyList()));
/** * Adds an annotation to a method. This is equivalent to {@link TreeMaker#addModifiersAnnotation}, * but it creates and returns a new <code>MethodTree, not a new <code>ModifiersTree</code>. * * @param methodTree the method to add the annotation to; cannot be null. * @param annotationTree the annotation to add; cannot be null. * @return a new method annotated with the new annotation; never null. */ public MethodTree addAnnotation(MethodTree methodTree, AnnotationTree annotationTree) { Parameters.notNull("methodTree", methodTree); // NOI18N Parameters.notNull("annotationTree", annotationTree); // NOI18N TreeMaker make = getTreeMaker(); return make.Method( make.addModifiersAnnotation(methodTree.getModifiers(), annotationTree), methodTree.getName(), methodTree.getReturnType(), methodTree.getTypeParameters(), methodTree.getParameters(), methodTree.getThrows(), methodTree.getBody(), (ExpressionTree)methodTree.getDefaultValue()); }