Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
leonard84 committed Oct 18, 2024
1 parent 4d293b2 commit 8b811ec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ private void addFeatureMetadata(FeatureMethod feature) {
ann.setMember(FeatureMetadata.BLOCKS, blockAnnElems = new ListExpression());

ListExpression paramNames = new ListExpression();
for (Parameter param : feature.getAst().getParameters())
for (Parameter param : feature.getAst().getParameters()) {
paramNames.addExpression(new ConstantExpression(param.getName()));
}
ann.setMember(FeatureMetadata.PARAMETER_NAMES, paramNames);

feature.getAst().addAnnotation(ann);
Expand All @@ -203,12 +204,13 @@ private void addBlockMetadata(Block block, BlockKind kind) {
blockAnn.setMember(BlockMetadata.KIND, new PropertyExpression(
new ClassExpression(nodeCache.BlockKind), kind.name()));
ListExpression textExprs = new ListExpression();
for (String text : block.getDescriptions())
for (String text : block.getDescriptions()) {
textExprs.addExpression(new ConstantExpression(text));
}
blockAnn.setMember(BlockMetadata.TEXTS, textExprs);
int index = blockAnnElems.getExpressions().size();
Assert.that(index == block.getBlockMetaDataIndex(),
() -> kind+" block mismatch of index: " + index + ", block.getBlockMetaDataIndex(): " + block.getBlockMetaDataIndex());
() -> kind + " block mismatch of index: " + index + ", block.getBlockMetaDataIndex(): " + block.getBlockMetaDataIndex());
blockAnnElems.addExpression(new AnnotationConstantExpression(blockAnn));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -430,9 +429,9 @@ private void addBlockListeners(Block block) {
|| blockType == BlockParseInfo.COMBINED
|| blockType == BlockParseInfo.ANONYMOUS) return;

// SpockRuntime.enterBlock(getSpecificationContext(), new BlockInfo(blockKind, [blockTexts]))
// SpockRuntime.enterBlock(getSpecificationContext(), new BlockInfo(blockKind, blockMetaDataIndex))
MethodCallExpression enterBlockCall = createBlockListenerCall(block, blockType, nodeCache.SpockRuntime_CallEnterBlock);
// SpockRuntime.exitedBlock(getSpecificationContext(), new BlockInfo(blockKind, [blockTexts]))
// SpockRuntime.exitedBlock(getSpecificationContext(), new BlockInfo(blockKind, blockMetaDataIndex))
MethodCallExpression exitBlockCall = createBlockListenerCall(block, blockType, nodeCache.SpockRuntime_CallExitBlock);

if (blockType == BlockParseInfo.CLEANUP) {
Expand All @@ -447,7 +446,7 @@ private void addBlockListeners(Block block) {
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));
}
}

Expand Down Expand Up @@ -559,7 +558,7 @@ private Statement createMockControllerCall(MethodNode method) {
public void visitCleanupBlock(CleanupBlock block) {
for (Block b : method.getBlocks()) {
// call addBlockListeners() here, as this method will already copy the contents of the blocks,
// so we need to transform here as they won't be copied again in visitMethodAgain where we normally add them
// so we need to transform the block listeners here as they won't be copied in visitMethodAgain where we normally add them
addBlockListeners(b);
if (b == block) break;
moveVariableDeclarations(b.getAst(), method.getStatements());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public Throwable getException() {
return error;
}

/**
* {@return the error context}
*
* @since 2.4
*/
public IErrorContext getErrorContext() {
return errorContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Provides context information for an error that occurred during the execution of a specification.
* <p>
* Depending on the context in which the error occurred, some of the methods may return {@code null}.
*
* @since 2.4
*/
public interface IErrorContext {
@Nullable
Expand Down

0 comments on commit 8b811ec

Please sign in to comment.