Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 402812 - [1.8][completion] Code Completion problems with static/default interface methods.
Summary: [1.8][completion] Code Completion problems with static/default interface meth...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: ANIRBAN CHAKRABORTY CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 402079
  Show dependency tree
 
Reported: 2013-03-09 10:50 EST by Srikanth Sankaran CLA
Modified: 2013-05-09 00:52 EDT (History)
1 user (show)

See Also:
srikanth_sankaran: review+


Attachments
Uploading patch for review (20.43 KB, patch)
2013-04-01 12:04 EDT, ANIRBAN CHAKRABORTY CLA
no flags Details | Diff
Applicable regression clean patch (24.43 KB, patch)
2013-04-02 17:27 EDT, ANIRBAN CHAKRABORTY CLA
no flags Details | Diff
Patch accommodating review comments. (24.09 KB, patch)
2013-04-22 04:39 EDT, ANIRBAN CHAKRABORTY CLA
no flags Details | Diff
Alternate simpler fix (19.57 KB, patch)
2013-05-08 06:33 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2013-03-09 10:50:55 EST
BETA_JAVA8:

Java 8 allows code carrying methods in interfaces in the form of static methods (not inherited by subtypes even though public; They can be accessed only
 statically using the declaring interface's type reference.) and default instance
methods.

There are various issues in completing on these method names as shown
by the snippet below:  | indicates cursor position.

// ---
interface I {
	static void staticMethod() {}
	default void defaultMethod() {
		stat|  // no proposals here
	}
}

public class X implements I {
	public void foo(I i) {
		i.defaultMethod(); // proposal for defaultMethod offered here
		I.stat|  // no proposals here.
		this.d| // no proposals here.
	}
}
Comment 1 Srikanth Sankaran CLA 2013-03-09 10:51:35 EST
Anirban, please follow up. TIA.
Comment 2 ANIRBAN CHAKRABORTY CLA 2013-03-14 02:33:33 EDT
Hello,
I'm working on this. Expect a patch within a week.
Thanks
Anirban
Comment 3 ANIRBAN CHAKRABORTY CLA 2013-03-24 11:55:09 EDT
Hello,
Still working on this. Some issues with the regression.
Will take a few more days.
Thanks
Anirban
Comment 4 ANIRBAN CHAKRABORTY CLA 2013-04-01 12:04:48 EDT
Created attachment 229209 [details]
Uploading patch for review

Hello,
Uploading patch for review. This has some regression failure though.
Thanks
Anirban
Comment 5 ANIRBAN CHAKRABORTY CLA 2013-04-02 17:27:43 EDT
Created attachment 229258 [details]
Applicable regression clean patch

Hello,
Uploading new regression clean patch for review.
Thanks
Anirban
Comment 6 Srikanth Sankaran CLA 2013-04-03 02:41:25 EDT
Here are the review comments:

(1) MessageSend.java: Remove the check for receiver being null. As can be
seen from other usages of this.receiver in this file, receiver field can
never be null.

(2) CastExpression: receiverIsImplicitThis() should chain to invocation site
and not return false. See how isSuperAccess is implemented in the same place.

(3) Same comment for Scope.java

(4) Please remove all formatting changes introduced in CompletionEngine.java
We don't want to reformat code unaltered by a fix.

(5) The patch generates additional compiler warnings. Please address all of
these warnings.

After these are addressed, please post a tested patch and I'll review one 
more time.
Comment 7 ANIRBAN CHAKRABORTY CLA 2013-04-03 06:51:56 EDT
Hello Srikanth,
Thanks for the comments#6.

1-3 : will do

I need some clarifications about (4) and (5) though.


>> (4) Please remove all formatting changes introduced in CompletionEngine.java
We don't want to reformat code unaltered by a fix.

These are not intended to be meaningless formatting. This code reorganization is supposed to implement functionality to solve a requirement in this bug.
With the 'default' function definition in an interface, a class hierarchy, implementing the interface, can completely do away with the ever implementing the method. This was not the case earlier. Any method declaration in an interface had to be implemented somewhere in the class hierarchy. The suggestions were being made by only the function definitions in the class hierarchy. But, with the advent of 'default' definitions, the class hierarchy need not define the method, but still expect the same in the suggestions. Hence the super-interfaces has to be searched for default methods.
If you look at the code reorganization closely, you'll see that previously the if block was completely bypassing the 'findInterfaceMethods(...)' call, if it not abstract, etc. But now, this call is not getting bypassed completely, but, if the conditions are do not satisfy, the calls is done only to find the default methods (getOnlyDefaultMethodsOfInterface == true). Thus this gets the default methods too in the suggestion.
Please let me know if you need further clarification.



>> (5) The patch generates additional compiler warnings. Please address all of
these warnings.
I ran the regression and it came clean. I thought, that this means both error, warnings and other outputs are matching. I don't understand what I'm missing, but if you may please provide any testcase or run scenarios, where I can see excess warnings, I'll be happy to clean them.

Thanks
Anirban
Comment 8 Srikanth Sankaran CLA 2013-04-04 01:06:33 EDT
(In reply to comment #7)

> These are not intended to be meaningless formatting. This code
> reorganization is supposed to implement functionality to solve a requirement
> in this bug.

Anirban,

Why is this code block:

			if (hasPotentialDefaultAbstractMethods &&
					(currentType.isAbstract() ||
							currentType.isTypeVariable() ||
							currentType.isIntersectionType() ||
							currentType.isEnum())){


changed to:

			if (hasPotentialDefaultAbstractMethods
					&& (currentType.isAbstract() ||
						currentType.isTypeVariable() ||
						currentType.isIntersectionType() ||
						currentType.isEnum())) {

??

Likewise there are other changes. Please go through every diff in this
file in the comparator and eliminate noise changes that are not material
to the fix.

> >> (5) The patch generates additional compiler warnings. Please address all of
> these warnings.
> I ran the regression and it came clean.

Please look in the problem markers view. Your patch generates additional
warnings in CompletionTests.java. This has nothing to do with regression
tests.
Comment 9 ANIRBAN CHAKRABORTY CLA 2013-04-22 04:39:53 EDT
Created attachment 229949 [details]
Patch accommodating review comments.

Patch accommodating review comments.
Comment 10 Srikanth Sankaran CLA 2013-05-08 06:32:09 EDT
Review comments:

(1) Please use the same code formatting conventions as you see used in the
project:

if(condition) ==> if (condition) 

(2) The changes in CompletionEngine look pretty complicated and can stand
for simplification. Basically, in the existing code, there is a short 
circuiting of searching in super interfaces for methods when the current type 
is concrete. This is because a concrete type for it to compile successfully 
must implement all interface methods and so search of the type should provide 
us with all the completion proposals as it is and searching superinterfaces 
cannot augment the set of proposals in any way.

Not so with Java8. A concrete type may not implement default methods of its
superinterfaces and so the methods it implements may not be a superset of
methods contracts of its super interfaces ==> For Java 8, super interfaces
MUST always be searched in the present scheme of things or else we will
miss some proposals.

Given this observation, we can simplify the fix quite bit.
Comment 11 Srikanth Sankaran CLA 2013-05-08 06:33:25 EDT
Created attachment 230642 [details]
Alternate simpler fix

Anirban, please take a look and let me know if you agree.
Comment 12 Srikanth Sankaran CLA 2013-05-08 06:51:50 EDT
(In reply to comment #10)

> (2) The changes in CompletionEngine look pretty complicated and can stand
> for simplification. Basically, in the existing code, there is a short 
> circuiting of searching in super interfaces for methods when the current
> type 
> is concrete. This is because a concrete type for it to compile successfully 
> must implement all interface methods and so search of the type should
> provide 
> us with all the completion proposals as it is and searching superinterfaces 
> cannot augment the set of proposals in any way.


See that this short circuiting is rendered ineffective by the patch in
comment#9.
Comment 13 ANIRBAN CHAKRABORTY CLA 2013-05-08 09:51:57 EDT
Hello Srikanth,
I agree with the patch.
Thanks
Anirban
Comment 14 Srikanth Sankaran CLA 2013-05-09 00:52:47 EDT
Fix and test released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=7c6fe4f21cb5ba3a5ee61e01b5b0b2742e043690

Thanks Anirban.