@Requires({
    "processingEnv != null",
    "element != null",
    "annotation != null"
  })
  @Ensures("result != null")
  public static List<Long> getLineNumbers(ProcessingEnvironment processingEnv,
      Element element, AnnotationMirror annotation) {
    Trees treeUtils = Trees.instance(processingEnv);
    if (treeUtils == null) {
      return Collections.emptyList();
    }

    TreePath path = treeUtils.getPath(element, annotation);
    if (path == null) {
      return Collections.emptyList();
    }

    CompilationUnitTree unitTree = path.getCompilationUnit();
    LineMap lineMap = unitTree.getLineMap();
    SourcePositions positions = treeUtils.getSourcePositions();

    AnnotationTree annotationTree = (AnnotationTree) path.getLeaf();
    AssignmentTree assignTree =
        (AssignmentTree) annotationTree.getArguments().get(0);
    ExpressionTree exprTree = assignTree.getExpression();

    ArrayList<Long> lines = new ArrayList<Long>();
    if (exprTree.getKind() == Kind.STRING_LITERAL) {
      long pos = positions.getStartPosition(unitTree, exprTree);
      lines.add(lineMap.getLineNumber(pos));
    } else {
      NewArrayTree valuesTree = (NewArrayTree) exprTree;
      for (ExpressionTree valueTree : valuesTree.getInitializers()) {
        long pos = positions.getStartPosition(unitTree, valueTree);
        lines.add(lineMap.getLineNumber(pos));
      }
    }

    return lines;
  }
@ Requires ( { "processingEnv != null" , "element != null" , "annotation != null" } ) @ Ensures ( "result != null" ) public static List < Long > getLineNumbers ( ProcessingEnvironment processingEnv , Element element , AnnotationMirror annotation ) { Trees treeUtils = Trees . instance ( processingEnv ) ; if ( treeUtils == null ) { return Collections . emptyList ( ) ; } TreePath path = treeUtils . getPath ( element , annotation ) ; if ( path == null ) { return Collections . emptyList ( ) ; } CompilationUnitTree unitTree = path . getCompilationUnit ( ) ; LineMap lineMap = unitTree . getLineMap ( ) ; SourcePositions positions = treeUtils . getSourcePositions ( ) ; AnnotationTree annotationTree = ( AnnotationTree ) path . getLeaf ( ) ; AssignmentTree assignTree = ( AssignmentTree ) annotationTree . getArguments ( ) . get ( 0 ) ; ExpressionTree exprTree = assignTree . getExpression ( ) ; ArrayList < Long > lines = new ArrayList < Long > ( ) ; if ( exprTree . getKind ( ) == Kind . STRING_LITERAL ) { long pos = positions . getStartPosition ( unitTree , exprTree ) ; lines . add ( lineMap . getLineNumber ( pos ) ) ; } else { NewArrayTree valuesTree = ( NewArrayTree ) exprTree ; for ( ExpressionTree valueTree : valuesTree . getInitializers ( ) ) { long pos = positions . getStartPosition ( unitTree , valueTree ) ; lines . add ( lineMap . getLineNumber ( pos ) ) ; } } return lines ; }
Returns the line numbers associated with {@code annotation}.