Paul King created GROOVY-10004:
----------------------------------

             Summary: @Lazy transform should check for explicit getters/setters
                 Key: GROOVY-10004
                 URL: https://issues.apache.org/jira/browse/GROOVY-10004
             Project: Groovy
          Issue Type: Improvement
            Reporter: Paul King
            Assignee: Paul King


The {{@Lazy}} transform renames the backing field to "make it more hidden" and 
doesn't provide a setter, hence making the field read-only (apart from 
reflection tricks).
{code}
class Zoo {
    @Lazy String animal = { 'sloth' }()
    //void setAnimal(String animal) { this.animal = animal }
    //String getAnimal() { this.animal }
}
{code}
Here {{animal}} becomes {{$animal}}. The intention is to disallow the fields 
use anymore apart from the sanctioned initialization code provided by the 
transform. No attempt is made to rename usages of the field that may otherwise 
occur within the class. Hence adding an explicit getter or setter in the normal 
way yields a {{StackOverflowError}} when trying to access the original property 
or {{MissingFieldException}} if trying to access the field directly, i.e. 
{{this.@animal}}. The transform should instead issue an error if explicit 
getters/setters are found. It would still be possible to access the {{$animal}} 
field (which in general may or may not be initialized) if there was really a 
need, just not in the standard getter or setter.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to