Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 391331 - [1.8][compiler] Compiler should replicate annotations with mixed SE7 & SE8 targets
Summary: [1.8][compiler] Compiler should replicate annotations with mixed SE7 & SE8 ta...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 383624
Blocks: 287648 392238
  Show dependency tree
 
Reported: 2012-10-08 02:19 EDT by Srikanth Sankaran CLA
Modified: 2013-10-19 00:31 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2012-10-08 02:19:17 EDT
BETA_JAVA8:

From EDR draft section 2.3:

@Target({ ElementType.TYPE_USE, ElementType.METHOD })
public @interface SillyAnnotation {  }

If @SillyAnnotation were written before a non-void method, then the 
annotation would apply to both the return type and the method declaration. 
The annotation appears twice in the AST during annotation processing, 
and it appears twice in the classfile. ... If you write @SillyAnnotation 
on a void-returning method, then it applies only to the declaration, 
because it is not written in a type annotation position.

We need to add support for this part of the specification.
Comment 1 Srikanth Sankaran CLA 2012-10-08 02:20:22 EDT
Jay, this is a corner case scenario. I would touch this only after 
bug 383624 is resolved.
Comment 2 Stephan Herrmann CLA 2012-10-16 16:42:48 EDT
In today's BETA_JAVA8 I'm seeing 38 regressions (9 in NullAnnotationTest times 4 compliance levels + 2 in AnnotationDependencyTests).

It looks like all could be fixed for now by fixing this bug, I'll take a quick look.
Comment 3 Stephan Herrmann CLA 2012-10-16 17:08:00 EDT
May back-and-forth movement in this issue is documented in bug 392119.
Comment 4 Srikanth Sankaran CLA 2012-10-16 20:54:01 EDT
Stephan, assigning this to you - this can be worked at a pace & schedule
convenient to you.
Comment 5 Stephan Herrmann CLA 2012-10-17 18:44:30 EDT
Thanks for raising this bug, actually.

Due to the replication you quote the following case in bug 392238 is easily classified as nonsense:
  
  void foo(@Nullable Outer. @NonNull Inner arg)

The @Nullable annotation, besides being useless in this position per TYPE_USE, would - interpreted as an SE7 annotation - contradict the @NonNull annotation on the same line (see bug 392238 for more).
Comment 6 Srikanth Sankaran CLA 2013-02-27 01:39:43 EST
Jesper, Manoj raised this issued today:

// --
import java.lang.annotation.*;
public class X {
	public static void main(String[] args) {
		Outer outer = new Outer();
		Outer.Inner inner = outer.new Inner();
		@Marker3 Outer. @Marker1 Inner. @Marker2 Deeper deeper = inner.new Deeper();
	}
}

class Outer {
	class Inner {
		class Deeper {}
	}
}

@java.lang.annotation.Target(value = {ElementType.TYPE_USE})
@interface Marker1{}
@java.lang.annotation.Target(value = {ElementType.TYPE_USE})
@interface Marker2{}
@java.lang.annotation.Target(value = {ElementType.TYPE_USE})
@interface Marker3{}


While doing conversion, (ASTConverter: 3537) typeReference showed "Outer.@Marker1 Inner.@Marker2 Deeper". @Marker3 is missing (as a consequence of it not being in Annotations[0][] of course of typeReference).
// ---

If an annotation target clearly spells out that it is a type annotation
and it occurs in a Java7 location, perhaps we should transfer it to the type reference. Thanks for evaluating.
Comment 7 Jesper Moller CLA 2013-03-22 20:43:57 EDT
As I understand this, the task is really two-fold:

1) Any annotations targeted for TYPE_USE which are now put on a declaration need to be replicated to the first segment of the type use.
2) Any annotations on the declaration NOT targeted for the type of declaration must be removed from the annotations.

The trick regarding 'void' methods only applies to method declarations, right?

Should this affect the bindings only, or also modify the AST?
Comment 8 Jesper Moller CLA 2013-03-25 12:49:29 EDT
(In reply to comment #7)

> Should this affect the bindings only, or also modify the AST?

Re-reading comment 0 again, I guess it really should modify the AST, too.
I have a rough version which presently only works for locals, but it's shaping up fine.

Hybrid annotations are going to disturb formatting, though!
Comment 9 Stephan Herrmann CLA 2013-09-21 08:56:37 EDT
If a binding-only solution is acceptable, then I believe ASTNode.copySE8AnnotationsToType() resolves this issue by now.
OTOH, if we need an AST solution, than we should've solved this one before doing our binding tricks...
WDYT?
Comment 10 Srikanth Sankaran CLA 2013-09-25 23:11:49 EDT
(In reply to Stephan Herrmann from comment #9)
> If a binding-only solution is acceptable, then I believe
> ASTNode.copySE8AnnotationsToType() resolves this issue by now.
> OTOH, if we need an AST solution, than we should've solved this one before
> doing our binding tricks...
> WDYT?

I think the spec is talking about the Sun compiler tree API's which are not
standard. I think what is required is in-effect achievement of this to the
extent it is visible to other parties (class files, annotation processors etc)
Comment 11 Srikanth Sankaran CLA 2013-10-13 10:27:36 EDT
We have an issue with JEP120, where in when the container is just target TYPE_USE
and the repeating annotation is both TYPE_USE and METHOD, we emit extra containers
for METHOD when we should not. This could be addressed as part of this ticket.
Comment 12 Srikanth Sankaran CLA 2013-10-15 00:25:24 EDT
(In reply to Srikanth Sankaran from comment #11)
> We have an issue with JEP120, where in when the container is just target
> TYPE_USE
> and the repeating annotation is both TYPE_USE and METHOD, we emit extra
> containers
> for METHOD when we should not. This could be addressed as part of this
> ticket.

With the resolution of https://bugs.eclipse.org/bugs/show_bug.cgi?id=419412
this may have gone away - I didn't actually verify.

I think for the present bug per comment#10, we should not touch the ASTs
at all.

I think most of what is required should already in place. We may have just
to verify and close this ticket.
Comment 13 Srikanth Sankaran CLA 2013-10-19 00:31:31 EDT
Sorry for grabbing this, I am trying to wrap up loose ends before the early access
announcements.

Fix and tests released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=cdd7d3ab18b0522945b5ad8d6604c424fb55fd11

Replication is ensured in class files and bindings (inasmuch as the latter
is the underlying artifact for AnnotationMirror's), AST is nobody's business
and left untouched.