Bug 54204 - [Comments] Java Model and DOM AST differ in element source range when multiple comment blocks present
Summary: [Comments] Java Model and DOM AST differ in element source range when multipl...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 56532 349959 (view as bug list)
Depends on:
Blocks: 46171 66463
  Show dependency tree
 
Reported: 2004-03-09 16:07 EST by Srimanth CLA
Modified: 2020-02-17 17:17 EST (History)
9 users (show)

See Also:


Attachments
New heuristic proposal (100.44 KB, text/html)
2004-04-14 13:48 EDT, Frederic Fusier CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Srimanth CLA 2004-03-09 16:07:34 EST
I dont know if this is a defect or an intentional feature, but if you have a
method with two javadoc comment blocks on top of it, IMethod gives the
offset/length including both the comment blocks, whereas AST (MethodDeclaration)
takes only the lowest comment block into consideration. An example could be:

public class SomeClass{
  /**
   * Comment block 1
   */
  /**
   * Comment block 2
   */
  public void foo(){
  }
}

Is it possible to get a consistent source range from both AST and JDT?
Comment 1 Philipe Mulet CLA 2004-03-10 05:03:08 EST
We have been aware of this issue for a long time, but haven't been able to 
change it so as not to break existing clients who did make assumptions on these.
The DOM AST source range should include all leading comments...

Jim: could we address this somehow in the new API ? We could say that when 
using the 3.0 level AST, these positions are now correctly reflecting what they 
should have been since day one ?
Comment 2 Gili Mendel CLA 2004-03-10 07:31:11 EST
When you have one watch, you can tell what the time is.  When you have two
watches, you will never be sure ;-)
Comment 3 Jim des Rivieres CLA 2004-03-10 08:52:01 EST
The new methods Frederic added, CompilationUnit.getExtendedStartPosition
(ASTNode) and getExtendedLength(ASTNode), should include all leading (and 
trailing) comments.
Comment 4 Philipe Mulet CLA 2004-03-25 06:53:11 EST
Frederic - pls verify it now works.
Comment 5 Frederic Fusier CLA 2004-04-14 06:04:24 EDT
I've verified with build I20040407 that CompilationUnit.getExtendedStartPosition
(ASTNode) and getExtendedLength(ASTNode) work correctly for provided example
=> both javadoc comments are including in leading comments :)
Comment 6 Frederic Fusier CLA 2004-04-14 07:19:06 EDT
Reopen as there are differences.

In following example:
public class SomeClass{
  /**
   * Comment block 1
   */

  /**
   * Comment block 2
   */
  public void foo(){
  }
}
which looks really similar than initial one, JDT put both comments as leading 
ones and AST extended range put only second one. They are many other examples 
which can show different leading/trailing comments...

We agree that JDT and AST should behave the same way. I will think about a 
common behavior and propose it in next comment...
Comment 7 Frederic Fusier CLA 2004-04-14 13:48:13 EDT
Created attachment 9496 [details]
New heuristic proposal

This document explain existing JDT and AST currently implemented heuristics and
propose a new common one.
It also provide examples to try to show old and new expected behaviors.
Feedbacks will be greatly appreciated, thx
Comment 8 Frederic Fusier CLA 2004-04-14 13:54:42 EDT
I've written attached document using word and save it under HTML format. I've 
verified that I can read it using IE6.1 but I know that HTML generated by 
Microsoft is often non-standard. So let me know if you get some troubles to 
read it...
Comment 9 Frederic Fusier CLA 2004-04-15 11:11:21 EDT
AST heuristic came from JDT-UI who definitely wants it unchanged.
Initial reason for this behavior is that detached comments are often not really 
meaningful for following node.

Here's a simple example which shows that:
public class Test {
	
  //***** Start of methods *****
	
  /* Method foo */
  public void foo(){
  }
  // End of foo
  	
  /* Method bar */
  public void bar(){}
  // End of bar
	
  //***** End of methods *****
}

In this case '//***** Start of methods' comment is obviously not really 
attached to foo method declaration. That's why "condition 4" was added to 
heuristic to stop comments search when an empty line was encountered.

However, we also definitely need to have similar extended source range for both 
Java and AST models...

So, if AST heuristic cannot be changed for the while (also due to big impacts 
on JDT-UI code and tests), the only solution we have is to modify JDT heuristic 
to behaves like AST one.

Also note that problem I mentionned in document about AST heuristic comes from 
personal and user feedback (bug 46171). As this behavior may be natural for 
other users (like JDT-UI ones), we'll keep bug 46171 as enhancement to provide 
user interface to modify this heuristic (surely not targeted for 3.0)...
Comment 10 Sten-Erik Bergner CLA 2004-04-18 04:11:13 EDT
Fine actually. Although impressed the "New heuristic proposal" I did not agree 
with it:
(1) For the reason examplified in comment #8.
(2) Because I believe that the focus on relating as many comments as posssible 
(in the proposal actual ALL comments) to one node or another is 
counterproductive from the JDT user's point of view. At all times, even when 
using refactoring commands or drag&droping program elements, when I edit my 
code, I naturally want to know exactly what happens with it. Complicated 
heuristics with tricky corner cases will simply not do. Robustness is the 
issue, and, as always, doing as little as possible the key. Therefore I 
believe in a default heuristic much simpler than todays with an added 
possiblity for the individual user to introduce additional rules to support a 
specific programming (code formating) style. Just my 0.02.
Comment 11 Philipe Mulet CLA 2004-04-28 10:58:35 EDT
Too risky for now.
Defer. Will reconsider post 3.0
Comment 12 Martin Aeschlimann CLA 2004-05-26 12:13:22 EDT
*** Bug 47337 has been marked as a duplicate of this bug. ***
Comment 13 Frederic Fusier CLA 2004-05-27 09:28:50 EDT
We finally agreed with jdt-ui that bug 47337 was not a duplicate. That bug has
been fixed separately and put in 3.0 RC1...
Comment 14 Frederic Fusier CLA 2007-06-21 07:26:55 EDT
Reopen as LATER is deprecated...
Comment 15 Markus Keller CLA 2013-03-07 12:42:37 EST
*** Bug 56532 has been marked as a duplicate of this bug. ***
Comment 16 Markus Keller CLA 2013-03-07 12:44:45 EST
*** Bug 349959 has been marked as a duplicate of this bug. ***
Comment 17 Eclipse Genie CLA 2020-02-17 17:17:42 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.