Bug 117032 - AST line numbers: Problems with single line source
Summary: AST line numbers: Problems with single line source
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-18 08:20 EST by Martin Aeschlimann CLA
Modified: 2005-12-12 11:39 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2005-11-18 08:20:08 EST
20051118

An AST dos not get line numbers when the source only has one line.

In the example: The second fails (-2 is returned)

public void test1() throws Exception {
	{
		String s= "package pack1;\npublic class C {}"; 
		ASTParser parser= ASTParser.newParser(AST.JLS3);
		parser.setSource(s.toCharArray());
		CompilationUnit node= (CompilationUnit) parser.createAST(null);
		int lineNumber= node.getLineNumber(0);
		assertEquals(1, lineNumber);
	}
	
	{
		String s= "package pack1;public class C {}"; 
		ASTParser parser= ASTParser.newParser(AST.JLS3);
		parser.setSource(s.toCharArray());
		CompilationUnit node= (CompilationUnit) parser.createAST(null);
		int lineNumber= node.getLineNumber(0);
		assertEquals(1, lineNumber);
	}

}
Comment 1 Olivier Thomann CLA 2005-11-18 08:56:28 EST
I'll fix it.
Comment 2 Olivier Thomann CLA 2005-11-18 09:18:29 EST
Fixed and released in HEAD.
Regression tests added in
org.eclipse.jdt.core.tests.dom.ASTPositionsTest.test004/005
Comment 3 Frederic Fusier CLA 2005-12-12 11:39:32 EST
Verified for 3.2 M4 using build I20051212-0010