Bug 100041 - [javadoc][dom] Wrong positions when javadoc comment inside method declaration
Summary: [javadoc][dom] Wrong positions when javadoc comment inside method declaration
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-14 14:25 EDT by Olivier Thomann CLA
Modified: 2005-09-26 10:06 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix (4.50 KB, patch)
2005-06-14 14:52 EDT, Olivier Thomann CLA
no flags Details | Diff
Corresponding regression test (3.30 KB, patch)
2005-06-14 14:52 EDT, Olivier Thomann CLA
no flags Details | Diff
Simpler patch to fix this issue (972 bytes, patch)
2005-08-03 08:49 EDT, Frederic Fusier CLA
no flags Details | Diff
New test cases added to ASTConverterJavadocTest (6.23 KB, patch)
2005-08-03 08:51 EDT, Frederic Fusier CLA
no flags Details | Diff
Bundle all test cases in one patch (12.27 KB, patch)
2005-08-03 08:55 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2005-06-14 14:25:43 EDT
Using RC2, the positions for the local variable are wrong. They include the
javadoc positions. They should start on the final keyword.

public class Y {
	public static void foo(Object object) {
		/**
		 * javadoc comment.
		 */
		if (object instanceof ClassLoader) {
			final String s = null;
		}
	}
}
Comment 1 Olivier Thomann CLA 2005-06-14 14:42:13 EDT
The problem comes from the fact that we consider javadoc inside method bodies.
This has a side-effect on the local variable declaration because this is
changing the modifierSourceStart. So any local that has a modifier (likely
final) can potentially have bad positions if a javadoc comment is within the
same method.
Comment 2 Olivier Thomann CLA 2005-06-14 14:52:12 EDT
Created attachment 23090 [details]
Proposed fix

The only side-effect of this fix is that local classes within a method don't
include the preceeding javadoc if any.
They are considered as a statement (indeed they are a type declaration
statement). Method declarations inside these local classes keep their javadoc
if any.

I don't break any existing JDT/Core DOM/AST tests with this patch. It would
need to be reviewed.
Comment 3 Olivier Thomann CLA 2005-06-14 14:52:30 EDT
Created attachment 23091 [details]
Corresponding regression test
Comment 4 Olivier Thomann CLA 2005-06-14 15:22:27 EDT
Another side effect of the current bug is that the local declaration has no
modidier in the DOM/AST tree.
Comment 5 Olivier Thomann CLA 2005-06-14 20:37:20 EDT
Fix is not good enough. Needs more investigation.
Comment 6 Olivier Thomann CLA 2005-06-15 10:38:27 EDT
This is a regression compare to 3.0.2. The positions looks good in 3.0.2.
Comment 7 Olivier Thomann CLA 2005-06-15 11:36:48 EDT
Too risky for 3.1.
Will be considered post 3.1.
Comment 8 Olivier Thomann CLA 2005-06-27 17:57:15 EDT
Tagged as 3.1.1 since this is a regression compare to 3.0.2
Comment 9 Frederic Fusier CLA 2005-08-03 08:49:29 EDT
Created attachment 25611 [details]
Simpler patch to fix this issue

This fix has the advantage to be minimalistic and seems to have no side effect
(ie. javadoc comments for local class and their body declarations are kept).
Comment 10 Frederic Fusier CLA 2005-08-03 08:51:39 EDT
Created attachment 25612 [details]
New test cases added to ASTConverterJavadocTest

These new test cases complete previous regression test, especially to verify
that javadoc comments are kept inside method.
Comment 11 Frederic Fusier CLA 2005-08-03 08:55:54 EDT
Created attachment 25613 [details]
Bundle all test cases in one patch

Note that previous patch was not complete...
I forgot to put last changes for testBug100041c.
Comment 12 Frederic Fusier CLA 2005-08-03 10:07:13 EDT
All JDT/Core and JDT/UI tests pass with this fix.

Patches released in R3_1_maintenance branch.
Comment 13 Frederic Fusier CLA 2005-08-03 12:21:50 EDT
Backported in HEAD stream.
Comment 14 Olivier Thomann CLA 2005-08-09 10:17:12 EDT
Verified in 3.2M1 (I20050808-2000)
Comment 15 Maxime Daniel CLA 2005-09-26 10:03:45 EDT
Verified for 3.1.1 using build M20050923-1430.
Comment 16 Olivier Thomann CLA 2005-09-26 10:06:13 EDT
Verified.