on implementing state components as a first class concept

Vicente Romero vicente.romero at oracle.com
Thu Apr 25 20:17:14 UTC 2019


Hi,

Joe and I have been chatting offline about his proposal for making 
record state components a first class concept. The closest concept 
available in the compiler is, as seen from the javax.lang.model API: 
j.l.m.e.VariableElement which is implemented by 
com.sun.tools.javac.code.VarSymbol in javac. This is the same class we 
use for parameters, fields, etc. This means that we will be having two 
field-like structures inside the same class, inside the same scope and 
with the same name.

One way to overcome the same name issue could be to generate a synthetic 
name for the private field, kind or $stateComponent, that way the 
compiler won't have any issue attributing both field-like entities. The 
problem with this is that user code added to the record, will use the 
state component name so that user code will need to be rewritten, at 
parser time?, so that it refer to the synthetic name given to the 
private field. This is not a big deal but could generate other side-effects.

I'm not very happy with these options to implement state components as a 
first class concept mostly because of the user code rewriting issue. 
Other options could be to use the same field-like entities for both 
purposes or annotate the record with the state components information.

Comments?

Vicente


More information about the amber-dev mailing list