From c34f817a668633dd484c8c560e09b54dfca8bf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Br=C3=BCnings?= Date: Fri, 18 Oct 2024 18:08:48 +0200 Subject: [PATCH] Apply review comments --- .../spockframework/compiler/SpecRewriter.java | 18 +++++++----------- .../spockframework/compiler/SpockNames.java | 5 ++++- .../runtime/model/IErrorContext.java | 2 ++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/spock-core/src/main/java/org/spockframework/compiler/SpecRewriter.java b/spock-core/src/main/java/org/spockframework/compiler/SpecRewriter.java index 893c83e41a..bb877578e2 100644 --- a/spock-core/src/main/java/org/spockframework/compiler/SpecRewriter.java +++ b/spock-core/src/main/java/org/spockframework/compiler/SpecRewriter.java @@ -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; @@ -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(), @@ -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); @@ -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) { @@ -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 ); @@ -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 featureStats = new ArrayList<>(); @@ -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( @@ -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); diff --git a/spock-core/src/main/java/org/spockframework/compiler/SpockNames.java b/spock-core/src/main/java/org/spockframework/compiler/SpockNames.java index 4eadf163ba..5353720184 100644 --- a/spock-core/src/main/java/org/spockframework/compiler/SpockNames.java +++ b/spock-core/src/main/java/org/spockframework/compiler/SpockNames.java @@ -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"; } diff --git a/spock-core/src/main/java/org/spockframework/runtime/model/IErrorContext.java b/spock-core/src/main/java/org/spockframework/runtime/model/IErrorContext.java index 7e11bbd882..8e38d1fd5c 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/model/IErrorContext.java +++ b/spock-core/src/main/java/org/spockframework/runtime/model/IErrorContext.java @@ -1,5 +1,6 @@ package org.spockframework.runtime.model; +import org.spockframework.util.Beta; import org.spockframework.util.Nullable; /** @@ -9,6 +10,7 @@ * * @since 2.4 */ +@Beta public interface IErrorContext { @Nullable SpecInfo getCurrentSpec();