You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2016/11/18 21:41:58 UTC

[jira] [Created] (GROOVY-8002) Static compilation drops source position for method calls

Eric Milles created GROOVY-8002:
-----------------------------------

             Summary: Static compilation drops source position for method calls
                 Key: GROOVY-8002
                 URL: https://issues.apache.org/jira/browse/GROOVY-8002
             Project: Groovy
          Issue Type: Bug
            Reporter: Eric Milles
            Priority: Minor


@CompileStatic is dropping source position for method calls in a couple cases.  There are several circumstances where a MethodCallExpression is created using the 1st constructor of MCE, which creates a ConstantExpression for the method with no position.  And later when org.codehaus.groovy.classgen.asm.sc.StaticPropertyAccessHelper.PoppingMethodCallExpression.transformExpression(ExpressionTransformer) is called, the transformed expression has lost position info.

The latter is pretty easy.  See the one line addition below:
{java}
        public Expression transformExpression(final ExpressionTransformer transformer) {
            PoppingMethodCallExpression trn = new PoppingMethodCallExpression(receiver.transformExpression(transformer), setter, (TemporaryVariableExpression) tmp.transformExpression(transformer));
            trn.copyNodeMetaData(this);
            // GRECLIPSE add
            trn.setSourcePosition(this);
            // GRECLIPSE end
            trn.setImplicitThis(isImplicitThis());
            trn.setSafe(isSafe());
            trn.setSpreadSafe(isSpreadSafe());
            return trn;
        }
{/java}

MethodCallExpression could use an override of setSourcePosition to try and propagate some info to method and arguments expressions.  Here is what I came up with:
{java}
    public void setSourcePosition(ASTNode node) {
        super.setSourcePosition(node);
        if (node instanceof MethodCall) {
            if (node instanceof MethodCallExpression) {
                method.setSourcePosition(((MethodCallExpression) node).getMethod());
            } else {
                method.setSourcePosition(node);
                method.setEnd(method.getStart() + getMethodAsString().length());
            }
            if (arguments != null) {
                arguments.setSourcePosition(((MethodCall) node).getArguments());
            }
        } else if (node instanceof PropertyExpression) {
            method.setSourcePosition(((PropertyExpression) node).getProperty());
        }
    }
{/java}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)