<commit_before>package org.jetbrains.plugins.groovy.dsl

/**
 * @author ilyas
 */

public class GroovyDslExecutor {
  private final List<Closure> myScriptEnhancers = [];
  private final List<Closure> myClassEnhancers = [];

  public GroovyDslExecutor(String text, String fileName) {
    def shell = new GroovyShell()
    def script = shell.parse(text, fileName)

    def mc = new ExpandoMetaClass(script.class, false)


    mc.enhanceScript = {Map args, Closure enh ->
      enh.resolveStrategy = Closure.DELEGATE_FIRST
      myScriptEnhancers << {
        ScriptDescriptor wrapper, GroovyEnhancerConsumer c ->
        if (args.extension == wrapper.extension) {
          runEnhancer enh, new EnhancerDelegate(consumer:c)
        }
      }
    }

    mc.enhanceClass = {Map args, Closure enh ->
      enh.resolveStrategy = Closure.DELEGATE_FIRST
      myClassEnhancers << {
        ClassDescriptor cw, GroovyEnhancerConsumer c ->
        if (!args.className || cw.getQualifiedName() == args.className) {
          runEnhancer enh, new EnhancerDelegate(consumer:c)
        }
      }

    }

    mc.initialize()
    script.metaClass = mc
    try {
      script.run()
    }
    catch (Throwable e) {
      println e
      // Suppress all exceptions!
      // todo provide diagnostics
    }
  }

  def runEnhancer(code, delegate) {
    def copy = code.clone()
    copy.delegate = delegate
    copy()
  }

  def processVariants(ClassDescriptor descriptor, GroovyEnhancerConsumer consumer) {
    for (e in (descriptor instanceof ScriptDescriptor ? myScriptEnhancers : myClassEnhancers)) {
      e(descriptor, consumer)
    }
  }

}

class EnhancerDelegate {
  GroovyEnhancerConsumer consumer

  def property(Map args) {
    consumer.property(args.name, stringifyType(args.type))
  }<commit_msg>groovy-dsl.jar<commit_after>package org.jetbrains.plugins.groovy.dsl

/**
 * @author ilyas
 */

public class GroovyDslExecutor {
  private final List<Closure> myScriptEnhancers = [];
  private final List<Closure> myClassEnhancers = [];
  private final String myFileName;

  public GroovyDslExecutor(String text, String fileName) {
    myFileName = fileName

    def shell = new GroovyShell()
    def script = shell.parse(text, fileName)

    def mc = new ExpandoMetaClass(script.class, false)


    mc.enhanceScript = {Map args, Closure enh ->
      enh.resolveStrategy = Closure.DELEGATE_FIRST
      myScriptEnhancers << {
        ScriptDescriptor wrapper, GroovyEnhancerConsumer c ->
        if (args.extension == wrapper.extension) {
          runEnhancer enh, new EnhancerDelegate(consumer:c)
        }
      }
    }

    mc.enhanceClass = {Map args, Closure enh ->
      enh.resolveStrategy = Closure.DELEGATE_FIRST
      myClassEnhancers << {
        ClassDescriptor cw, GroovyEnhancerConsumer c ->
        if (!args.className || cw.getQualifiedName() == args.className) {
          runEnhancer enh, new EnhancerDelegate(consumer:c)
        }
      }

    }

    mc.initialize()
    script.metaClass = mc
    try {
      script.run()
    }
    catch (Throwable e) {
      println e
      // Suppress all exceptions!
      // todo provide diagnostics
    }
  }

  def runEnhancer(code, delegate) {
    def copy = code.clone()
    copy.delegate = delegate
    copy()
  }

  def processVariants(ClassDescriptor descriptor, GroovyEnhancerConsumer consumer) {
    for (e in (descriptor instanceof ScriptDescriptor ? myScriptEnhancers : myClassEnhancers)) {
      e(descriptor, consumer)
    }
  }

  def String toString() {
    return "${super.toString()}; file = $myFileName";
  }

}

class EnhancerDelegate {
  GroovyEnhancerConsumer consumer

  def property(Map args) {
    consumer.property(args.name, stringifyType(args.type))
  }
{'fraction_non_alphanumeric': 0.09720730397422127, 'fraction_numerical': 0.0, 'mean_word_length': 2.892371995820272, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '262266', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1126, 'n_words': 255}