<commit_before>package org.codehaus.groovy.tools

import java.io.File

import com.thoughtworks.qdox.JavaDocBuilder
import com.thoughtworks.qdox.model.JavaSource
import com.thoughtworks.qdox.model.JavaClass
import com.thoughtworks.qdox.model.JavaMethod
import com.thoughtworks.qdox.model.JavaParameter
import com.thoughtworks.qdox.model.Type

/**
 * Generate documentation about the methods provided by the Groovy Development Kit
 * enhancing the standard JDK classes.
 *
 * @author <NAME>
 */
class DocGenerator
{
	File           file
	File           outputFile
	JavaDocBuilder builder

	DocGenerator(File fileToParse, File outputFile)
	{
		this.file       = fileToParse
		this.outputFile = outputFile
	}

	/**
	 * Parse the DefaultGroovyMethods class to build a graph representing the structure of the class,
	 * with its methods, javadoc comments and tags.
	 */
	private void parse()
	{
		reader  = file.newReader()
		builder = new JavaDocBuilder()

		builder.addSource(reader)
	}

	/**
	 * Builds an HTML page from the structure of DefaultGroovyMethods.
	 */
	void generate()
	{
		parse()

		sources = builder.getSources()
		firstSource = sources[0]
		classes = firstSource.getClasses()
		groovyMeth = classes[0]

		// categorize all groovy methods per core JDK class to which it applies
		jdkEnhancedClasses = [:]
		methods = groovyMeth.getMethods()
		for (method in methods)
		{
			if (method.isPublic() && method.isStatic())
			{
				parameters = method.getParameters()
				jdkClass = parameters[0].type.toString()
				if (jdkEnhancedClasses.containsKey(jdkClass))
					jdkEnhancedClasses[jdkClass].add(method)
				else
					jdkEnhancedClasses[jdkClass] = [method]
			}
		}

		writer = outputFile.newPrintWriter()
		writer.withWriter{writer |
			writer.println("<html>")
			writer.println(" <head>")
			writer.println("  <title>GDK : Groovy methods</title>")
			writer.println(' <style type="text/css">')
			writer.println('   @import url("./style/maven-base.css");')
			writer.println(' </style>')
			writer.println(' <style type="text/css">')
			writer.println('   @import url("http://codehaus.org/codehaus-style.css");')
			writer.println(' </style>')
			//writer.println(" <style>")
			//writer.println("   body, h1, h2, h3, p, div, span { font-family: sans-serif; font-size: 10pt }")
			//writer.println("   h1 { padding: 6px; font-size: 24pt; color: #008800; font-weight: bold; font-size: 24pt}")
			//writer.println("   h2 { padding: 4px; font-size: 14pt; color: #008800; padding: 4px; border: 1px solid #aaaaaa; font-size: larger; background-color: #eeeeee;}")
			//writer.println("   h3 { margin: 10px }")
			//writer.println("   p { margin: 20px }")
			//writer.println(" </style>")
			writer.println(" </head>")
			writer.println(" <body>")
			writer.println(" <h1>Groovy JDK methods</h1>")
			writer.println(" <p>New methods added to the JDK to make it more groovy.</p>")

			writer2 = writer
            sb = new StringBuffer()
            counter = 0

			// lets iterate in sorted class name order
			sortedClasses = [] + jdkEnhancedClasses.keySet()
			for (className in sortedClasses.sort()) {

				sb.append("<h2>${getObjectType(className)}</h2>")
				writer2.println("<ul><b>${className}</b>")

				listOfMethods = jdkEnhancedClasses[className]

				for (meth in listOfMethods) {
                    counter++
                    anchor = "meth${counter}"
                    writer2.println("<li><a href='#${anchor}'>${getReturnType(meth)} ${meth.getName()}(${getParametersDecl(meth)})</a></li>")

                    sb.append("  <a name='${anchor}'></a>")
				    sb.append("  <p><b>${getReturnType(meth)} ${meth.getName()}(${getParametersDecl(meth)})</b></p>")
					sb.append("  <ul>${getComment(meth)}")
					sb.append("  ${getParametersReturnAndEx(meth)}</ul></p>")
				}
				writer2.println("</ul>")
			}
            writer.println(sb.toString())

			writer.println(" </body>")
			writer.println("</html>")
		}
	}

	/**
	 * Retrives a String representing the return type of the method passed as parameter.
	 *
	 * @param method a method
	 * @return the return type of the method
	 */<commit_msg>updated the document generator to use a tabular layout for the index and to sort methods<commit_after>package org.codehaus.groovy.tools

import java.io.File

import com.thoughtworks.qdox.JavaDocBuilder
import com.thoughtworks.qdox.model.JavaSource
import com.thoughtworks.qdox.model.JavaClass
import com.thoughtworks.qdox.model.JavaMethod
import com.thoughtworks.qdox.model.JavaParameter
import com.thoughtworks.qdox.model.Type

/**
 * Generate documentation about the methods provided by the Groovy Development Kit
 * enhancing the standard JDK classes.
 *
 * @author <NAME>
 */
class DocGenerator
{
	File           file
	File           outputFile
	JavaDocBuilder builder

	DocGenerator(File fileToParse, File outputFile)
	{
		this.file       = fileToParse
		this.outputFile = outputFile
	}

	/**
	 * Parse the DefaultGroovyMethods class to build a graph representing the structure of the class,
	 * with its methods, javadoc comments and tags.
	 */
	private void parse()
	{
		reader  = file.newReader()
		builder = new JavaDocBuilder()

		builder.addSource(reader)
	}

	/**
	 * Builds an HTML page from the structure of DefaultGroovyMethods.
	 */
	void generate()
	{
		parse()

		sources = builder.getSources()
		firstSource = sources[0]
		classes = firstSource.getClasses()
		groovyMeth = classes[0]

		// categorize all groovy methods per core JDK class to which it applies
		jdkEnhancedClasses = [:]
		methods = groovyMeth.getMethods()
		for (method in methods)
		{
			if (method.isPublic() && method.isStatic())
			{
				parameters = method.getParameters()
				jdkClass = parameters[0].type.toString()
				if (jdkEnhancedClasses.containsKey(jdkClass))
					jdkEnhancedClasses[jdkClass].add(method)
				else
					jdkEnhancedClasses[jdkClass] = [method]
			}
		}

		writer = outputFile.newPrintWriter()
		writer.withWriter{writer |
			writer.println("<html>")
			writer.println(" <head>")
			writer.println("  <title>GDK : Groovy methods</title>")
			writer.println(' <style type="text/css">')
			writer.println('   @import url("./style/maven-base.css");')
			writer.println(' </style>')
			writer.println(' <style type="text/css">')
			writer.println('   @import url("http://codehaus.org/codehaus-style.css");')
			writer.println(' </style>')
			//writer.println(" <style>")
			//writer.println("   body, h1, h2, h3, p, div, span { font-family: sans-serif; font-size: 10pt }")
			//writer.println("   h1 { padding: 6px; font-size: 24pt; color: #008800; font-weight: bold; font-size: 24pt}")
			//writer.println("   h2 { padding: 4px; font-size: 14pt; color: #008800; padding: 4px; border: 1px solid #aaaaaa; font-size: larger; background-color: #eeeeee;}")
			//writer.println("   h3 { margin: 10px }")
			//writer.println("   p { margin: 20px }")
			//writer.println(" </style>")
			writer.println(" </head>")
			writer.println(" <body>")
			writer.println(" <h1>Groovy JDK methods</h1>")
			writer.println(" <p>New methods added to the JDK to make it more groovy.</p>")

			writer2 = writer
            sb = new StringBuffer()
            counter = 0

			// lets iterate in sorted class name order
			sortedClasses = [] + jdkEnhancedClasses.keySet()
			for (className in sortedClasses.sort()) {

				sb.append("<h2>${getObjectType(className)}</h2>")
				writer2.println("<b>${className}</b>")

				listOfMethods = jdkEnhancedClasses[className]
				listOfMethods.sort { it.name }
				
				writer2.println("<table>")
				for (meth in listOfMethods) {
                    counter++
                    anchor = "meth${counter}"
                    writer2.println("<tr><td>${getReturnType(meth)}</td> <td><a href='#${anchor}'>${meth.getName()}(${getParametersDecl(meth)})</a></td></tr>")

                    sb.append("  <a name='${anchor}'></a>")
				    sb.append("  <p><b>${getReturnType(meth)} ${meth.getName()}(${getParametersDecl(meth)})</b></p>")
					sb.append("  <ul>${getComment(meth)}")
					sb.append("  ${getParametersReturnAndEx(meth)}</ul></p>")
				}
				writer2.println("</table>")
			}
            writer.println(sb.toString())

			writer.println(" </body>")
			writer.println("</html>")
		}
	}

	/**
	 * Retrives a String representing the return type of the method passed as parameter.
	 *
	 * @param method a method
	 * @return the return type of the method
	 */
{'fraction_non_alphanumeric': 0.15299572039942938, 'fraction_numerical': 0.011055634807417974, 'mean_word_length': 3.3726611226611225, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5213211', 'n_tokens_mistral': 3080, 'n_tokens_neox': 2659, 'n_words': 628}