target_info structure of a method receiver
Alex Buckley
alex.buckley at oracle.com
Thu Sep 18 22:00:57 UTC 2014
Hi Joel,
On 9/18/2014 1:25 AM, Joel Borggren-Franck wrote:
> Thanks for the clarification. Makes sense, however there is still
> something with the receivers that feel problematic:
>
> --- 8< ---
>
> public class Outer<@B T, @C U> {
>
> class Inner {
>
> Inner(@A Outer<@NotB T, @NotC U> Outer.this) { ... }
>
> }
> }
>
> --- 8< ---
>
> Focusing on the inner class' constructor receiver parameter, JLS 8.4.1
> says:
>
> " In an inner class's constructor, the type of the receiver parameter
> must be the class or interface which is the immediately enclosing type
> declaration of the inner class, and the name of the receiver parameter
> must be Identifier . this where Identifier is the simple name of the
> class or interface which is the immediately enclosing type declaration
> of the inner class; otherwise, a compile-time error occurs."
>
> The type of the receiver parameter Outer<@NotB T, @NotC U> looks like a
> set of parameterized types to me, not "the type" in singular. Is this
> problematic?
The type Outer<@NotB T, @NotC U> is indeed a parameterized type. The
quote intends for it to be [a parameterization of] the [generic] class
Outer<T,U>. Another plausible type for the receiver parameter is
Outer<String,String>. Yet another plausible type is raw Outer. I don't
see a problem here - the immediately enclosing type declaration
represents a generic class and it's not controversial to parameterize
it. (Yes, you parameterize it with more types, each of which can be
annotated, but I don't see any real confusion.)
> What is the relation between the annotations on the receiver type's
> type parameters and the receiver type declaration's annotations on
> the type parameters?
You mean: what is the relation between annotations on the receiver
type's _type arguments_ and annotations on the receiver type
declaration's _type parameters_? The answer is: none. The type
parameters T and U of the generic class can be annotated one way, and
particular parameterized types Outer<...,...> can annotate their type
arguments in other ways. This is a feature!
> After this is erased, how should runtime reflection piece together
> the receiver type? There is no j.l.r.Type subtype that represents a
> generic class/interface that is not a class/interface declaration. If
> the receiver type should not be the erased type, is it desirable to
> represent a set of parameterized types with different type parameter
> annotations than on the class?
For your example, I'd expect j.l.r.Constructor#getAnnotatedReceiverType
to return a j.l.r.AnnotatedType which exposes @A and is instanceof
j.l.r.AnnotatedParameterizedType so you can obtain its annotated type
arguments @NotB T and @NotC U. (You happen to have used some in-scope
type parameters as the type arguments.)
Alex
More information about the compiler-dev
mailing list