<commit_before>#!/usr/bin/groovy

@Grab('org.eclipse.text:org.eclipse.text:3.5.101')
@Grab('org.eclipse.tycho:org.eclipse.jdt.core:3.10.0.v20140604-1726')
@Grab('org.eclipse.birt.runtime:org.eclipse.core.resources:3.9.0.v20140514-1307')


import org.eclipse.jdt.core.formatter.CodeFormatter
import org.eclipse.jdt.core.ToolFactory
import org.eclipse.jface.text.Document
import groovy.io.FileType


def settings =  new XmlSlurper().parse('codestyle.xml')
def options = settings[0].children[0].children.collectEntries { [it.attributes.id, it.attributes.value] }
def codeFormatter = ToolFactory.createCodeFormatter(options);

new File("src").eachFileRecurse(FileType.FILES) {
	if (it.name =~ /^[^.]*\.java$/) {
		def source = it.getText("utf-8")
		def edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, '\n')
		def document = new Document(source);
		edit.apply(document)
		def formattedSource = document.get()
		if (formattedSource != source) {
			System.err.println("${it} is incorrectly formatted")
			System.exit(1)
		}<commit_msg>Add line to write newly formatted file<commit_after>#!/usr/bin/groovy

@Grab('org.eclipse.text:org.eclipse.text:3.5.101')
@Grab('org.eclipse.tycho:org.eclipse.jdt.core:3.10.0.v20140604-1726')
@Grab('org.eclipse.birt.runtime:org.eclipse.core.resources:3.9.0.v20140514-1307')


import org.eclipse.jdt.core.formatter.CodeFormatter
import org.eclipse.jdt.core.ToolFactory
import org.eclipse.jface.text.Document
import groovy.io.FileType


def settings =  new XmlSlurper().parse('codestyle.xml')
def options = settings[0].children[0].children.collectEntries { [it.attributes.id, it.attributes.value] }
def codeFormatter = ToolFactory.createCodeFormatter(options);

new File("src").eachFileRecurse(FileType.FILES) {
	if (it.name =~ /^[^.]*\.java$/) {
		def source = it.getText("utf-8")
		def edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, '\n')
		def document = new Document(source);
		edit.apply(document)
		def formattedSource = document.get()
		if (formattedSource != source) {
			//new File(it.toString()).withWriter { it.write(document.get()) }
			System.err.println("${it} is incorrectly formatted")
			System.exit(1)
		}
{'fraction_non_alphanumeric': 0.16607142857142856, 'fraction_numerical': 0.0375, 'mean_word_length': 5.207756232686981, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6458703', 'n_tokens_mistral': 868, 'n_tokens_neox': 771, 'n_words': 121}