[ 
https://issues.apache.org/jira/browse/GROOVY-8222?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King closed GROOVY-8222.
-----------------------------

> AsmClassGenerator does not set source positions on property expressions
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-8222
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8222
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Assignee: John Wagenleitner
>            Priority: Major
>             Fix For: 2.4.13
>
>
> AsmClassGenerator.visitVariableExpression and 
> AsmClassGenerator.processClassVariable can create a new PropertyExpression 
> from a VariableExpression and the source position of the original is not 
> transferred.
> Solution is pretty minimal:
> {code} // mid way through visitVariableExpression:
>         if (variable == null) {
>             // GRECLIPSE edit
>             //processClassVariable(variableName);
>             processClassVariable(expression);
>             // GRECLIPSE end
>         } else {
> {code}
> {code}
>     // GRECLIPSE edit
>     //private void processClassVariable(String name) {
>     private void processClassVariable(VariableExpression expression) {
>         String name = expression.getName();
>     // GRECLIPSE end
> {code}
> {code} // end of processClassVariable:
>         } else {
>             // GRECLIPSE edit
>             //PropertyExpression pexp = new 
> PropertyExpression(VariableExpression.THIS_EXPRESSION, name);
>             PropertyExpression pexp = new PropertyExpression(new 
> VariableExpression("this", ClassHelper.DYNAMIC_TYPE), name);
>             pexp.getObjectExpression().setSourcePosition(expression);
>             pexp.getProperty().setSourcePosition(expression);
>             // GRECLIPSE end
>             pexp.setImplicitThis(true);
>             visitPropertyExpression(pexp);
>         }
> {code}
> I found this because I had a {{with}} expression that produced an error that 
> was attributed to line -1.
> {code}
> import com.fasterxml.jackson.annotation.JsonInclude
> import com.fasterxml.jackson.databind.ObjectMapper
> import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule
> import org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean
> @groovy.transform.CompileStatic
> final class CustomObjectMapper extends ObjectMapper
> {
>     CustomObjectMapper()
>     {
>         super(mimicSpring())
>     }
>     private static ObjectMapper mimicSpring()
>     {
>         /* Formerly in SpringDispatcherContext.xml:
>          *  <bean 
> class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
>          *    
> p:modulesToInstall="com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule"
>          *    p:serializationInclusion="NON_NULL" 
> p:failOnUnknownProperties="false"
>          *    p:autoDetectFields="false" p:autoDetectGettersSetters="true">
>          *  </bean>
>          */
>         new Jackson2ObjectMapperFactoryBean().with {
>             modulesToInstall = JsonOrgModule // Joda module is auto-discovered
>             serializationInclusion = JsonInclude.Include.NON_NULL
>             defaultViewInclusion = true // include w/o view tag
>             failOnUnknownProperties = false
>             autoDetectGettersSetters = true
>             autoDetectFields = false
>             afterPropertiesSet()
>             return object // error on this line; this.object is the 
> PropertyExpression that is created by AsmClassGenerator
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to