Bug 27204

Summary: AST.lineNumber(position) is not working, if the class didn't have a new line at the end of file.
Product: [Eclipse Project] JDT Reporter: Kelvin <kelvin>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED WORKSFORME QA Contact:
Severity: major    
Priority: P3 CC: Olivier_Thomann
Version: 2.1   
Target Milestone: 2.1 M4   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Kelvin CLA 2002-11-26 18:48:17 EST
I am trying to use AST.lineNumber() to return the line number. However, when 
the class didn't have a newline at the end of file, the AST parser seems not 
working and lineNumber() always return 1. 

ie.
public class NO_WORKING {

    public void method() { }
}  <--- no new line, "}" is the last character
--------------------------

public class WORKING {
    
    public void method() { }
}
 <--- new line here
------------------------------
Comment 1 Olivier Thomann CLA 2002-11-27 10:33:29 EST
I could not reproduce with latest. Could you please let me know what code you
used and which build?

I tried the following code:

assertTrue("not a compilation unit", result.getNodeType() ==
ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
CompilationUnit compilationUnit = (CompilationUnit) result;
ASTNode node = getASTNode(compilationUnit, 0, 0);
assertNotNull("No node", node);
assertTrue("not a method declaration", node.getNodeType() ==
ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
MethodDeclaration methodDeclaration = (MethodDeclaration) node;
SimpleName name = methodDeclaration.getName();
assertEquals("wrong line number", 3,
compilationUnit.lineNumber(name.getStartPosition()));

with your first test case (the one without any line break at the end). I got the
proper answer. I tried with the binding resolution, it worked as well.

I need more information in order to reproduce. Do you have any errors in your code?
Comment 2 Olivier Thomann CLA 2002-11-27 12:52:39 EST
Add CC.
Comment 3 Olivier Thomann CLA 2002-11-28 09:00:49 EST
Without further information, I will close it as WORKSFORME.
Comment 4 Olivier Thomann CLA 2002-12-02 08:44:07 EST
Close as WORKSFORME. Please reopen if you have more information or better steps
to reproduce.