Bug 27204 - AST.lineNumber(position) is not working, if the class didn't have a new line at the end of file.
Summary: AST.lineNumber(position) is not working, if the class didn't have a new line ...
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: 2.1 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-26 18:48 EST by Kelvin CLA
Modified: 2002-12-02 08:44 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.