Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8002

Static compilation drops source position for method calls

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.8, 3.0.0-beta-3
    • Component/s: None
    • Labels:
      None

      Description

      @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:

              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;
              }
      

      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:

          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());
              }
          }
      

        Attachments

          Activity

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              emilles Eric Milles

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 50m
                50m

                  Issue deployment