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

Bug 326610

Summary: [content assist] code assist for package-info.java
Product: [Eclipse Project] JDT Reporter: Paul Fullbright <paul.fullbright>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: amj87.iitr, daniel_megert, Olivier_Thomann, pwebster, satyam.kandula, srikanth_sankaran, stanio, stephan.herrmann
Version: 3.6Flags: satyam.kandula: review+
Target Milestone: 3.8 M7   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 345285    
Attachments:
Description Flags
proposed fix v1.0 + regression tests
none
jar for tests
none
proposed fix v1.1 + regression tests none

Description Paul Fullbright CLA 2010-09-29 19:08:36 EDT
There are currently no code assist choices for the package declaration in package-info.java

I would expect to see at least annotations that are package targettable.
Comment 1 Dani Megert CLA 2010-09-30 04:41:53 EDT
This needs to be provided by JDT Core.
Comment 2 Paul Fullbright CLA 2011-01-20 16:28:45 EST
Incidentally, it looks like the lack of support extends to not being able to *add* code assist.  We get no usable CompletionContext anywhere in a package-info.java file.  The prefix is always null, the token start is always -1, and the token end is always -1.
Comment 3 Ayushman Jain CLA 2011-01-21 00:46:46 EST
(In reply to comment #2)
> Incidentally, it looks like the lack of support extends to not being able to
> *add* code assist.  We get no usable CompletionContext anywhere in a
> package-info.java file.  The prefix is always null, the token start is always
> -1, and the token end is always -1.

In that case, the Parser (CompletionParser) will have to support completion in package-info.java
Comment 4 Paul Fullbright CLA 2011-01-21 11:10:40 EST
Should I log an additional bug against the parser?  Or should this be reassigned/cloned?
Comment 5 Ayushman Jain CLA 2011-01-24 01:17:44 EST
(In reply to comment #4)
> Should I log an additional bug against the parser?  Or should this be
> reassigned/cloned?

This bug report is sufficient for whatever changes are needed. I'll look into this as soon as I have time. You can anyways look at the CompletionParser and see what rule gets triggered when u try completing in package-info.java. Adding relevant actions to that rule should give us the completion token and we can then build the context in CompletionEngine using this token.
Comment 6 Stephan Herrmann CLA 2012-01-29 07:20:16 EST
Given that package-info.java will gain importance for hosting @NonNullByDefault declarations, I'm offering my help on this bug, if desired.
Comment 7 Srikanth Sankaran CLA 2012-03-20 11:33:21 EDT
If you plan to include a fix for this in 3.8 M7, please adjust the
target suitably, so it becomes easier to track.
Comment 8 Ayushman Jain CLA 2012-03-20 14:23:07 EDT
Yes this is definitely important.
Comment 9 Ayushman Jain CLA 2012-04-06 16:00:23 EDT
Created attachment 213713 [details]
proposed fix v1.0 + regression tests
Comment 10 Ayushman Jain CLA 2012-04-09 01:12:05 EDT
Thanks for taking this up for review Satyam. 
A few points about the patch:
1) I noticed that content assist does not work in any java file if the caret is outside of a class body. Thats why content assist didn't also work in package-info.java. Here I believe keywords should be proposed atleast. In package-info, only package and import should be proposed. Also, when package is already declared, then it should not be proposed again.
2) The completion for annotations was messed up in package-info.java because we were 'overwriting' the package annotations (i.e. those declared in package-info) onto the type's annotations. In case, of package-info, package-info is the type, so all annotations defined here are on this type, and there are no annotations coming from the package (unlike actual types in a package). So, this operation should not be done for package-info type.

I also noticed two tests wrongly written where 3 classes in the same file were declared public, so fixed that as well, though that change is not related to this bug.
Comment 11 Satyam Kandula CLA 2012-04-09 08:24:06 EDT
(In reply to comment #10)
I just played with the patch and here are some comments:
- Please attach the jar file as a separate patch?
- When I try to do a content assist on say @Deprecated, it converts into @java.lang.Deprecated even if there is an import. 
- Why are some tests in CompletionTests and some in CompletionTests2?
- The tests are creating 1.4 projects. You should better create 1.5 projects.
Comment 12 Ayushman Jain CLA 2012-04-09 08:37:16 EDT
(In reply to comment #11)
> (In reply to comment #10)
> I just played with the patch and here are some comments:
> - Please attach the jar file as a separate patch?
Sure.
> - When I try to do a content assist on say @Deprecated, it converts into
> @java.lang.Deprecated even if there is an import. 
I think this is done by JDT/Text and may have been a side-effect of bug 215971. We should raise a separate bug for this.
> - Why are some tests in CompletionTests and some in CompletionTests2?
CompletionTests usually have simple tests where code complete is done on working copies whereas CompletionTests2 have more java model code. In keeping with the tradition, I separated the added tests. :)
> - The tests are creating 1.4 projects. You should better create 1.5 projects.
Ok. :)
Comment 13 Ayushman Jain CLA 2012-04-09 08:38:41 EDT
Created attachment 213746 [details]
jar for tests

This is to be copied inside ..\org.eclipse.jdt.core.tests.model\workspace\Completion
Comment 14 Satyam Kandula CLA 2012-04-09 09:58:57 EDT
(In reply to comment #13)
> Created attachment 213746 [details]
> jar for tests
> 
> This is to be copied inside
> ..\org.eclipse.jdt.core.tests.model\workspace\Completion
Looks like the jar attached is corrupted. I have picked up the one from the Eclipse installation and so, it's OK.
Comment 15 Satyam Kandula CLA 2012-04-09 10:00:23 EDT
(In reply to comment #12)
> > - Why are some tests in CompletionTests and some in CompletionTests2?
> CompletionTests usually have simple tests where code complete is done on
> working copies whereas CompletionTests2 have more java model code. In keeping
> with the tradition, I separated the added tests. :)
Thanks for the info. You might want to add these tests in CompletionTests_1_5.
Comment 16 Satyam Kandula CLA 2012-04-09 10:05:49 EDT
Here are the code review comments:
- Newly added call to system.arraycopy in CompilationUnitScope doesn't seem to be correct. Can you add a test which runs into this case? 
- Are the changes in CompletionEngine really necessary?
Comment 17 Ayushman Jain CLA 2012-04-10 05:59:19 EDT
Created attachment 213792 [details]
proposed fix v1.1 + regression tests

(In reply to comment #16)
> Here are the code review comments:
> - Newly added call to system.arraycopy in CompilationUnitScope doesn't seem to
> be correct. Can you add a test which runs into this case? 
I couldn;t find any such case so I just removed the arrayCopy. The test in CompletionTest2 shows why the if check is needed.
> - Are the changes in CompletionEngine really necessary?
I've added a test to show this.
Comment 18 Satyam Kandula CLA 2012-04-10 09:29:23 EDT
(In reply to comment #17)
The patch looks good.
Minor nitpicks: 
- The variable name proposePackageKeyword doesn't convey the right usage. I think it will be better be renamed as ignorePackageKeyword. 
- CompilationUnitScope - The if's can be merged.
Comment 19 Ayushman Jain CLA 2012-04-11 02:29:29 EDT
Took care of above comments and released in master via commit http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=e29082e6108e43f171cfe9fae0a56914a1f2ec3e
Comment 20 Paul Fullbright CLA 2012-04-13 11:11:52 EDT
Is this going to make it into any 3.x builds?  I'm looking at the latest and don't see it yet.
Comment 21 Paul Webster CLA 2012-04-13 11:20:26 EDT
(In reply to comment #20)
> Is this going to make it into any 3.x builds?  I'm looking at the latest and
> don't see it yet.

It should show up in the 3.8 I build when they get fixed, hopefully sometime next week ...

PW
Comment 22 Paul Fullbright CLA 2012-04-23 11:24:43 EDT
I just tried eclipse-SDK-N20120320-2000-win32-x86_64.
Should I be seeing some annotation completion proposals at this point?

(In reply to comment #21)
> It should show up in the 3.8 I build when they get fixed, hopefully sometime
> next week ...
> 
> PW
Comment 23 Ayushman Jain CLA 2012-04-23 11:29:03 EDT
(In reply to comment #22)
> I just tried eclipse-SDK-N20120320-2000-win32-x86_64.
> Should I be seeing some annotation completion proposals at this point?
No this bug was fixed later than that. You might want to try http://download.eclipse.org/eclipse/downloads/drops/I20120419-1434/
Comment 24 Paul Fullbright CLA 2012-04-23 13:13:27 EDT
(In reply to comment #23)
> No this bug was fixed later than that. You might want to try
> http://download.eclipse.org/eclipse/downloads/drops/I20120419-1434/

Grr, I'm reading "3" and seeing "4".  But your link is "no longer available for download", and all the other I or N builds are from March.  Any idea what's up on not having any working builds from *anytime* in the last month?
Comment 25 Ayushman Jain CLA 2012-04-23 13:52:48 EDT
(In reply to comment #24)
> (In reply to comment #23)
> > No this bug was fixed later than that. You might want to try
> > http://download.eclipse.org/eclipse/downloads/drops/I20120419-1434/
> 
> Grr, I'm reading "3" and seeing "4".  But your link is "no longer available for
> download", and all the other I or N builds are from March.  Any idea what's up
> on not having any working builds from *anytime* in the last month?

We're in the process of migrating our build infrastructure to build.eclipse.org, so there have been missing builds since the last month. I'm hoping there will be a good 4.2 build this Tuesday and 3.8 build this Wed. Thanks for your patience.
Comment 26 Srikanth Sankaran CLA 2012-04-30 04:58:16 EDT
Verified for 3.8 M7 using Build id: I20120429-2000