<commit_before>package org.springframework.roo.classpath.itd;

import org.springframework.roo.classpath.details.InvocableMemberMetadata;
import org.springframework.roo.support.util.Assert;

/**
 * A simple way of producing method bodies for {@link InvocableMemberMetadata#getBody()}.
 * 
 * <p>
 * Method bodies immediately assume they are indented two levels.
 * 
 * @author <NAME>
 * @since 1.0
 *
 */
public class InvocableMemberBodyBuilder {
	
	private int indentLevel = 0;
	
	private StringBuilder stringBuilder = new StringBuilder();

	public InvocableMemberBodyBuilder() {
		indentLevel++;
		indentLevel++;
	}

	/**
	 * Increases the indent by one level.
	 */
	public InvocableMemberBodyBuilder indent() {
		indentLevel++;
		return this;
	}
	
	/**
	 * Resets the indent to zero.
	 */
	public InvocableMemberBodyBuilder reset() {
		indentLevel = 0;
		return this;
	}

	/**
	 * Decreases the indent by one level.
	 */
	public InvocableMemberBodyBuilder indentRemove() {
		indentLevel--;
		return this;
	}

	/**
	 * Prints a blank line, ensuring any indent is included before doing so.
	 */
	public InvocableMemberBodyBuilder newLine(boolean indentBefore) {
		if (indentBefore) {
			appendIndent();
		}
        // We use \n for consistency with JavaParser's DumpVisitor, which always uses \n
		stringBuilder.append("\n");
		//pw.append(System.getProperty("line.separator"));
		return this;
	}
	
	public InvocableMemberBodyBuilder newLine() {
		newLine(true);
		return this;
	}
	
	/**
	 * Prints the message, WITHOUT ANY INDENTATION.
	 */
	public InvocableMemberBodyBuilder append(String message) {
		if (message != null && !"".equals(message)) {
			stringBuilder.append(message);
		}
		return this;
	}

	/**
	 * Prints the message, after adding indents and returns to a new line. This is the most commonly used method.
	 */
	public InvocableMemberBodyBuilder appendFormalLine(String message) {
		appendIndent();
		if (message != null && !"".equals(message)) {
			stringBuilder.append(message);
		}
		return newLine(false);
	}

	/**
	 * Prints the relevant number of indents.
	 */
	public InvocableMemberBodyBuilder appendIndent() {
		for (int i = 0 ; i < indentLevel; i++) {
			stringBuilder.append("    ");
		}
		return this;
	}
	
	public String getOutput() {
		Assert.isTrue(this.indentLevel == 2, "Indent level must be 2 (not " + indentLevel + ") to terminate!");
		return stringBuilder.toString();
	}

}<commit_msg>ROO-777: Make InvocableMemberBodyBuilder more useful for .java source file emission<commit_after>package org.springframework.roo.classpath.itd;

import org.springframework.roo.classpath.details.InvocableMemberMetadata;
import org.springframework.roo.support.util.Assert;

/**
 * A simple way of producing method bodies for {@link InvocableMemberMetadata#getBody()}.
 * 
 * <p>
 * Method bodies immediately assume they are indented two levels.
 * 
 * @author <NAME>
 * @since 1.0
 *
 */
public class InvocableMemberBodyBuilder {
	
	private boolean reset = false;
	
	private int indentLevel = 0;
	
	private StringBuilder stringBuilder = new StringBuilder();

	public InvocableMemberBodyBuilder() {
		indentLevel++;
		indentLevel++;
	}

	/**
	 * Increases the indent by one level.
	 */
	public InvocableMemberBodyBuilder indent() {
		indentLevel++;
		return this;
	}
	
	/**
	 * Resets the indent to zero.
	 */
	public InvocableMemberBodyBuilder reset() {
		indentLevel = 0;
		reset = true;
		return this;
	}

	/**
	 * Decreases the indent by one level.
	 */
	public InvocableMemberBodyBuilder indentRemove() {
		indentLevel--;
		return this;
	}

	/**
	 * Prints a blank line, ensuring any indent is included before doing so.
	 */
	public InvocableMemberBodyBuilder newLine(boolean indentBefore) {
		if (indentBefore) {
			appendIndent();
		}
        // We use \n for consistency with JavaParser's DumpVisitor, which always uses \n
		stringBuilder.append("\n");
		//pw.append(System.getProperty("line.separator"));
		return this;
	}
	
	public InvocableMemberBodyBuilder newLine() {
		newLine(true);
		return this;
	}
	
	/**
	 * Prints the message, WITHOUT ANY INDENTATION.
	 */
	public InvocableMemberBodyBuilder append(String message) {
		if (message != null && !"".equals(message)) {
			stringBuilder.append(message);
		}
		return this;
	}

	/**
	 * Prints the message, after adding indents and returns to a new line. This is the most commonly used method.
	 */
	public InvocableMemberBodyBuilder appendFormalLine(String message) {
		appendIndent();
		if (message != null && !"".equals(message)) {
			stringBuilder.append(message);
		}
		return newLine(false);
	}

	/**
	 * Prints the relevant number of indents.
	 */
	public InvocableMemberBodyBuilder appendIndent() {
		for (int i = 0 ; i < indentLevel; i++) {
			stringBuilder.append("    ");
		}
		return this;
	}
	
	public String getOutput() {
		if (reset) {
			Assert.isTrue(this.indentLevel == 0, "Indent level must be 0 (not " + indentLevel + ") to terminate following a reset!");
		} else {
			Assert.isTrue(this.indentLevel == 2, "Indent level must be 2 (not " + indentLevel + ") to terminate (use reset to indent to level 0)!");
		}
		return stringBuilder.toString();
	}

}
{'fraction_non_alphanumeric': 0.11639185257032007, 'fraction_numerical': 0.0038797284190106693, 'mean_word_length': 3.7216117216117217, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4674805', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1529, 'n_words': 451}