2

I'm trying to extract the number of lines from my source code in Eclipse with the jdt package.

I found a similar question here : https://stackoverflow.com/questions/11126857/eclipse-astnode-to-source-code-line-number/11131452#11131452 Unni Kris answer wasn't a working solution.

I have a class that extract compilationUnits, with a parser it create an AST. I then proceed to attach a visitor to the ASTNode.

In my visitor class I tried the following:

public boolean visit(CompilationUnit node) {
    int lineNumber = node.getLineNumber(node.getStartPosition()) ;
    System.out.println("Nombre de Ligne : " + lineNumber);
    return super.visit(node);
}

which gave me "1" number of line. The workspace I'm trying to extract metrics from have at least a dozen lines for each class.

Thank you.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Tristan
  • 1,349
  • 2
  • 16
  • 25
  • Found the solution at https://stackoverflow.com/questions/14371526/getting-startposition-and-length-of-a-method-invocation-using-jdt However, compilationUnit.getLineNumber() return me -1 for some classes that I'm testing with. I do not understand the behavior. – Tristan Feb 05 '14 at 05:48

0 Answers0