Пример #1
0
  /**
   * 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);
    }
  }