Exemple #1
0
  public static Annotation copyAnnotation(Annotation annotation, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;

    if (annotation instanceof MarkerAnnotation) {
      MarkerAnnotation ann = new MarkerAnnotation(copyType(annotation.type, source), pS);
      setGeneratedBy(ann, source);
      ann.declarationSourceEnd = ann.sourceEnd = ann.statementEnd = pE;
      return ann;
    }

    if (annotation instanceof SingleMemberAnnotation) {
      SingleMemberAnnotation ann =
          new SingleMemberAnnotation(copyType(annotation.type, source), pS);
      setGeneratedBy(ann, source);
      ann.declarationSourceEnd = ann.sourceEnd = ann.statementEnd = pE;
      // TODO memberValue(s) need to be copied as well (same for copying a NormalAnnotation as
      // below).
      ann.memberValue = ((SingleMemberAnnotation) annotation).memberValue;
      return ann;
    }

    if (annotation instanceof NormalAnnotation) {
      NormalAnnotation ann = new NormalAnnotation(copyType(annotation.type, source), pS);
      setGeneratedBy(ann, source);
      ann.declarationSourceEnd = ann.statementEnd = ann.sourceEnd = pE;
      ann.memberValuePairs = ((NormalAnnotation) annotation).memberValuePairs;
      return ann;
    }

    return annotation;
  }