groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8222) AsmClassGenerator does not set source positions on property expressions
Date Sat, 08 Jul 2017 17:40:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16079242#comment-16079242
] 

ASF GitHub Bot commented on GROOVY-8222:
----------------------------------------

Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/559#discussion_r126286728
  
    --- Diff: src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java ---
    @@ -1251,11 +1251,13 @@ private void processClassVariable(String name) {
                 mv.visitInsn(DUP);
     
                 loadThisOrOwner();
    -            mv.visitLdcInsn(name);
    +            mv.visitLdcInsn(expression.getName());
     
                 mv.visitMethodInsn(INVOKESPECIAL, "org/codehaus/groovy/runtime/ScriptReference",
"<init>", "(Lgroovy/lang/Script;Ljava/lang/String;)V", false);
             } else {
    -            PropertyExpression pexp = new PropertyExpression(new VariableExpression("this"),
name);
    +            PropertyExpression pexp = new PropertyExpression(new VariableExpression("this"),
expression.getName());
    --- End diff --
    
    The patch provided in the JIRA creates a new `VariableExpression` (see below), I think
that needs to be done so the source position is not set on the constant `VariableExpress.THIS_EXPRESSION`
via the `getObjectExpression().setSourcePosition(..)` call.
    
    ```java
    PropertyExpression pexp = new PropertyExpression(new VariableExpression("this", ClassHelper.DYNAMIC_TYPE),
name);
    ```


> 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
>
> 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
(v6.4.14#64029)

Mime
View raw message