<commit_before>/*
 * Copyright 2003-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package groovy.inspect.swingui

import groovy.inspect.swingui.TreeNodeWithProperties
import groovy.text.GStringTemplateEngine
import groovy.text.Template
import java.util.concurrent.atomic.AtomicBoolean
import javax.swing.tree.DefaultMutableTreeNode
import javax.swing.tree.TreeNode
import org.codehaus.groovy.GroovyBugError
import org.codehaus.groovy.classgen.BytecodeExpression
import org.codehaus.groovy.classgen.GeneratorContext
import org.codehaus.groovy.control.CompilationUnit
import org.codehaus.groovy.control.CompilationUnit.PrimaryClassNodeOperation
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.ast.*
import org.codehaus.groovy.ast.expr.*
import org.codehaus.groovy.ast.stmt.*
import org.codehaus.groovy.control.CompilationFailedException

/**
 * This class controls the conversion from a Groovy script as a String into
 * a Swing JTree representation of the AST in that script. The script itself
 * will be a TreeNode, and each class in the script will be a tree node. The
 * conversion creates tree nodes for any concrete class found within an AST
 * visitor. So, if a TreeNode should be shown once for each ASTNode and the parent
 * types will not appear as nodes. Custom subclasses of expression types will
 * not appear in the tree.
 *
 * The String label of a TreeNode is defined by classname in AstBrowserProperties.properties.
 *
 * @author <NAME> 
 */
class ScriptToTreeNodeAdapter {

    def static Properties classNameToStringForm

    static {
        URL url =  ClassLoader.getSystemResource("groovy/inspect/swingui/AstBrowserProperties.groovy");

        def config = new ConfigSlurper().parse(url)
        classNameToStringForm = config.toProperties()

        String home = System.getProperty("user.home")
        if (home) {
            File userFile = new File(home + File.separator + ".groovy/AstBrowserProperties.groovy")
            if (userFile.exists()) {
                def customConfig = new ConfigSlurper().parse(userFile.toURL())
                // layer custom string forms onto defaults with putAll, do not replace them
                classNameToStringForm.putAll(customConfig.toProperties())
            }
        }
    }

    /**
    * Performs the conversion from script to TreeNode.
     *
     * @param script
     *      a Groovy script in String form
     * @param compilePhase
     *      the int based CompilePhase to compile it to.
    */<commit_msg>Removed semicolon in order to trigger a new build. I think last failure has nothing to do with my checkin. Lost my TeamCity password<commit_after>/*
 * Copyright 2003-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package groovy.inspect.swingui

import groovy.inspect.swingui.TreeNodeWithProperties
import groovy.text.GStringTemplateEngine
import groovy.text.Template
import java.util.concurrent.atomic.AtomicBoolean
import javax.swing.tree.DefaultMutableTreeNode
import javax.swing.tree.TreeNode
import org.codehaus.groovy.GroovyBugError
import org.codehaus.groovy.classgen.BytecodeExpression
import org.codehaus.groovy.classgen.GeneratorContext
import org.codehaus.groovy.control.CompilationUnit
import org.codehaus.groovy.control.CompilationUnit.PrimaryClassNodeOperation
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.ast.*
import org.codehaus.groovy.ast.expr.*
import org.codehaus.groovy.ast.stmt.*
import org.codehaus.groovy.control.CompilationFailedException

/**
 * This class controls the conversion from a Groovy script as a String into
 * a Swing JTree representation of the AST in that script. The script itself
 * will be a TreeNode, and each class in the script will be a tree node. The
 * conversion creates tree nodes for any concrete class found within an AST
 * visitor. So, if a TreeNode should be shown once for each ASTNode and the parent
 * types will not appear as nodes. Custom subclasses of expression types will
 * not appear in the tree.
 *
 * The String label of a TreeNode is defined by classname in AstBrowserProperties.properties.
 *
 * @author <NAME> 
 */
class ScriptToTreeNodeAdapter {

    def static Properties classNameToStringForm

    static {
        URL url =  ClassLoader.getSystemResource("groovy/inspect/swingui/AstBrowserProperties.groovy")

        def config = new ConfigSlurper().parse(url)
        classNameToStringForm = config.toProperties()

        String home = System.getProperty("user.home")
        if (home) {
            File userFile = new File(home + File.separator + ".groovy/AstBrowserProperties.groovy")
            if (userFile.exists()) {
                def customConfig = new ConfigSlurper().parse(userFile.toURL())
                // layer custom string forms onto defaults with putAll, do not replace them
                classNameToStringForm.putAll(customConfig.toProperties())
            }
        }
    }

    /**
    * Performs the conversion from script to TreeNode.
     *
     * @param script
     *      a Groovy script in String form
     * @param compilePhase
     *      the int based CompilePhase to compile it to.
    */
{'fraction_non_alphanumeric': 0.07181018227529855, 'fraction_numerical': 0.003771213073538655, 'mean_word_length': 3.5399429386590584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1462039', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1638, 'n_words': 609}