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

Bug 526590

Summary: [content assist] Annotation attributes are not completed for abstract method parameter annotations
Product: [Eclipse Project] JDT Reporter: Gayan Perera <gayanper>
Component: CoreAssignee: Gayan Perera <gayanper>
Status: CLOSED FIXED QA Contact: Till Brychcy <register.eclipse>
Severity: major    
Priority: P3 CC: jarthana, manoj.palat, register.eclipse
Version: 4.7   
Target Milestone: 4.8 M4   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/111844
https://git.eclipse.org/r/111979
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=d9bc7897f13a47cf70b0edfdef55bb3d99dfc9d8
Whiteboard:

Description Gayan Perera CLA 2017-10-28 01:18:17 EDT
Annotation attributes are not suggested when content assist is triggered on 
- method parameter annotation on interface methods
- method parameter annotation on abstract methods in classes

But attributes are suggested for:
- default method on interfaces
- none abstract methods on classes.

Ex:
@RestController
public interface Controller {
  public List findAll(@RequestParameter(...) String type);
}
Comment 1 Noopur Gupta CLA 2017-10-30 02:40:46 EDT
No result is returned by ICodeAssist#codeComplete in this case when invoked from JavaCompletionProposalComputer#internalComputeCompletionProposals.

Moving to JDT Core.
Comment 2 Gayan Perera CLA 2017-10-30 22:53:25 EDT
Raised to major since this cause lack of functionality.
Comment 3 Gayan Perera CLA 2017-11-15 08:36:59 EST
Any update on this issue? I would like to provide a patch if someone can shed some light on where i should look at.
Comment 4 Jay Arthanareeswaran CLA 2017-11-15 08:47:48 EST
(In reply to Gayan Perera from comment #3)
> Any update on this issue? I would like to provide a patch if someone can
> shed some light on where i should look at.

First thing you need to find is whether or not the parsed AST is okay. Plant a breakpoint in CompletionEngine#complete() on code parsedUnit.resolve() and see what the unit looks like. Typically, the unit will contain a node whose type starts with CompletionOn*. If there's a problem with recovery, it is likely you will see something broken here, for e.g, the scope or enclosing element for the completion node is incorrect. If everything is alright, let it resolve and see where things go wrong in resolving the Completion node. Typically, most CompletionOn* nodes have a method starting with resolve*(), which is another good place to watch.

Thanks for the offer, BTW.
Comment 5 Till Brychcy CLA 2017-11-15 16:07:57 EST
I know the annotation completion code a bit because of my work on bug 425035, so I can have a look at this.
Comment 6 Gayan Perera CLA 2017-11-17 08:06:45 EST
While debugging the path i found out that the reason is that parsedUnit.resolve(); doesn't throw a CompletionNodeFound signal. The reason in that at
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements() the #statements field is  null. But if this was the method implementation then the the #statments field is not null and resolving the first statement will signal.
Comment 7 Till Brychcy CLA 2017-11-17 08:40:11 EST
Probably the completionnode is moved from the parameters to the body during recovery but the body is not resolved in this case, because the method is abstract.

Maybe you can find the if() that causes this to be skipped.
Comment 8 Gayan Perera CLA 2017-11-17 08:46:31 EST
Found the place, Seems like the curpit is at
org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(MethodDeclaration, CompilationUnitDeclaration)

	if (md.isAbstract())
		return;

this cause the method not to be parsed which cause the parseBlockStatements method call in CompletionEngine#complete method not to update the method body. This cause the org.eclipse.jdt.internal.compiler.parser.RecoveredMethod.methodBody not to get updated which cause the problem i mentioned in my previous comment. Removing the if (md.isAbstract()) cause the completion to work, but not sure why that check is there is the first place. Can anyone help me out ?
Comment 9 Till Brychcy CLA 2017-11-17 08:57:20 EST
This may be just an optimization.

First thing you can try is to remove the if() and run the tests.
As this is only in AssistParser, it probably won't break anything.

Easiest way would be to create a gerrit.
I think this should be documented in https://wiki.eclipse.org/JDT_Core_Committer_FAQ
Comment 10 Eclipse Genie CLA 2017-11-18 10:45:21 EST
New Gerrit change created: https://git.eclipse.org/r/111844
Comment 11 Till Brychcy CLA 2017-11-18 17:40:44 EST
(In reply to Eclipse Genie from comment #10)
> New Gerrit change created: https://git.eclipse.org/r/111844

Thanks!

The tests ran successfully.

What remains to be done:

1) Please make gerrit for the master. All changes first go into the master, and if no problems appear in a milestone build, they may be backported to the maintenance branch.

2) Whenever possible, a regression test should be added. Easiest way to write one is to look for a similar one. In this case, the test should probably go into CompletionTests_1_5. Note you always have to run the whole class as Junit Plugin Test. But there is one useful feature: look for the commented line that sets the static variable TEST_NAMES and set it to the name of the test you're developing, then only this test will only be executed.
Comment 12 Gayan Perera CLA 2017-11-20 12:05:14 EST
when i tried to push to gerrit using the master branch it keeps on rejecting. any reason ?
Comment 13 Till Brychcy CLA 2017-11-20 12:50:00 EST
(In reply to Gayan Perera from comment #12)
> when i tried to push to gerrit using the master branch it keeps on
> rejecting. any reason ?

It usually tells you the reason in the dialog that pops up.

Have you added the signed-off-by?
Have you added a commit id?

If you forgot any of these, go to the git staging view, click on the "Amend..."-button,
Click on the relevant button(s) next to it to add was missing, commit again.
Comment 14 Eclipse Genie CLA 2017-11-21 09:53:44 EST
New Gerrit change created: https://git.eclipse.org/r/111979
Comment 15 Till Brychcy CLA 2017-11-21 12:34:11 EST
(In reply to Eclipse Genie from comment #14)
> New Gerrit change created: https://git.eclipse.org/r/111979

Excellent!

One minor thing: Can you please update the patch so the 
"Author" and "Signed-Off" fields contain your name, i.e. instead of 

gayanper <gayanper@gmail.com>

it should be 

Gayan Perera <gayanper@gmail.com>
Comment 17 Till Brychcy CLA 2017-11-22 12:58:10 EST
(In reply to Eclipse Genie from comment #16)
> Gerrit change https://git.eclipse.org/r/111979 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=d9bc7897f13a47cf70b0edfdef55bb3d99dfc9d8

Released for 4.8M4

Thanks, Gayan!
Comment 18 Gayan Perera CLA 2017-11-25 08:36:19 EST
Glad that i could make a contribution to improve eclipse :).
Comment 19 Manoj N Palat CLA 2017-12-04 08:06:33 EST
(In reply to Gayan Perera from comment #18)
> Glad that i could make a contribution to improve eclipse :).

+1. Thanks Gayan for the contribution.

To make it  a complete commit, can you create a test as well? Almost every fix  generally is accompanied with a reproducible testcase which clearly fails before the fix and passes after the fix.
See CompletionTests18 for various examples. Let us know if you require more info..
Comment 20 Till Brychcy CLA 2017-12-04 08:15:21 EST
(In reply to Manoj Palat from comment #19)
> (In reply to Gayan Perera from comment #18)
> > Glad that i could make a contribution to improve eclipse :).
> 
> +1. Thanks Gayan for the contribution.
> 
> To make it  a complete commit, can you create a test as well? Almost every
> fix  generally is accompanied with a reproducible testcase which clearly
> fails before the fix and passes after the fix.
> See CompletionTests18 for various examples. Let us know if you require more
> info..

Manoj, I guess you looked at the wrong gerrit, he already did that!
Comment 21 Manoj N Palat CLA 2017-12-05 23:04:17 EST
(In reply to Till Brychcy from comment #20)
> (In reply to Manoj Palat from comment #19)
> > (In reply to Gayan Perera from comment #18)
> > > Glad that i could make a contribution to improve eclipse :).
> > 
> > +1. Thanks Gayan for the contribution.

> 
> Manoj, I guess you looked at the wrong gerrit, he already did that!

Thanks Till. My bad - yes, I see the tests in the commit - was looking at the wrong gerrit as you mentioned.
Comment 22 Manoj N Palat CLA 2017-12-06 00:29:58 EST
Verified for Eclipse Photon 4.8 M4 with Build id: I20171205-0800
Comment 23 Gayan Perera CLA 2018-08-26 02:19:08 EDT
This is now fixed in Eclipse Photon 4.8, therefore closing the issue.