From 3c8b712aa288459462554b4f55e3b04d3e29b702 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 18 Apr 2017 12:06:09 +0200 Subject: [PATCH] Made BlockBuilder public it's a useful class that can be used by different test generators fixes #254 --- .../verifier/builder/BlockBuilder.groovy | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/BlockBuilder.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/BlockBuilder.groovy index de3f392561..2f2ef6da5c 100644 --- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/BlockBuilder.groovy +++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/BlockBuilder.groovy @@ -27,7 +27,6 @@ import groovy.transform.PackageScope * * @since 1.0.0 */ -@PackageScope @CompileStatic class BlockBuilder { @@ -43,21 +42,33 @@ class BlockBuilder { builder = new StringBuilder() } + /** + * Adds indents to start a new block + */ BlockBuilder startBlock() { indents++ return this } + /** + * Ends block by removing indents + */ BlockBuilder endBlock() { indents-- return this } + /** + * Creates a block and adds indents + */ BlockBuilder indent() { startBlock().startBlock() return this } + /** + * Removes indents and closes the block + */ BlockBuilder unindent() { endBlock().endBlock() return this @@ -81,6 +92,7 @@ class BlockBuilder { } } + @PackageScope BlockBuilder addBlock(MethodBuilder methodBuilder) { startBlock() methodBuilder.appendTo(this) @@ -89,6 +101,11 @@ class BlockBuilder { return this } + /** + * Adds the given text at the end of the line + * + * @return updated BlockBuilder + */ BlockBuilder addAtTheEnd(String toAdd) { String lastChar = builder.charAt(builder.length() - 1) as String String secondLastChar = builder.length() >= 2 ? builder.charAt(builder.length() - 2) as String : "" @@ -114,6 +131,12 @@ class BlockBuilder { return character == "{" || character == toAdd } + /** + * Updates the current text with the provided one + * + * @param contents - text to replace the current content with + * @return updated Block Builder + */ BlockBuilder updateContents(String contents) { this.builder.replace(0, this.builder.length(), contents) return this