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

Bug 488663

Summary: [1.9] Allow diamond with anonymous classes
Product: [Eclipse Project] JDT Reporter: Jay Arthanareeswaran <jarthana>
Component: CoreAssignee: Sasikanth Bharadwaj <sasikanth.bharadwaj>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat, markus.kell.r, sasikanth.bharadwaj, stephan.herrmann
Version: 4.5.1Flags: sasikanth.bharadwaj: review? (stephan.herrmann)
Target Milestone: BETA J9   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/78691
https://git.eclipse.org/r/83111
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=8f0eb26398d5c8dde9ae3b5affe939426eea53ca
https://git.eclipse.org/r/85256
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=cfc8f74b9c8820b855dd3ffbed748d7233058b28
Whiteboard:
Bug Depends on:    
Bug Blocks: 495954    

Description Jay Arthanareeswaran CLA 2016-02-29 00:14:06 EST
The coin project in JEP 213 states:

"Allow diamond with anonymous classes if the argument type of the inferred type is denotable. Because the inferred type using diamond with an anonymous class constructor could be outside of the set of types supported by the signature attribute, using diamond with anonymous classes was disallowed in Java SE 7. As noted in the JSR 334 proposed final draft, it would be possible to ease this restriction if the inferred type was denotable."

This is already supported in JDK 9, we should add support too in our BETA_JAVA9 branch.
Comment 1 Eclipse Genie CLA 2016-08-09 09:58:14 EDT
New Gerrit change created: https://git.eclipse.org/r/78691
Comment 2 Eclipse Genie CLA 2016-10-13 08:38:52 EDT
New Gerrit change created: https://git.eclipse.org/r/83111
Comment 3 Sasikanth Bharadwaj CLA 2016-10-17 02:57:29 EDT
Stephan, please take a look at the change.

I'm not sure about a couple of things with this.

1. In AllocationExpression.inferDiamondCOnstructor, the special handling if allocationType isInterface - would it be better to add the no-arg constructor to the PTB and proceed with sfmb.applyTypeArgumentsOnConstructor?

2. All non-private instance methods in an anonymous class using '<>' must be treated as if they are annotated with @override. To achieve this, I'm setting the TagBits.AnnotationOverride bit on the method. Would it be better to handle this in the MethodDeclaration.resolve instead?

3. Have I covered everything? :-)

Thanks in advance for your time
Comment 4 Sasikanth Bharadwaj CLA 2016-10-17 03:46:57 EDT
I wonder why genie did not comment on this bug - I released the change as a first cut implementation so that we will have a build with this feature to demo, leaving the bug open for follow up actions comments

Released via commit http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA9&id=8f0eb26398d5c8dde9ae3b5affe939426eea53ca
Comment 5 Sasikanth Bharadwaj CLA 2016-10-17 03:49:22 EDT
One more thing I'm not sure about that I forgot to mention in earlier comment

I assumed redundant type argument specification check would now apply for anonymous diamond too - does that hold?
Comment 7 Markus Keller CLA 2016-11-16 06:36:00 EST
Y20161110-1000

A "Redundant specification of type arguments" problem is wrongly reported for anonymous types in 1.8 mode:

package p;
import java.util.Comparator;
public class C {
	Comparator<String> comparator = new Comparator<String>() { //
		@Override
		public int compare(String o1, String o2) {
			return 0;
		}
	};
}

This causes various compile errors in platform.ui projects.

The new analysis must only be active for source level >= 9. I'm surprised that we don't have a test case for this in Java 7 or 8 mode.
Comment 8 Eclipse Genie CLA 2016-11-18 00:43:04 EST
New Gerrit change created: https://git.eclipse.org/r/85256
Comment 10 Sasikanth Bharadwaj CLA 2016-11-22 05:17:11 EST
(In reply to comment #7)
> The new analysis must only be active for source level >= 9. I'm surprised that
> we don't have a test case for this in Java 7 or 8 mode.
Thanks Markus. Now we do.
Comment 11 Sasikanth Bharadwaj CLA 2016-11-24 05:11:05 EST
Bug 506952 comment 3 identifies some tests that fail when run with JDK9 because of change in behavior w.r.t diamond in anonymous class declarations. Fixed these failures via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA9&id=30f7fbb7f1e3845d31ba25b4ce8dc4eb4bcb844e