Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leonard84 committed Oct 18, 2024
1 parent 8b811ec commit c34f817
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public class SpecRewriter extends AbstractSpecVisitor implements IRewriteResourc
// https://issues.apache.org/jira/browse/GROOVY-10403
// needed for groovy-4 compatibility and only available since groovy-4
private static final java.lang.reflect.Method GET_PLAIN_NODE_REFERENCE = ReflectionUtil.getMethodBySignature(ClassNode.class, "getPlainNodeReference", boolean.class);
public static final String SPOCK_VALUE = "$spock_value";
public static final String SPOCK_FEATURE_THROWABLE = "$spock_feature_throwable";
public static final String SPOCK_TMP_THROWABLE = "$spock_tmp_throwable";

private final AstNodeCache nodeCache;
private final SourceLookup lookup;
Expand Down Expand Up @@ -167,7 +164,7 @@ private void createFinalFieldGetter(Field field) {

private void createSharedFieldSetter(Field field) {
String setterName = "set" + MetaClassHelper.capitalize(field.getName());
Parameter[] params = new Parameter[] { new Parameter(field.getAst().getType(), SPOCK_VALUE) };
Parameter[] params = new Parameter[] { new Parameter(field.getAst().getType(), SpockNames.SPOCK_VALUE) };
MethodNode setter = spec.getAst().getMethod(setterName, params);
if (setter != null) {
errorReporter.error(field.getAst(),
Expand All @@ -188,7 +185,7 @@ private void createSharedFieldSetter(Field field) {
// use internal name
new ConstantExpression(field.getAst().getName())),
Token.newSymbol(Types.ASSIGN, -1, -1),
new VariableExpression(SPOCK_VALUE))));
new VariableExpression(SpockNames.SPOCK_VALUE))));

setter.setSourcePosition(field.getAst());
spec.getAst().addMethod(setter);
Expand Down Expand Up @@ -443,11 +440,10 @@ private void addBlockListeners(Block block) {
ifThrowableIsNotNull(storeFailedBlock(failedBlock)),
new ExpressionStatement(enterBlockCall)
));
block.getAst().add(new ExpressionStatement(exitBlockCall));
} else {
block.getAst().add(0, new ExpressionStatement(enterBlockCall));
block.getAst().add(new ExpressionStatement(exitBlockCall));
}
block.getAst().add(new ExpressionStatement(exitBlockCall));
}

private @NotNull Statement storeFailedBlock(VariableExpression failedBlock) {
Expand All @@ -462,7 +458,7 @@ private void addBlockListeners(Block block) {
private IfStatement ifThrowableIsNotNull(Statement statement) {
return new IfStatement(
// if ($spock_feature_throwable != null)
new BooleanExpression(AstUtil.createVariableIsNotNullExpression(new VariableExpression(SpecRewriter.SPOCK_FEATURE_THROWABLE, nodeCache.Throwable))),
new BooleanExpression(AstUtil.createVariableIsNotNullExpression(new VariableExpression(SpockNames.SPOCK_FEATURE_THROWABLE, nodeCache.Throwable))),
statement,
EmptyStatement.INSTANCE
);
Expand Down Expand Up @@ -565,7 +561,7 @@ public void visitCleanupBlock(CleanupBlock block) {
}

VariableExpression featureThrowableVar =
new VariableExpression(SPOCK_FEATURE_THROWABLE, nodeCache.Throwable);
new VariableExpression(SpockNames.SPOCK_FEATURE_THROWABLE, nodeCache.Throwable);
method.getStatements().add(createVariableDeclarationStatement(featureThrowableVar));

List<Statement> featureStats = new ArrayList<>();
Expand Down Expand Up @@ -618,7 +614,7 @@ private TryCatchStatement createCleanupTryCatch(CleanupBlock block, VariableExpr
}

private CatchStatement createThrowableAssignmentAndRethrowCatchStatement(VariableExpression assignmentVar) {
Parameter catchParameter = new Parameter(nodeCache.Throwable, SPOCK_TMP_THROWABLE);
Parameter catchParameter = new Parameter(nodeCache.Throwable, SpockNames.SPOCK_TMP_THROWABLE);

BinaryExpression assignThrowableExpr =
new BinaryExpression(
Expand All @@ -635,7 +631,7 @@ private CatchStatement createThrowableAssignmentAndRethrowCatchStatement(Variabl
}

private CatchStatement createHandleSuppressedThrowableStatement(VariableExpression featureThrowableVar) {
Parameter catchParameter = new Parameter(nodeCache.Throwable, SPOCK_TMP_THROWABLE);
Parameter catchParameter = new Parameter(nodeCache.Throwable, SpockNames.SPOCK_TMP_THROWABLE);

BinaryExpression featureThrowableNotNullExpr = AstUtil.createVariableIsNotNullExpression(featureThrowableVar);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.spockframework.compiler;

public class SpockNames {
public static final String VALUE_RECORDER = "$spock_valueRecorder";
public static final String ERROR_COLLECTOR = "$spock_errorCollector";
public static final String FAILED_BLOCK = "$spock_failedBlock";
public static final String OLD_VALUE = "$spock_oldValue";
public static final String SPOCK_EX = "$spock_ex";
public static final String SPOCK_FEATURE_THROWABLE = "$spock_feature_throwable";
public static final String SPOCK_TMP_THROWABLE = "$spock_tmp_throwable";
public static final String SPOCK_VALUE = "$spock_value";
public static final String VALUE_RECORDER = "$spock_valueRecorder";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.spockframework.runtime.model;

import org.spockframework.util.Beta;
import org.spockframework.util.Nullable;

/**
Expand All @@ -9,6 +10,7 @@
*
* @since 2.4
*/
@Beta
public interface IErrorContext {
@Nullable
SpecInfo getCurrentSpec();
Expand Down

0 comments on commit c34f817

Please sign in to comment.