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 Sun, 11 Jun 2017 14:08:20 GMT

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

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

GitHub user ArsenBabakhanyan opened a pull request:

    https://github.com/apache/groovy/pull/559

    GROOVY-8222: Setting Source Position in newly created PropertyExpression

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ArsenBabakhanyan/groovy GROOVY-8222

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/559.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #559
    
----
commit 5dcd3aea6710469042b6c7bada86dac28e6d67f8
Author: Arsen Babakhanyan <arsen.ba@gmail.com>
Date:   2017-06-11T14:06:29Z

    GROOVY-8222: Setting Source Position in newly created PropertyExpression

----


> 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.3.15#6346)

Mime
View raw message