Bug 108258 - [typing] Toggle Comment on folded Javadoc fails
Summary: [typing] Toggle Comment on folded Javadoc fails
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: 3.1.1   Edit
Assignee: Tom Hofmann CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-29 07:24 EDT by Ulrich Voigt CLA Friend
Modified: 2005-09-07 09:15 EDT (History)
2 users (show)

See Also:


Attachments
ProjectionViewer.java.diff (2.33 KB, patch)
2005-08-31 11:15 EDT, Tom Hofmann CLA Friend
no flags Details | Diff
ProjectionViewer.java.diff (7.10 KB, patch)
2005-09-05 11:19 EDT, Tom Hofmann CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Voigt CLA Friend 2005-08-29 07:24:24 EDT
Eclipse is trying to compile a javadoc comment as java-sourcecode if it gets
uncommented.

Example (linenumbers added):
1    /**
2     * This method gets called when a bound property is changed.
3     * 
4     * @param evt A PropertyChangeEvent object describing the event source and
the property that has
5     *            changed.
6     */
7    public void propertyChange(PropertyChangeEvent evt)
8    {
9    }

1. Mark line 2-6 and comment with Strg-/
2. Save the file
3. Mark line 2-6 and uncomment with Strg-/
4. Save the file
=> The javadoc comment is handled as sourcecode and compile errors are displayed
for the javadoc section
Comment 1 Ulrich Voigt CLA Friend 2005-08-29 07:31:46 EDT
The steps to reproduce are wrong. It should be:

1. The javadoc comment must be folded
2. Mark the folded javadoc comment and the complete method
3. Comment it with Strg-/ (everything except line 1 is commented with '//')
4. Save the file
5. Mark line 2-9 and uncomment with Strg-/
6. Save the file
=> The javadoc comment is handled as sourcecode and compile errors are displayed
for the javadoc section
Comment 2 Frederic Fusier CLA Friend 2005-08-29 08:03:09 EDT
Move to JDT/UI
It seems that editor behaves as line 1 was commented but didn't show // at
beginning. Selecting line 1 and uncomment it fixes the problem...
Comment 3 Dani Megert CLA Friend 2005-08-31 03:30:31 EDT
The document is correctly updated but the first comment line is not correctly
shown in the editor is not.

This used to work in 3.0.

Tom, please investigate.
Comment 4 Tom Hofmann CLA Friend 2005-08-31 03:58:15 EDT
Notes:

- To reproduce, in step 2 (from comment 1), make sure to select the folded line
entirely (otherwise, the first line of the javadoc region is not commented out).

- choosing "New editor" afterwards opens a new editor that correctly shows the
contents of the document. Also, closing and reopening the editor works as expected.

I suspect a problem in the projection infrastructure.
Comment 5 Tom Hofmann CLA Friend 2005-08-31 09:50:39 EDT
DefaultJavaFoldingStructureProvider creates a foldable region for the lines that
(at least partially) contain javadoc. The foldable region translates to two 
fragments that are removed in the projection: the first line of the javadoc, and
the remaining lines of the javadoc after the caption line. The double slashes
get added at the offset of the first fragment, which is equal to the offset of
the foldable region.

Position updating inconsistency:
a. "comment lines" adds double slashes to all lines
b. the document mapping gets updated accordingly <- FragmentUpdater
c. the folding regions tracked by the java folding structure provider get
updated <- DefaultPositionUpdater (since AnnotationModel uses the default
position category)
d. the reconcile triggers recomputation of the folding structure
e. the folding region for the javadoc gets removed, which triggers
ProjectionDocument::addMasterDocumentRange

Both the fragment and the foldable region get updated by position updaters.
However, two different position updaters are used that have slightly different
semantics when adding the slashes that to the first javadoc line (which is
folded away):

- FragmentUpdater considers them to be part of the java doc line fragment
(inclusive).
- DefaultPositionUpdater does not include the slashes in the foldable region,
since the document change happens right at the offset of the position (exclusive).
Comment 6 Tom Hofmann CLA Friend 2005-08-31 10:38:00 EDT
A solution would be to enforce strictly line based fragments in
ProjectionViewer::{add,remove}MasterDocumentRegion
Comment 7 Tom Hofmann CLA Friend 2005-08-31 11:00:30 EDT
Fixed > 20050831

The projection infrastructure can handle arbitrary fragments, but
ProjectionViewer only supports line based fragments. ProjectionViewer must
therefore ensure that any fragments it adds to the document mapping are stricly
line based, even if the ProjectionAnnotations do not adhere to this convention.
Comment 8 Tom Hofmann CLA Friend 2005-08-31 11:15:41 EDT
Created attachment 26706 [details]
ProjectionViewer.java.diff

Patch against ProjectionViewer.java R1.75

This is a 3.1.1 candidate.
Comment 9 Dani Megert CLA Friend 2005-09-01 07:51:48 EDT
Agree. Approving for 3.1.1.

Slightly modified the patch together with Tom.
Second reviewed by Tobias.
Released into R3_1_maintenance.
Comment 10 Markus Keller CLA Friend 2005-09-02 08:54:58 EDT
start verifying ...
Comment 11 Markus Keller CLA Friend 2005-09-02 09:31:56 EDT
Verified in M20050831-1200 + ZRH plugins from R3_1_maintenance.
Comment 12 Markus Keller CLA Friend 2005-09-02 09:55:07 EDT
Reopening, since I found an analogous case where the last line is not correctly
updated:

public class Try {
    int a;
    int b;
}

- fold the type
- select the whole line
- press Ctrl+Shift+/ (Add Block Comment)
=> the closing */ is not rendered
Comment 13 Tom Hofmann CLA Friend 2005-09-05 10:02:45 EDT
Investigating fix...
Comment 14 Tom Hofmann CLA Friend 2005-09-05 11:19:09 EDT
Created attachment 26832 [details]
ProjectionViewer.java.diff

Patch against ProjectionViewer.java R1.75.2.1

This patch removes the prior fix and chooses a different approach: when
collapsing ProjectionAnnotations, we always delegated to IProjectionPosition to
compute the actual folding regions. However, when expanding a
ProjectionAnnotation, we previously took the entire region of the projetion
annotation, instead of again letting the annotation decide which regions were
folded. This caused the asymmetric behavior described in this PR.

This patch also delegates to the IProjectionPosition to compute the regions to
expand.

The patch works fine for me. However, the changes are far from minimal and we
have to debate about whether to include it into R3_1_maintenance.
Comment 15 Tom Hofmann CLA Friend 2005-09-05 11:19:38 EDT
Avail. in HEAD > 20050905
Comment 16 Dani Megert CLA Friend 2005-09-07 09:14:00 EDT
The bug described in comment 12 is already in since R3.0. Since the fix for this
problem is not trivial and I just found another case where it's not working at
the end of the file we will not put it into 3.1.1.

Filed bug 108925 to track this further.
Comment 17 Dani Megert CLA Friend 2005-09-07 09:15:01 EDT
Marking as verified since the regression which has been introduced got fixed.