Generation of synthesized parameters
Joseph Darcy
joe.darcy at oracle.com
Wed Jan 30 16:05:42 PST 2013
On 1/30/2013 11:57 AM, Eric McCorkle wrote:
>
> On 01/29/13 20:14, Alex Buckley wrote:
>> I have been looking into the JLS treatment of the constructs mentioned
>> below, with an eye to clarifying matters in JLS8.
>>
>> I think a construct emitted by javac should be marked as synthesized if
>> it corresponds to a construct declared implicitly in source code.
>> Constructs declared implicitly in source code are:
>>
>> - default constructors (8.8.9)
>> - the initial parameters of constructors for non-private inner member
>> classes and anonymous classes (13.1, 15.9.5.1)
>> - the values and valueOf methods of enums (8.9.2)
>> - certain public fields of enums (8.9.2)
>> - certain public methods of interfaces (9.2)
>>
>> So for the purpose of this thread, only the second item need be marked
>> synthesized.
>>
>
> This gives rise to two questions:
>
> 1) Based on inspecting the javac source, it seems that
> Runtime*ParameterAnnotations won't include an entry for the synthesized
> parameter.
>
> My reasoning is this: writeParameterAttrs iterates through
> MethodSymbol.params in order to write out the attributes, and
> MethodSymbol.params does not seem to include this parameter.
> (Incidentally, I used that writeParameterAttrs as an example for writing
> out MethodParameters attributes, which is probably why MethodParameters
> right now don't contain these parameters either).
>
> Testing this shows that this is indeed the case.
>
> However, the current spec indicates that there should be a
> correspondence between MethodParameters (which should have the
> synthesized parameter), and Runtime*ParameterAnnotations (which, unless
> I'm wrong, won't), and the i'th type descriptor in the enclosing method.
>
> This tells me one of the spec or javac needs to be updated.
>
> 2) Does this mean that the remaining parameters should be marked
> SYNTHETIC? Or should they be left alone?
>
> a) Follow-up: is it objectionable to have javac set the
> SYNTHESIZED/SYNTHETIC modifier flag when it creates synthesized or
> synthetic parameters? It doesn't seem to do this now, otherwise the
> SYNTHETIC parameters would get reported correctly.
Just answering 2a), yes -- I believe it is appropriate and necessary for
javac (and other Java compilers) to get the synthesized and synthetic
bits for parameters and other constructs. After all, it is the compiler
who best knows what is being added that is not already in the source :-)
-Joe
More information about the compiler-dev
mailing list