Skip to content

Commit 8478ba1

Browse files
committed
Merge branch 'vampire/mixin-spec-internals' into 'vampire/flexible-version-check'
2 parents aeb57e2 + 74371ac commit 8478ba1

File tree

11 files changed

+344
-306
lines changed

11 files changed

+344
-306
lines changed

spock-core/src/main/java/org/spockframework/compiler/AstNodeCache.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class AstNodeCache {
4242
public final ClassNode ErrorRethrower = ClassHelper.makeWithoutCaching(ErrorRethrower.class);
4343
public final ClassNode Specification = ClassHelper.makeWithoutCaching(Specification.class);
4444
public final ClassNode SpecInternals = ClassHelper.makeWithoutCaching(SpecInternals.class);
45+
public final ClassNode SpecialMethodCallTarget = ClassHelper.makeWithoutCaching(SpecialMethodCallTarget.class);
4546
public final ClassNode MockController = ClassHelper.makeWithoutCaching(MockController.class);
4647
public final ClassNode SpecificationContext = ClassHelper.makeWithoutCaching(SpecificationContext.class);
4748
public final ClassNode DataVariableMultiplication = ClassHelper.makeWithoutCaching(DataVariableMultiplication.class);

spock-core/src/main/java/org/spockframework/compiler/DeepBlockRewriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ private boolean handleOldCall(MethodCallExpression expr) {
289289
return true;
290290
}
291291

292+
expr.setObjectExpression(new ClassExpression(resources.getAstNodeCache().SpecialMethodCallTarget));
292293
expr.setMethod(new ConstantExpression(expr.getMethodAsString() + "Impl"));
293294
List<Expression> args = AstUtil.getArgumentList(expr);
294295
if (args.size() != 1) {

spock-core/src/main/java/org/spockframework/compiler/SpecialMethodCall.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ public class SpecialMethodCall implements ISpecialMethodCall {
4545
@Nullable
4646
private final ClosureExpression closureExpr;
4747
private final boolean conditionBlock;
48+
private final AstNodeCache nodeCache;
4849

4950
public SpecialMethodCall(String methodName, Expression inferredName, Expression inferredType,
5051
MethodCallExpression methodCallExpr, @Nullable BinaryExpression binaryExpr,
51-
@Nullable ClosureExpression closureExpr, boolean conditionBlock) {
52+
@Nullable ClosureExpression closureExpr, boolean conditionBlock, AstNodeCache nodeCache) {
5253
this.methodName = methodName;
5354
this.inferredName = inferredName;
5455
this.inferredType = inferredType;
5556
this.binaryExpr = binaryExpr;
5657
this.methodCallExpr = methodCallExpr;
5758
this.closureExpr = closureExpr;
5859
this.conditionBlock = conditionBlock;
60+
this.nodeCache = nodeCache;
5961
}
6062

6163
@Override
@@ -168,13 +170,15 @@ public ClosureExpression getClosureExpr() {
168170
@Override
169171
public void expand() {
170172
List<Expression> args = new ArrayList<>();
173+
args.add(VariableExpression.THIS_EXPRESSION);
171174
args.add(inferredName);
172175
args.add(inferredType);
173176
args.addAll(AstUtil.getArgumentList(methodCallExpr));
174177

175178
ArgumentListExpression argsExpr = new ArgumentListExpression(args);
176179
AstUtil.copySourcePosition(methodCallExpr.getArguments(), argsExpr);
177180
methodCallExpr.setArguments(argsExpr);
181+
methodCallExpr.setObjectExpression(new ClassExpression(nodeCache.SpecialMethodCallTarget));
178182
methodCallExpr.setMethod(new ConstantExpression(methodName + "Impl"));
179183
}
180184

@@ -208,7 +212,7 @@ public static SpecialMethodCall parse(MethodCallExpression methodCallExpr, @Null
208212
}
209213
wrapCastedConstructorArgs(arguments, nodeCache);
210214

211-
return new SpecialMethodCall(methodName, inferredName, inferredType, methodCallExpr, binaryExpr, closureExpr, conditionBlock);
215+
return new SpecialMethodCall(methodName, inferredName, inferredType, methodCallExpr, binaryExpr, closureExpr, conditionBlock, nodeCache);
212216
}
213217

214218
private static void wrapCastedConstructorArgs(List<Expression> arguments, AstNodeCache nodeCache) {

spock-core/src/main/java/org/spockframework/lang/SpecInternals.java

Lines changed: 5 additions & 296 deletions
Large diffs are not rendered by default.

spock-core/src/main/java/org/spockframework/runtime/SpecialMethodCallTarget.java

Lines changed: 323 additions & 0 deletions
Large diffs are not rendered by default.

spock-specs/src/test/groovy/org/spockframework/smoke/StackTraceFiltering.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ thrown(RuntimeException)
302302
WrongExceptionThrownError e = thrown()
303303

304304
stackTraceLooksLike e, """
305-
org.spockframework.lang.SpecInternals|checkExceptionThrown|-
306-
org.spockframework.lang.SpecInternals|thrownImpl|-
307305
apackage.ASpec|a feature|5
308306
"""
309307

spock-specs/src/test/resources/snapshots/org/spockframework/smoke/ast/AstSpec/Primitive_types_are_used_in_AST_transformation-groovy4.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,17 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
173173
POP
174174
L17
175175
LINENUMBER 8 L17
176+
LDC Lorg/spockframework/runtime/SpecialMethodCallTarget;.class
176177
ALOAD 0
177178
ACONST_NULL
178179
ACONST_NULL
179180
LDC Ljava/lang/RuntimeException;.class
180-
INVOKEDYNAMIC invoke(Lapackage/TestSpec;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object; [
181+
INVOKEDYNAMIC invoke(Ljava/lang/Class;Lapackage/TestSpec;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object; [
181182
// handle kind 0x6 : INVOKESTATIC
182183
org/codehaus/groovy/vmplugin/v8/IndyInterface.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;I)Ljava/lang/invoke/CallSite;
183184
// arguments:
184185
"thrownImpl",
185-
2
186+
0
186187
]
187188
POP
188189
ALOAD 0

spock-specs/src/test/resources/snapshots/org/spockframework/smoke/ast/AstSpec/Primitive_types_are_used_in_AST_transformation.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,12 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
160160
ALOAD 1
161161
LDC 2
162162
AALOAD
163+
LDC Lorg/spockframework/runtime/SpecialMethodCallTarget;.class
163164
ALOAD 0
164165
ACONST_NULL
165166
ACONST_NULL
166167
LDC Ljava/lang/RuntimeException;.class
167-
INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callCurrent (Lgroovy/lang/GroovyObject;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; (itf)
168+
INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; (itf)
168169
POP
169170
ALOAD 0
170171
ICONST_2

spock-specs/src/test/resources/snapshots/org/spockframework/smoke/ast/condition/ExceptionConditionsAstSpec/thrown_rewrite_keeps_correct_method_reference.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void $spock_feature_0_0() {
2121
}
2222
org.spockframework.runtime.SpockRuntime.callBlockExited(this, 0)
2323
org.spockframework.runtime.SpockRuntime.callBlockEntered(this, 1)
24-
this.thrownImpl(null, null, java.lang.IllegalStateException)
24+
org.spockframework.runtime.SpecialMethodCallTarget.thrownImpl(this, null, null, java.lang.IllegalStateException)
2525
org.spockframework.runtime.SpockRuntime.callBlockExited(this, 1)
2626
this.getSpecificationContext().getMockController().leaveScope()
2727
}

spock-specs/src/test/resources/snapshots/org/spockframework/smoke/ast/condition/ExceptionConditionsAstSpec/thrown_rewrite_keeps_correct_method_reference_for_multi_assignments.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void $spock_feature_0_0() {
2121
}
2222
org.spockframework.runtime.SpockRuntime.callBlockExited(this, 0)
2323
org.spockframework.runtime.SpockRuntime.callBlockEntered(this, 1)
24-
this.thrownImpl(null, null, java.lang.IllegalStateException)
24+
org.spockframework.runtime.SpecialMethodCallTarget.thrownImpl(this, null, null, java.lang.IllegalStateException)
2525
org.spockframework.runtime.SpockRuntime.callBlockExited(this, 1)
2626
this.getSpecificationContext().getMockController().leaveScope()
2727
}

0 commit comments

Comments
 (0)