groovy.lang.GroovyClassLoader.createCollector()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中groovy.lang.GroovyClassLoader.createCollector()方法的一些代码示例,展示了GroovyClassLoader.createCollector()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroovyClassLoader.createCollector()方法的具体详情如下:
包路径:groovy.lang.GroovyClassLoader
类名称:GroovyClassLoader
方法名:createCollector

GroovyClassLoader.createCollector介绍

[英]creates a ClassCollector for a new compilation.
[中]为新编译创建类收集器。

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * Loads the given class node returning the implementation Class.
 * <p>
 * WARNING: this compilation is not synchronized
 *
 * @param classNode
 * @return a class
 */
public Class defineClass(ClassNode classNode, String file, String newCodeBase) {
  CodeSource codeSource = null;
  try {
    codeSource = new CodeSource(new URL("file", "", newCodeBase), (java.security.cert.Certificate[]) null);
  } catch (MalformedURLException e) {
    //swallow
  }
  CompilationUnit unit = createCompilationUnit(config, codeSource);
  ClassCollector collector = createCollector(unit, classNode.getModule().getContext());
  try {
    unit.addClassNode(classNode);
    unit.setClassgenCallback(collector);
    unit.compile(Phases.CLASS_GENERATION);
    definePackageInternal(collector.generatedClass.getName());
    return collector.generatedClass;
  } catch (CompilationFailedException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy

ClassCollector collector = createCollector(unit, su);
unit.setClassgenCallback(collector);
int goalPhase = Phases.CLASS_GENERATION;

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

/**
 * Loads the given class node returning the implementation Class.
 * <p/>
 * WARNING: this compilation is not synchronized
 *
 * @param classNode
 * @return a class
 */
public Class defineClass(ClassNode classNode, String file, String newCodeBase) {
  CodeSource codeSource = null;
  try {
    codeSource = new CodeSource(new URL("file", "", newCodeBase), (java.security.cert.Certificate[]) null);
  } catch (MalformedURLException e) {
    //swallow
  }
  CompilationUnit unit = createCompilationUnit(config, codeSource);
  ClassCollector collector = createCollector(unit, classNode.getModule().getContext());
  try {
    unit.addClassNode(classNode);
    unit.setClassgenCallback(collector);
    unit.compile(Phases.CLASS_GENERATION);
    definePackage(collector.generatedClass.getName());
    return collector.generatedClass;
  } catch (CompilationFailedException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.kohsuke.droovy/groovy

/**
 * Loads the given class node returning the implementation Class.
 * <p/>
 * WARNING: this compilation is not synchronized
 *
 * @param classNode
 * @return a class
 */
public Class defineClass(ClassNode classNode, String file, String newCodeBase) {
  CodeSource codeSource = null;
  try {
    codeSource = new CodeSource(new URL("file", "", newCodeBase), (java.security.cert.Certificate[]) null);
  } catch (MalformedURLException e) {
    //swallow
  }
  CompilationUnit unit = createCompilationUnit(config, codeSource);
  ClassCollector collector = createCollector(unit, classNode.getModule().getContext());
  try {
    unit.addClassNode(classNode);
    unit.setClassgenCallback(collector);
    unit.compile(Phases.CLASS_GENERATION);
    return collector.generatedClass;
  } catch (CompilationFailedException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

/**
 * Loads the given class node returning the implementation Class.
 * <p/>
 * WARNING: this compilation is not synchronized
 *
 * @param classNode
 * @return a class
 */
public Class defineClass(ClassNode classNode, String file, String newCodeBase) {
  CodeSource codeSource = null;
  try {
    codeSource = new CodeSource(new URL("file", "", newCodeBase), (java.security.cert.Certificate[]) null);
  } catch (MalformedURLException e) {
    //swallow
  }
  CompilationUnit unit = createCompilationUnit(config, codeSource);
  ClassCollector collector = createCollector(unit, classNode.getModule().getContext());
  try {
    unit.addClassNode(classNode);
    unit.setClassgenCallback(collector);
    unit.compile(Phases.CLASS_GENERATION);
    return collector.generatedClass;
  } catch (CompilationFailedException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

/**
 * Loads the given class node returning the implementation Class.
 * <p/>
 * WARNING: this compilation is not synchronized
 *
 * @param classNode
 * @return a class
 */
public Class defineClass(ClassNode classNode, String file, String newCodeBase) {
  CodeSource codeSource = null;
  try {
    codeSource = new CodeSource(new URL("file", "", newCodeBase), (java.security.cert.Certificate[]) null);
  } catch (MalformedURLException e) {
    //swallow
  }
  CompilationUnit unit = createCompilationUnit(config, codeSource);
  ClassCollector collector = createCollector(unit, classNode.getModule().getContext());
  try {
    unit.addClassNode(classNode);
    unit.setClassgenCallback(collector);
    unit.compile(Phases.CLASS_GENERATION);
    definePackage(collector.generatedClass.getName());
    return collector.generatedClass;
  } catch (CompilationFailedException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

ClassCollector collector = createCollector(unit, su);
unit.setClassgenCallback(collector);
int goalPhase = Phases.CLASS_GENERATION;

代码示例来源:origin: org.kohsuke.droovy/groovy

ClassCollector collector = createCollector(unit, su);
unit.setClassgenCallback(collector);
int goalPhase = Phases.CLASS_GENERATION;

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

ClassCollector collector = createCollector(unit, su);
unit.setClassgenCallback(collector);
int goalPhase = Phases.CLASS_GENERATION;

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

private Class doParseClass(GroovyCodeSource codeSource) {
  validate(codeSource);
  Class answer;  // Was neither already loaded nor compiling, so compile and add to cache.
  CompilationUnit unit = createCompilationUnit(config, codeSource.getCodeSource());
  SourceUnit su = null;
  if (codeSource.getFile() == null) {
    su = unit.addSource(codeSource.getName(), codeSource.getScriptText());
  } else {
    su = unit.addSource(codeSource.getFile());
  }
  ClassCollector collector = createCollector(unit, su);
  unit.setClassgenCallback(collector);
  int goalPhase = Phases.CLASS_GENERATION;
  if (config != null && config.getTargetDirectory() != null) goalPhase = Phases.OUTPUT;
  unit.compile(goalPhase);
  answer = collector.generatedClass;
  String mainClass = su.getAST().getMainClassName();
  for (Object o : collector.getLoadedClasses()) {
    Class clazz = (Class) o;
    String clazzName = clazz.getName();
    definePackage(clazzName);
    setClassCacheEntry(clazz);
    if (clazzName.equals(mainClass)) answer = clazz;
  }
  return answer;
}

相关文章