Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 415821 - [1.8][compiler] CLASS_EXTENDS target type annotation missing for anonymous classes.
Summary: [1.8][compiler] CLASS_EXTENDS target type annotation missing for anonymous cl...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 287648
  Show dependency tree
 
Reported: 2013-08-25 08:10 EDT by Srikanth Sankaran CLA
Modified: 2013-10-02 07:08 EDT (History)
0 users

See Also:


Attachments
Fix and tests (8.09 KB, text/plain)
2013-10-01 20:51 EDT, Andrew Clement CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2013-08-25 08:10:59 EDT
BETA_JAVA8:
----------

Per discussions in the EG list, the spec is being amended to require
a target_type=CLASS_EXTENDS type annotation for the following case:
This is apart from the target_type=NEW type annotation which we already
emit.

Note that the reference compiler already emits the CLASS_EXTENDS type
annotation, but not the NEW target type annotation, a bug has been raised
against javac for this purpose.

// ---
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface X {}

class C { void m() { new @X Foo() {}; } }
// --

From the EG discussion:

...

The wording for target_type=CLASS_EXTENDS (0x10) refers to a "type in 
extends clause of class or interface declaration" so it's not clear that 
the @X annotation should be stored this way. To clarify, the wording for 
target_type=CLASS_EXTENDS should say:

"type in extends clause of class or interface declaration (including the 
direct superclass of an anonymous class declaration), ..."

...
Comment 1 Srikanth Sankaran CLA 2013-08-25 08:11:27 EDT
Andy, please take a look, TIA.
Comment 2 Srikanth Sankaran CLA 2013-08-25 08:13:56 EDT
We should remember to check to do the right thing for the case below where
an interface is implemented by the anonymous class.

interface I {
	void f();
}
public class X {
void foo() {
	I i = new I () {

		public void f() {
		
		}
		
	};
	}
}
Comment 3 Andrew Clement CLA 2013-10-01 20:51:44 EDT
Created attachment 236025 [details]
Fix and tests

Two tests: one for the class case, one for the interface case.

The fix here is to ensure we don't lose the annotated type reference object, by attaching it to the generated type declaration for the anonymous usage. If attached correctly the type annotation generator will just do the right thing (which is why there are only 3 lines of change to make it work here).
Comment 4 Srikanth Sankaran CLA 2013-10-02 06:58:57 EDT
Fix is good, released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=5ecdad70bb6e2e1bbd5c5ec539acc885a5698c4e.

Thanks a lot Andy.
Comment 5 Srikanth Sankaran CLA 2013-10-02 07:07:53 EDT
Patch looks good. Released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=5ecdad70bb6e2e1bbd5c5ec539acc885a5698c4e.

Thanks Andy.
Comment 6 Srikanth Sankaran CLA 2013-10-02 07:08:57 EDT
Third attempt at resolving...