当前位置: 首页>>代码示例>>Java>>正文


Java CompileException类代码示例

本文整理汇总了Java中org.codehaus.commons.compiler.CompileException的典型用法代码示例。如果您正苦于以下问题:Java CompileException类的具体用法?Java CompileException怎么用?Java CompileException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CompileException类属于org.codehaus.commons.compiler包,在下文中一共展示了CompileException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBindable

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount)
    throws CompileException, IOException {
  ICompilerFactory compilerFactory;
  try {
    compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
  } catch (Exception e) {
    throw new IllegalStateException(
        "Unable to instantiate java compiler", e);
  }
  IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator();
  cbe.setClassName(expr.name);
  cbe.setExtendedClass(Utilities.class);
  cbe.setImplementedInterfaces(
      fieldCount == 1
          ? new Class[] {Bindable.class, Typed.class}
          : new Class[] {ArrayBindable.class});
  cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader());
  if (CalcitePrepareImpl.DEBUG) {
    // Add line numbers to the generated janino class
    cbe.setDebuggingInformation(true, true, true);
  }
  return (Bindable) cbe.createInstance(new StringReader(s));
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:EnumerableInterpretable.java

示例2: getScalar

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
static Scalar getScalar(ClassDeclaration expr, String s)
    throws CompileException, IOException {
  ICompilerFactory compilerFactory;
  try {
    compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
  } catch (Exception e) {
    throw new IllegalStateException(
        "Unable to instantiate java compiler", e);
  }
  IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator();
  cbe.setClassName(expr.name);
  cbe.setImplementedInterfaces(new Class[]{Scalar.class});
  cbe.setParentClassLoader(JaninoRexCompiler.class.getClassLoader());
  if (CalcitePrepareImpl.DEBUG) {
    // Add line numbers to the generated janino class
    cbe.setDebuggingInformation(true, true, true);
  }
  return (Scalar) cbe.createInstance(new StringReader(s));
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:JaninoRexCompiler.java

示例3: report

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
@Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
  if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
    String message = diagnostic.toString() + " (" + diagnostic.getCode() + ")";
    logger.error(message);
    Location loc = new Location( //
        diagnostic.getSource().toString(), //
        (short) diagnostic.getLineNumber(), //
        (short) diagnostic.getColumnNumber() //
    );
    // Wrap the exception in a RuntimeException, because "report()"
    // does not declare checked exceptions.
    throw new RuntimeException(new CompileException(message, loc));
  } else if (logger.isTraceEnabled()) {
    logger.trace(diagnostic.toString() + " (" + diagnostic.getCode() + ")");
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:18,代码来源:DrillDiagnosticListener.java

示例4: getClassByteCode

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
private byte[][] getClassByteCode(ClassNames className, String sourceCode)
    throws CompileException, ClassNotFoundException, ClassTransformationException, IOException {
  AbstractClassCompiler classCompiler;
  if (jdkClassCompiler != null &&
      (policy == CompilerPolicy.JDK || (policy == CompilerPolicy.DEFAULT && sourceCode.length() > janinoThreshold))) {
    classCompiler = jdkClassCompiler;
  } else {
    classCompiler = janinoClassCompiler;
  }

  byte[][] bc = classCompiler.getClassByteCode(className, sourceCode);
  /*
   * final String baseDir = System.getProperty("java.io.tmpdir") + File.separator + classCompiler.getClass().getSimpleName();
   * File classFile = new File(baseDir + className.clazz);
   * classFile.getParentFile().mkdirs();
   * BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(classFile));
   * out.write(bc[0]);
   * out.close();
   */
  return bc;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:22,代码来源:QueryClassLoader.java

示例5: getClassByteCode

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
public byte[][] getClassByteCode(ClassNames className, String sourceCode)
      throws CompileException, IOException, ClassNotFoundException, ClassTransformationException {
    if (getLogger().isDebugEnabled()) {
      getLogger().debug("Compiling (source size={}):\n{}", DrillStringUtils.readable(sourceCode.length()), prefixLineNumbers(sourceCode));

/* uncomment this to get a dump of the generated source in /tmp
      // This can be used to write out the generated operator classes for debugging purposes
      // TODO: should these be put into a directory named with the query id and/or fragment id
      final int lastSlash = className.slash.lastIndexOf('/');
      final File dir = new File("/tmp", className.slash.substring(0, lastSlash));
      dir.mkdirs();
      final File file = new File(dir, className.slash.substring(lastSlash + 1) + ".java");
      final FileWriter writer = new FileWriter(file);
      writer.write(sourceCode);
      writer.close();
*/
    }
    return getByteCode(className, sourceCode);
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:AbstractClassCompiler.java

示例6: getClassBody

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
private String getClassBody(Class<?> c) throws CompileException, IOException{
  String path = c.getName();
  path = path.replaceFirst("\\$.*", "");
  path = path.replace(".", FileUtils.separator);
  path = "/" + path + ".java";
  URL u = Resources.getResource(c, path);
  InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
  try (InputStream is = supplier.getInput()) {
    if (is == null) {
      throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
    }
    String body = IO.toString(is);

    //TODO: Hack to remove annotations so Janino doesn't choke.  Need to reconsider this problem...
    //return body.replaceAll("@(?:Output|Param|Workspace|Override|SuppressWarnings\\([^\\\\]*?\\)|FunctionTemplate\\([^\\\\]*?\\))", "");
    return body.replaceAll("@(?:\\([^\\\\]*?\\))?", "");
  }

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:FunctionConverter.java

示例7: getByteCode

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
@Override
protected ClassBytes[] getByteCode(final ClassNames className, final String sourcecode, boolean debug)
    throws CompileException, IOException, ClassNotFoundException, ClassTransformationException {
  StringReader reader = new StringReader(sourcecode);
  Scanner scanner = new Scanner((String) null, reader);
  Java.CompilationUnit compilationUnit = new Parser(scanner).parseCompilationUnit();
  ClassFile[] classFiles = new UnitCompiler(compilationUnit, compilationClassLoader)
                                .compileUnit(debug, debug, debug);

  ClassBytes[] byteCodes = new ClassBytes[classFiles.length];
  for(int i = 0; i < classFiles.length; i++){
    ClassFile file = classFiles[i];
    byteCodes[i] = new ClassBytes(file.getThisClassName(), file.toByteArray());
  }
  return byteCodes;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:JaninoClassCompiler.java

示例8: getClassByteCode

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
@Override
  public ClassBytes[] getClassByteCode(ClassNames className, String sourceCode, boolean debug)
      throws CompileException, IOException, ClassNotFoundException, ClassTransformationException {
    if (getLogger().isDebugEnabled()) {
      getLogger().debug("Compiling (source size={}):\n{}", DremioStringUtils.readable(sourceCode.length()),
          debug ? prefixLineNumbers(sourceCode) : debug);

/* uncomment this to get a dump of the generated source in /tmp
      // This can be used to write out the generated operator classes for debugging purposes
      // TODO: should these be put into a directory named with the query id and/or fragment id
      final int lastSlash = className.slash.lastIndexOf('/');
      final File dir = new File("/tmp", className.slash.substring(0, lastSlash));
      dir.mkdirs();
      final File file = new File(dir, className.slash.substring(lastSlash + 1) + ".java");
      final FileWriter writer = new FileWriter(file);
      writer.write(sourceCode);
      writer.close();
*/
    }
    return getByteCode(className, sourceCode, debug);
  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:22,代码来源:AbstractClassCompiler.java

示例9: get

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
private CompilationUnit get(Class<?> c) throws IOException {
    URL u = getSourceURL(c);
    try (Reader reader = Resources.asCharSource(u, UTF_8).openStream()) {
      String body = CharStreams.toString(reader);

      // TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem...
      body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", "");
      for(Replacement r : REPLACERS){
        body = r.apply(body);
      }
//       System.out.println("original");
      // System.out.println(body);;
      // System.out.println("decompiled");
      // System.out.println(decompile(c));

      try {
        return new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit();
      } catch (CompileException e) {
        logger.warn("Failure while parsing function class:\n{}", body, e);
        return null;
      }

    }

  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:FunctionInitializer.java

示例10: getClassByteCode

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
byte[][] getClassByteCode(ClassNames className, String sourceCode)
      throws CompileException, ClassNotFoundException, ClassTransformationException, IOException {

    byte[][] bc = getCompiler(sourceCode).getClassByteCode(className, sourceCode);

    // Uncomment the following to save the generated byte codes.
    // Use the JDK javap command to view the generated code.
    // This is the code from the compiler before byte code manipulations.
    // For a similar block to display byte codes after manipulation,
    // see QueryClassLoader.

//    final File baseDir = new File( new File( System.getProperty("java.io.tmpdir") ), "classes" );
//    for ( int i = 0;  i < bc.length;  i++ ) {
//      File classFile = new File( baseDir, className.slash + i + ".class" );
//      classFile.getParentFile().mkdirs();
//      try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(classFile))) {
//        out.write(bc[i]);
//      }
//    }
//    System.out.println( "Classes saved to: " + baseDir.getAbsolutePath() );

    return bc;
  }
 
开发者ID:axbaretto,项目名称:drill,代码行数:24,代码来源:ClassCompilerSelector.java

示例11: build

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
public Condition build(String script) throws IllegalAccessException,
        CompileException,
        InstantiationException,
        SecurityException, NoSuchMethodException, IllegalArgumentException,
        InvocationTargetException {

  ClassBodyEvaluator cbe = new ClassBodyEvaluator();
  cbe.setImplementedInterfaces(new Class[]{Condition.class});
  cbe.setExtendedClass(PropertyWrapperForScripts.class);
  cbe.setParentClassLoader(ClassBodyEvaluator.class.getClassLoader());
  cbe.cook(SCRIPT_PREFIX + script + SCRIPT_SUFFIX);

  Class<?> clazz = cbe.getClazz();
  Condition instance = (Condition) clazz.newInstance();
  Method setMapMethod = clazz.getMethod("setPropertyContainers", PropertyContainer.class, PropertyContainer.class);
  setMapMethod.invoke(instance, localPropContainer, context);

  return instance;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:20,代码来源:PropertyEvalScriptBuilder.java

示例12: getExpression

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
/**
 * Creates the instance of the class defined in {@link ClassDeclaration}
 * @param expr Interface whose instance needs to be created.
 * @param s The java code that implements the interface which should be used to create the instance.
 * @return The object of the class which implements the interface {@link Expression} with the code that is passed as input.
 * @throws CompileException
 * @throws IOException
 */
static Expression getExpression(ClassDeclaration expr, String s) throws CompileException, IOException {
  ICompilerFactory compilerFactory;
  try {
    compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
  } catch (Exception e) {
    throw new IllegalStateException("Unable to instantiate java compiler", e);
  }
  IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator();
  cbe.setClassName(expr.name);
  cbe.setImplementedInterfaces(expr.implemented.toArray(new Class[expr.implemented.size()]));
  cbe.setParentClassLoader(RexToJavaCompiler.class.getClassLoader());
  cbe.setDebuggingInformation(true, true, true);

  return (org.apache.samza.sql.data.Expression) cbe.createInstance(new StringReader(s));
}
 
开发者ID:apache,项目名称:samza,代码行数:24,代码来源:RexToJavaCompiler.java

示例13: testScript

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
/**
 * This test creates a Janino connection that executes simple valid and invalid scripts.
 */
public void testScript() {
    JaninoConnection c = new JaninoConnection(new ConnectionParameters(new MockConnectionEl(), MockDriverContext.INSTANCE));
    field = 0;
    c.executeScript(new StringResource(JaninoConnectionTest.class.getName() + ".field=1;"), null);
    try {
        c.executeScript(new StringResource(JaninoConnectionTest.class.getName() + ".nosuchfield=1;"), null);
        fail("This script should fail");
    } catch (ProviderException e) {
        Throwable ne = e.getNativeException();
        assertTrue(ne instanceof CompileException);
        //OK
    }
    c.close();
    assertEquals(1, field);
}
 
开发者ID:scriptella,项目名称:scriptella-etl,代码行数:19,代码来源:JaninoConnectionTest.java

示例14: compile

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
private static Function1<DataContext, Object[]> compile(String code,
    Object reason) {
  try {
    final ClassBodyEvaluator cbe = new ClassBodyEvaluator();
    cbe.setClassName(GENERATED_CLASS_NAME);
    cbe.setExtendedClass(Utilities.class);
    cbe.setImplementedInterfaces(new Class[] {Function1.class, Serializable.class});
    cbe.setParentClassLoader(RexExecutable.class.getClassLoader());
    cbe.cook(new Scanner(null, new StringReader(code)));
    Class c = cbe.getClazz();
    //noinspection unchecked
    final Constructor<Function1<DataContext, Object[]>> constructor =
        c.getConstructor();
    return constructor.newInstance();
  } catch (CompileException | IOException | InstantiationException
      | IllegalAccessException | InvocationTargetException
      | NoSuchMethodException e) {
    throw new RuntimeException("While compiling " + reason, e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:RexExecutable.java

示例15: getByteCode

import org.codehaus.commons.compiler.CompileException; //导入依赖的package包/类
@Override
protected byte[][] getByteCode(final ClassNames className, final String sourceCode)
    throws CompileException, IOException, ClassNotFoundException {
  try {
    // Create one Java source file in memory, which will be compiled later.
    DrillJavaFileObject compilationUnit = new DrillJavaFileObject(className.dot, sourceCode);

    CompilationTask task = compiler.getTask(null, fileManager, listener, compilerOptions, null, Collections.singleton(compilationUnit));

    // Run the compiler.
    if(!task.call()) {
      throw new CompileException("Compilation failed", null);
    } else if (!compilationUnit.isCompiled()) {
      throw new ClassNotFoundException(className + ": Class file not created by compilation.");
    }
    // all good
    return compilationUnit.getByteCode();
  } catch (RuntimeException rte) {
    // Unwrap the compilation exception and throw it.
    Throwable cause = rte.getCause();
    if (cause != null) {
      cause = cause.getCause();
      if (cause instanceof CompileException) {
        throw (CompileException) cause;
      }
      if (cause instanceof IOException) {
        throw (IOException) cause;
      }
    }
    throw rte;
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:33,代码来源:JDKClassCompiler.java


注:本文中的org.codehaus.commons.compiler.CompileException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。