You can get the ASTNode line number using the code below
int lineNumber = compilationUnit.getLineNumber(node.getStartPosition()) - 1;
the compilation unit can be obtained using the code below
ASTParser parser = ASTParser.newParser(AST.JLS3);
You can visit the node (e.g. MethodDeclaration node) using the code below:
compilationUnit.accept(new ASTVisitor() { public boolean visit(MethodDeclaration node) { int lineNumber = compilationUnit.getLineNumber(node.getStartPosition()) - 1; return true; } });
source share