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

Static compilation drops source position for method calls

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.5.8, 3.0.0-beta-3
    • None
    • 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

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

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