Package javax.tools.JavaCompiler

Examples of javax.tools.JavaCompiler.CompilationTask.call()


       */
      CompilationTask compilerTask = compiler.getTask( null, stdFileManager, diagnostics, compilationOptionss, null, compilationUnits );

      // Perform the compilation by calling the call method on compilerTask
      // object.
      boolean status = compilerTask.call();

      Object instance = null;
      if( !status ) {// If compilation error occurs
        /* Iterate through each compilation problem and print it */
        for(Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
View Full Code Here


  public static Class<?> compileSource(String completeClassName, String source) throws Throwable {
    boolean result = false;
    JavaFileManager fileManager = CompilerUtils.getStringSourceJavaFileManager(compiler, null, null, Charset.forName("UTF-8"));
    try {
      CompilationTask task = compiler.getTask(null, fileManager, null, null, null,Arrays.asList(new JavaSourceFromString(completeClassName, source)));
      result = task.call();
    } finally {
      fileManager.close();
    }
   
    if(!result)
View Full Code Here

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileManager fileManager = CompilerUtils.getStringSourceJavaFileManager(compiler, null, null, Charset.forName("UTF-8"));
    boolean result = false;
    try {
      CompilationTask task = compiler.getTask(null, fileManager, null, null, null,Arrays.asList(new JavaSourceFromString("com.test.Say", source)));
      result = task.call();
    } finally {
      fileManager.close();
    }

    if (!result)
View Full Code Here

   
    // tests before we renamed module_.class to $module_.class
    @Test
    public void testBinaryVersionIncompatibleModule1() throws IOException {
        CompilationTask compiler = compileJava("binaryVersionOld/module_.java");
        Assert.assertTrue(compiler.call());
       
        // so now make a jar containing the java module
        File jarFolder = new File(destDir, "com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld/1/");
        jarFolder.mkdirs();
        File jarFile = new File(jarFolder, "com.redhat.ceylon.compiler.java.test.bc.binaryVersionOld-1.jar");
View Full Code Here

    // tests after we renamed module_.class to $module_.class
    @Test
    public void testBinaryVersionIncompatibleModule2() throws IOException {
        CompilationTask compiler = compileJava("binaryVersionOld2/$module_.java");
        Assert.assertTrue(compiler.call());
       
        // so now make a jar containing the java module
        File jarFolder = new File(destDir, "com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld2/1/");
        jarFolder.mkdirs();
        File jarFile = new File(jarFolder, "com.redhat.ceylon.compiler.java.test.bc.binaryVersionOld2-1.jar");
View Full Code Here

    void compile(DiagnosticChecker dc, JavaSource... sources) {
        try {
            CompilationTask ct = javacTool.getTask(null, null, dc,
                    Arrays.asList("-d", testDir.getAbsolutePath(), "-cp", testDir.getAbsolutePath()),
                    null, Arrays.asList(sources));
            ct.call();
        }
        catch (Exception e) {
            error("Internal compilation error");
        }
    }
View Full Code Here

        options.add("-proc:only");
        List<File> files = new ArrayList<File>();
        files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
        final CompilationTask task = compiler.getTask(null, fm, diagColl,
            options, null, fm.getJavaFileObjectsFromFiles(files));
        task.call();
        int diagCount = 0;
        for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
            if (diag.getKind() != Diagnostic.Kind.WARNING) {
                throw new AssertionError("Only warnings expected");
            }
View Full Code Here

        if (processor != null) {
            // opts.add("-verbose");
            opts.addAll(Arrays.asList("-processor", processor));
        }
        CompilationTask task = comp.getTask(null, fm, dl, opts, null, Arrays.asList(files));
        boolean ok = task.call();
        if (dl == null && !ok)
            throw new Exception("compilation failed");
    }

    static class JavaSource extends SimpleJavaFileObject {
View Full Code Here

        this.javaFileManager.putFileForInput(StandardLocation.SOURCE_PATH, packageName, className + CharSequenceCompiler.JAVA_EXTENSION, source);
      }
    }
    // Get a CompliationTask from the compiler and compile the sources
    final CompilationTask task = this.compiler.getTask(null, this.javaFileManager, this.diagnostics, this.options, null, sources);
    final Boolean result = task.call();
    if (result == null || !result.booleanValue()) {
      throw new CharSequenceCompilerException("Compilation failed.", classes.keySet(), this.diagnostics);
    }
    try {
      // For each class name in the inpput map, get its compiled
View Full Code Here

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        JavaFileObject f = new MyFileObject("myfo://test", "class Bad { Missing x; }");
        List<? extends JavaFileObject> files = Arrays.asList(f);
        CompilationTask task = javac.getTask(pw, null, null, options, null, files);
        boolean ok = task.call();
        pw.close();
        String out = sw.toString();
        if (!out.isEmpty())
            System.err.println(out);
        if (ok)
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.