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

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

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

GroovyClassLoader.definePackage介绍

暂无

代码示例

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

private void definePackageInternal(String className) {
  int i = className.lastIndexOf('.');
  if (i != -1) {
    String pkgName = className.substring(0, i);
    java.lang.Package pkg = getPackage(pkgName);
    if (pkg == null) {
      definePackage(pkgName, null, null, null, null, null, null, null);
    }
  }
}

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

private void definePackage(String className) {
  int i = className.lastIndexOf('.');
  if (i != -1) {
    String pkgName = className.substring(0, i);
    Package pkg = getPackage(pkgName);
    if (pkg == null) {
      definePackage(pkgName, null, null, null, null, null, null, null);
    }
  }
}

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

private void definePackage(String className) {
  int i = className.lastIndexOf('.');
  if (i != -1) {
    String pkgName = className.substring(0, i);
    java.lang.Package pkg = getPackage(pkgName);
    if (pkg == null) {
      definePackage(pkgName, null, null, null, null, null, null, null);
    }
  }
}

代码示例来源: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: 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

for (Iterator iter = collector.getLoadedClasses().iterator(); iter.hasNext();) {
  Class clazz = (Class) iter.next();
  definePackage(clazz.getName());
  setClassCacheEntry(clazz);

代码示例来源: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;
}

相关文章