Bug 151500 - [assist] Method parameter names are not displayed for inner classes
Summary: [assist] Method parameter names are not displayed for inner classes
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.7 M1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 316937
Blocks:
  Show dependency tree
 
Reported: 2006-07-21 23:17 EDT by Remy Suen CLA
Modified: 2011-01-18 09:56 EST (History)
8 users (show)

See Also:
jarthana: review+


Attachments
The jar file to attach with the compiled class file for error reproduction purposes. (1.01 KB, application/octet-stream)
2006-07-21 23:18 EDT, Remy Suen CLA
no flags Details
Source jar file for attaching the source to the compiled class file. (803 bytes, application/octet-stream)
2006-07-21 23:19 EDT, Remy Suen CLA
no flags Details
Diff for InternalCompletionProposal.java that seems to fix the problem. (746 bytes, text/plain)
2010-06-15 02:34 EDT, Andreas Magnusson CLA
amj87.iitr: iplog+
Details
fix + tests (10.16 KB, patch)
2010-07-05 03:54 EDT, Ayushman Jain CLA
no flags Details | Diff
fix + updated tests (10.43 KB, patch)
2010-07-05 08:06 EDT, Ayushman Jain CLA
amj87.iitr: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2006-07-21 23:17:36 EDT
When performing code completion on an inner class's method, the names of the parameters are not included. The scenario occurs wherein the user attaches an external jar, and then attaches the source code.

1. Add the external jar to the build path
2. Start instantiating the class, foo.Foo f = new foo.Foo();
3. Go inside Foo and then use the attach source button to add the zipped up source code.
4. f.bar. (content assist pops up) Note here that someMethod presents 'arg0' as the parameter's name although subsequently pressing F3 on someMethod will load the source up and display 'parameterName' as the parameter's name.
Comment 1 Remy Suen CLA 2006-07-21 23:18:36 EDT
Created attachment 46672 [details]
The jar file to attach with the compiled class file for error reproduction purposes.
Comment 2 Remy Suen CLA 2006-07-21 23:19:21 EDT
Created attachment 46673 [details]
Source jar file for attaching the source to the compiled class file.
Comment 3 Dani Megert CLA 2006-07-22 12:14:56 EDT
Tom, please check whether this is us or JDT Core.
Comment 4 Tom Hofmann CLA 2006-07-24 04:46:16 EDT
We use the parameter names received from core. Moving to jdt-core.
Comment 5 Frederic Fusier CLA 2006-08-01 11:06:44 EDT
Not sure, but initial tracking seems to locate problem around findMethodParameterNames(char[],char[],char[],char[][]) method in CompletionProposal. While debugging, I saw that declaringTypeName is Foo.Bar and the NameLookup does not find type with this name as it seems to expect name with $ for member types...
HTH
Comment 6 Dani Megert CLA 2010-06-14 09:26:43 EDT
Still an issue in 3.6 RC4 and it's also not working for the case where the parameter names are in the class file and no source attached.
Comment 7 Andreas Magnusson CLA 2010-06-15 02:34:26 EDT
Created attachment 171895 [details]
Diff for InternalCompletionProposal.java that seems to fix the problem.

I debugged the issue and found that the problem is that the symbol name is concatenated in findMethodParameterNames(...) and immediately split in NameLookup.findType(name, ....). That doesn't go well for inner classes.
This patch calls NameLookup.findType(typeName, packageName, ...) and bypasses the concatenation/split and seems to solve this problem. I have no idea if it creates other problems though.
Comment 8 Ayushman Jain CLA 2010-06-15 07:23:56 EDT
(In reply to comment #7)
> Created an attachment (id=171895) [details]
> Diff for InternalCompletionProposal.java that seems to fix the problem.
> 
> I debugged the issue and found that the problem is that the symbol name is
> concatenated in findMethodParameterNames(...) and immediately split in
> NameLookup.findType(name, ....). That doesn't go well for inner classes.
> This patch calls NameLookup.findType(typeName, packageName, ...) and bypasses
> the concatenation/split and seems to solve this problem. I have no idea if it
> creates other problems though.

Thanks for the fix Andreas. You're correct - the concatenation and then subsequent separation of the package name and the declaring type name is the culprit here. When findType(name, ...) tries to de-concatenate the package name from the declaring type name, it results in the package name as foo.Foo and declaring type name as Bar. It should rather be foo and Foo.Bar respectively. Actually, I dont even understand why we need to follow this redundant approach at all, when we have an overloaded method NameLookup.findType(String typeName, String packageName,...)
which can take both the package and declaring type names as arguments. So i think its correct to bypass this concatenation step and straightaway call this instance of the findType method.

Note that this only occurs in when the source is in an external jar, because in the normal case, method argument names are computed inside CompletionEngine itself. Also note that attaching source/not shouldnt have any influence on this case.

Let me test the fix, and submit a final patch with testcase attached.
Comment 9 Ayushman Jain CLA 2010-06-15 12:10:44 EDT
While investigating, I found out one peculiar behaviour in JavaElement#getElementInfo(IProgressMonitor) due to which the following case still fails with the patch:

Suppose Foo.Bar in the referenced jar had a constructor - Bar(int a, int b) {}, and Foo itself had a constructor - Foo(int a)
Now the following code :
  
  new foo.Foo.Bar([CTRL-SPACE]

shows argument proposals as arg0 and arg1.

while 

new foo.Foo([CTRL-SPACE]

shows the correct proposal i.e. 'a'.

I've opened bug 316937 for this. Once that gets fixed, the above fix will be sufficient.  Note that a similar change will also have to done to InternalCompletionProposal.findConstructorParameterNames(..)
Comment 10 Ayushman Jain CLA 2010-07-05 03:54:18 EDT
Created attachment 173389 [details]
fix + tests

This is the patch incorporating Andreas' fix. With this, the problem doesnt occur even without the source attached.
The change in line InternalCompletionProposal.java:252 is to make sure that once parameter names are found, we dont go ahead to line 258 and attempt to find them all over again, as was the current behaviour.

Jay, requesting a quick review.
Comment 11 Jay Arthanareeswaran CLA 2010-07-05 06:07:30 EDT
(In reply to comment #10)
> Created an attachment (id=173389) [details]
> fix + tests
> 
> Jay, requesting a quick review.

The fix looks good, Ayush. I have a couple of comments on the tests, though.
1) I think it's better to use the relevance constant instead of the calculated value. This way when the constant values change, the existing tests will still pass.
2) I don't see how the folder "/P/src/p151500" gets used in the tests. May be I missed something?
Comment 12 Ayushman Jain CLA 2010-07-05 08:06:15 EDT
Created attachment 173414 [details]
fix + updated tests

updated fix according to above review comments. Thanks Jay!
Comment 13 Ayushman Jain CLA 2010-07-07 09:47:02 EDT
Released in HEAD for 3.7M1.
Added tests:
CompletionTests2#testBug151500a()
CompletionTests2#testBug151500b()
CompletionTests2#testBug151500c()
Comment 14 Dani Megert CLA 2010-07-07 11:04:35 EDT
Ayush, you don't need to set the iplog flag since you're a committer now.
Comment 15 Ayushman Jain CLA 2010-07-07 11:08:34 EDT
(In reply to comment #14)
> Ayush, you don't need to set the iplog flag since you're a committer now.

The fix was basically contributed by Andreas. I just introduced the tests and made some additions to the fix. So to give credit to Andreas, dont i need to set the iplog?
Comment 16 Dani Megert CLA 2010-07-07 11:16:50 EDT
>The fix was basically contributed by Andreas. I just introduced the tests and
>made some additions to the fix. So to give credit to Andreas, dont i need to
>set the iplog?
Yes, if that's the case you need to set the iplog flag on his patch, otherwise you will end up in the IP log used for legal review.
Comment 17 Ayushman Jain CLA 2010-07-07 13:57:32 EDT
Comment on attachment 171895 [details]
Diff for InternalCompletionProposal.java that seems to fix the problem.

Setting the iplog on Andreas' patch.
Comment 18 Srikanth Sankaran CLA 2010-08-04 03:00:22 EDT
Verified for 3.7 M1 using build I20100802-1800
Comment 19 Eddie Galvez CLA 2011-01-14 15:36:05 EST
Question -- we have an eclipse product where we have projects that have java build paths that include a Classpath Container that directs out to an external jar. The classpath container code attaches javadoc to that jar, and we have a class like this:


package some.package:

public class SomeException extends Exception

public abstract class SomeClass
 public final class InnerClass extends SomeException


when our end-users are typing

InnerClass ic = new InnerClass([CTRL-SPACE]

they just see arg0, arg1 and no javadoc.
Note that the CLASS javadoc for InnerClass appears as they hover over the type string "InnerClass". If they hover over the "new InnerClass" portion, they will see:

some.package.SomeClass.InnerClass.InnerClass(SomeClass arg0, String arg1, String arg2)


which might be where the trouble stems from; technically, yes, the first argument is the pointer to the containing class, but shouldn't the javadoc layer know to unwind that? (I can look at the html file on disk that the javadoc setting resolves to and I can see the constructor documentation in the html)

This is in 3.6.1. If this is the same issue, it would be great if this could make it to 3.6.2.
Comment 20 Dani Megert CLA 2011-01-17 03:25:19 EST
(In reply to comment #19)
Please don't hijack an existing bug but open a new one instead (https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT).
Comment 21 Eddie Galvez CLA 2011-01-18 09:56:41 EST
(In reply to comment #20)
> (In reply to comment #19)
> Please don't hijack an existing bug but open a new one instead
> (https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT).

I was attempting to avoid filing a DUPLICATE as reading through this ticket it appears related, but at your demand a new ticket # is coming in.