Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339328 - Wrong beginning replacement offset used when apply tag proposals in first child level of DOM Document
Summary: Wrong beginning replacement offset used when apply tag proposals in first chi...
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: jst.jsp (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows Server 2003
: P3 normal with 1 vote (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Nick Sandonato CLA
QA Contact: Nick Sandonato CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-09 04:27 EST by Bin Ouyang CLA
Modified: 2012-07-17 12:13 EDT (History)
3 users (show)

See Also:


Attachments
patch (1.74 KB, patch)
2011-10-18 14:51 EDT, Nick Sandonato CLA
no flags Details | Diff
Example of JSP file causing error (98 bytes, text/plain)
2012-03-20 05:01 EDT, Victor Homyakov CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bin Ouyang CLA 2011-03-09 04:27:32 EST
Build Identifier: M20100909-0800

when apply tag proposals in JSP Editor, if the tag is a top level node, which means its parent is DOM Document, then the applied proposal text will get a more "<" before cursor position. Like user input "<jsp:at" at the beginning of document and apply jsp:attribute proposal, then the editor replace it with "<<jsp:attribute name=""></jsp:attribute>". 

Reproducible: Always

Steps to Reproduce:
1.New a jsp file by Jsp file wizard, and use JSP Template "New JSP File(html)".
2.Input "<jsp:at"at the beginning of editor.
3.Press CTRL+SPACE.
4.Apply "jsp:attribute" proposal.
5.Then you can see the wrong applied text: "<<jsp:attribute name=""></jsp:attribute>".
Comment 1 Carl Anderson CLA 2011-03-09 12:04:53 EST
Bin, based on the build identifier, I am assuming that you are using Eclipse 3.6 SR1, which corresponds to WTP 3.2.2.  Have you tried 3.6 SR2 yet?
Comment 2 Nick Sandonato CLA 2011-03-09 14:14:51 EST
The computer was not taking into account the offset created by the leading < when calculating the replacement text. Changes have been checked into HEAD. Thanks for the bug report.
Comment 3 Bin Ouyang CLA 2011-10-13 05:57:36 EDT
I found the bug is still there with WTP 3.3.1, could u check this again?
Comment 4 Nick Sandonato CLA 2011-10-18 14:51:08 EDT
Created attachment 205451 [details]
patch

It looks like this original fix would have only worked with an empty document, not one that had contents. This patch should correct that.
Comment 5 Nick Sandonato CLA 2011-10-18 14:57:29 EDT
Released the changes to 3_3_Maintenance and HEAD. Thanks for re-opening this.
Comment 6 Victor Homyakov CLA 2012-03-10 15:48:06 EST
This problem is still present in Eclipse 3.7.2 (WTP 3.3.2).

Eclipse: Eclipse Java EE IDE for Web Developers.
Version: Indigo Service Release 2
Build id: 20120216-1857
Comment 7 Victor Homyakov CLA 2012-03-17 14:24:33 EDT
Reopen please. Or I should open new bug?
Comment 8 Nick Sandonato CLA 2012-03-19 17:50:17 EDT
(In reply to comment #7)
> Reopen please. Or I should open new bug?

Hi Victor,

I'm unable to reproduce this in Indigo based on the original description of the bug. Do you have a different scenario that you're experiencing this with?
Comment 9 Victor Homyakov CLA 2012-03-20 05:00:08 EDT
(In reply to comment #8)
> I'm unable to reproduce this in Indigo based on the original description of the
> bug. Do you have a different scenario that you're experiencing this with?

OK. I've got two scenarios. The first is similar to reporter's - with new JSP file.

1. Create new JSP file in existing project (right click on Project Explorer/Navigator/etc.  -> New -> Other... or File -> New -> Other... or Ctrl+N, then choose JSP file, then Finish).

2. Delete everything except of the first line. Content of JSP should look like:
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

3. Position cursor on the second line (empty) and type "<jsp:a" (without quotes). JSP proposals should appear with single selected choice jsp:attribute.

4. Press Enter. JSP will now look like
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<<jsp:attribute name=""></jsp:attribute>

Second scenario: with existing JSP file.

1. I have existing JSP file with following content:
<%@page contentType="text/html; charset=UTF-8"%>

<div class="center">

<button>OK</button>
</div>

note that 2nd and 4th lines are empty.

2. Place cursor to the second line. Type jsp:a, press Enter.

3. Place cursor to the fourth line. Type the same jsp:a, press Enter.

Resulting JSP:
<%@page contentType="text/html; charset=UTF-8"%>
<<jsp:attribute name=""></jsp:attribute>
<div class="center">
<jsp:attribute name=""></jsp:attribute>
<button>OK</button>
</div>
Comment 10 Victor Homyakov CLA 2012-03-20 05:01:48 EDT
Created attachment 212900 [details]
Example of JSP file causing error
Comment 11 Victor Homyakov CLA 2012-04-05 17:39:18 EDT
Have you reproduced error?
Comment 12 Nick Sandonato CLA 2012-04-09 16:51:22 EDT
(In reply to comment #11)
> Have you reproduced error?

Hi, Victor. I am able to reproduce it now. I think the leading page directive was important to reproducing.
Comment 13 Nick Sandonato CLA 2012-04-09 16:54:29 EDT
(In reply to comment #12)
> (In reply to comment #11)
> > Have you reproduced error?
> 
> Hi, Victor. I am able to reproduce it now. I think the leading page directive
> was important to reproducing.

Oh also, if you you invoke content assist and type out jsp:a, you won't have this problem. It seems to be related to leading with the <, which I may have forgotten when trying to reproduce.
Comment 14 Nick Sandonato CLA 2012-04-09 17:33:48 EDT
Checked in changes. The problem was in how the < is parsed when on a new line. By being on a new line after the page directive, the < became the last document region. So this needed to be checked.
Comment 15 Victor Homyakov CLA 2012-07-17 12:13:03 EDT
(In reply to comment #14)
> Checked in changes.

Is this fix available for Eclipse 3.8? I've installed Eclipse SDK (Version: 3.8.0 Build id: M20120626-2030) and latest Web Tools/Java Web Tools, but this problem persists.