Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 237775

Summary: [content assist] Duplicate page directive imports added by content assist
Product: [WebTools] WTP Source Editing Reporter: Mauro Molinari <mauromol>
Component: jst.jspAssignee: Aidyl Kareh <amkareh>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: major    
Priority: P3 CC: cameron.bateman, nsand.dev
Version: 2.0.2Keywords: plan
Target Milestone: 3.2 M3Flags: nsand.dev: review+
Hardware: PC   
OS: Windows XP   
Whiteboard: qplan
Attachments:
Description Flags
Bug Fix Patch nsand.dev: iplog+, nsand.dev: review+

Description Mauro Molinari CLA 2008-06-19 08:23:39 EDT
Build ID: M20080221-1800

Steps To Reproduce:
1. create a new Dynamic Web Project (with Dynamic Web Module 2.4 and Java 5.0)
2. create a new Java class like this:

package a;

public class TestClass
{

}

3. in WebContent, create a new JSP, name it test.jsp and accept al the defaults.

This JSP is created:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

4. at line 10, start a scriptlet and try to define a TestClass viariable, in this way:

// cut //
<body>
  <%
      TestCl <= invoke code completion here!
  %>
</body>
// cut //

5. invoke code completion as shown above: select TestClass as the completion proposal suggests

6. the result is the following:
=> an import is added after <!DOCTYPE>:
<%@page import="a.TestClass"%>
(this is ok!)
=> your class name is completed as "TestCls", instead of "TestClass"!

7. try to remove the last "s" of "TestCls" and invoke code completion again

8. select the suggested TestClass again; the result is the following:
=> another import is added, right after the first one, and also wrong:
<%@page import="a.TestClass"%>
<%@page import="TestClass"%>
=> the class name is still completed as "TestCls" instead of "TestClass"
Comment 1 Cameron Bateman CLA 2009-05-08 18:28:59 EDT
What is interesting is that this is particular to the package name "a".  The same problem doesn't manifest if the class is "b.TestClass" or "aa.TestClass".
Comment 2 Aidyl Kareh CLA 2009-09-03 09:40:03 EDT
Created attachment 146389 [details]
Bug Fix Patch

Problem was caused by several errors in the JSPProposalCollector class. The incorrect code completion was caused by an error when removing the signature from the class name. Thus, in the recreation scenario, the regular expression "a." was being removed from "a.TestClass" instead of "a\\.". This caused for all the 'a' characters followed by any character to be removed. The multiple page import of the same class was caused by a problem on the condition that determines when the auto adding of the page import is needed. Fixed code to address these problems.
Comment 3 Nick Sandonato CLA 2009-09-28 13:42:19 EDT
Patch looks good. Thanks, Aidyl.