Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
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
- links to