Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.spockframework.compiler;

import org.codehaus.groovy.runtime.wrappers.PojoWrapper;
import org.spockframework.lang.SpecInternals;
import org.spockframework.mock.runtime.MockController;
import org.spockframework.runtime.*;
import org.spockframework.runtime.extension.RepeatedExtensionAnnotations;
Expand Down Expand Up @@ -48,8 +47,8 @@ public class AstNodeCache {
public final ClassNode DataVariableMultiplicationFactor = ClassHelper.makeWithoutCaching(DataVariableMultiplicationFactor.class);
public final ClassNode BlockInfo = ClassHelper.makeWithoutCaching(BlockInfo.class);

public final MethodNode SpecInternals_GetSpecificationContext =
SpecInternals.getDeclaredMethods(Identifiers.GET_SPECIFICATION_CONTEXT).get(0);
public final MethodNode Specification_GetSpecificationContext =
Specification.getDeclaredMethods(Identifiers.GET_SPECIFICATION_CONTEXT).get(0);

public final MethodNode SpockRuntime_VerifyCondition =
SpockRuntime.getDeclaredMethods(org.spockframework.runtime.SpockRuntime.VERIFY_CONDITION).get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private boolean handleOldCall(MethodCallExpression expr) {
return true;
}

expr.setObjectExpression(new ClassExpression(resources.getAstNodeCache().SpecInternals));
expr.setMethod(new ConstantExpression(expr.getMethodAsString() + "Impl"));
List<Expression> args = AstUtil.getArgumentList(expr);
if (args.size() != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public VariableExpression captureOldValue(Expression oldValue) {

public MethodCallExpression getSpecificationContext() {
return createDirectMethodCall(VariableExpression.THIS_EXPRESSION,
nodeCache.SpecInternals_GetSpecificationContext, ArgumentListExpression.EMPTY_ARGUMENTS);
nodeCache.Specification_GetSpecificationContext, ArgumentListExpression.EMPTY_ARGUMENTS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ public class SpecialMethodCall implements ISpecialMethodCall {
@Nullable
private final ClosureExpression closureExpr;
private final boolean conditionBlock;
private final AstNodeCache nodeCache;

public SpecialMethodCall(String methodName, Expression inferredName, Expression inferredType,
MethodCallExpression methodCallExpr, @Nullable BinaryExpression binaryExpr,
@Nullable ClosureExpression closureExpr, boolean conditionBlock) {
@Nullable ClosureExpression closureExpr, boolean conditionBlock, AstNodeCache nodeCache) {
this.methodName = methodName;
this.inferredName = inferredName;
this.inferredType = inferredType;
this.binaryExpr = binaryExpr;
this.methodCallExpr = methodCallExpr;
this.closureExpr = closureExpr;
this.conditionBlock = conditionBlock;
this.nodeCache = nodeCache;
}

@Override
Expand Down Expand Up @@ -168,13 +170,15 @@ public ClosureExpression getClosureExpr() {
@Override
public void expand() {
List<Expression> args = new ArrayList<>();
args.add(VariableExpression.THIS_EXPRESSION);
args.add(inferredName);
args.add(inferredType);
args.addAll(AstUtil.getArgumentList(methodCallExpr));

ArgumentListExpression argsExpr = new ArgumentListExpression(args);
AstUtil.copySourcePosition(methodCallExpr.getArguments(), argsExpr);
methodCallExpr.setArguments(argsExpr);
methodCallExpr.setObjectExpression(new ClassExpression(nodeCache.SpecInternals));
methodCallExpr.setMethod(new ConstantExpression(methodName + "Impl"));
}

Expand Down Expand Up @@ -208,7 +212,7 @@ public static SpecialMethodCall parse(MethodCallExpression methodCallExpr, @Null
}
wrapCastedConstructorArgs(arguments, nodeCache);

return new SpecialMethodCall(methodName, inferredName, inferredType, methodCallExpr, binaryExpr, closureExpr, conditionBlock);
return new SpecialMethodCall(methodName, inferredName, inferredType, methodCallExpr, binaryExpr, closureExpr, conditionBlock, nodeCache);
}

private static void wrapCastedConstructorArgs(List<Expression> arguments, AstNodeCache nodeCache) {
Expand Down
351 changes: 0 additions & 351 deletions spock-core/src/main/java/org/spockframework/lang/SpecInternals.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.spockframework.mock;

import org.spockframework.runtime.SpecInternals;
import org.spockframework.runtime.extension.IDefaultValueProviderExtension;
import org.spockframework.util.ReflectionUtil;
import org.spockframework.util.ThreadSafe;
Expand Down Expand Up @@ -160,7 +161,8 @@ private Object createDummy(IMockInvocation invocation) {
Class<?> type = invocation.getMethod().getReturnType();
Type genericType = invocation.getMethod().getExactReturnType();
Specification spec = invocation.getMockObject().getSpecification();
return spec.createMock("dummy", genericType, MockNature.STUB, GroovyObject.class.isAssignableFrom(type) ?
MockImplementation.GROOVY : MockImplementation.JAVA, emptyMap(), null);
return GroovyObject.class.isAssignableFrom(type)
? SpecInternals.GroovyStubImpl(spec, "dummy", genericType)
: SpecInternals.StubImpl(spec, "dummy", genericType);
}
}
Loading