Java 8 JavaCompiler.CompilationTask - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JavaCompiler.CompilationTask class.

This code example shows how to use the following methods:call, setProcessors
        destdir.mkdirs();
 
        CompilationTask task = javac.getTask(null, null, null,
                Arrays.asList("-sourcepath", srcdir + File.pathSeparator + rsrcdir, "-d", destdir.toString()),
                Collections.singleton("pkg.X"), null);
        task.setProcessors(Collections.singleton(new AnnoProc()));
        boolean result = task.call();
        System.err.println("javac result with composite source path: " + result);
        expect(result, true);
    } 
 
    private void testMissingResource(JavaCompiler javac) throws Exception {
        System.err.println("testMissingResource");
        File tmpdir = new File("testMissingResource");
        File srcdir = new File(tmpdir, "src");
        File destdir = new File(tmpdir, "dest");
        write(srcdir, "pkg/X.java", "package pkg; class X {}");
        destdir.mkdirs();
 
        CompilationTask task = javac.getTask(null, null, null,
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(testDir));
 
        JavaSource js = new JavaSource();
        System.err.println(js.getCharContent(false));
        CompilationTask t = comp.getTask(null, fm, null, null, null, Arrays.asList(js));
        if (!t.call())
            throw new Error("compilation failed");
 
        File testClass = new File(testDir, "Test.class");
        String out = javap(testClass);
 
        // Extract class sig from first line of Java source 
        String expect = js.source.replaceAll("(?s)^(.* Test[^{]+?) *\\{.*", "$1");
 
        // Extract class sig from line from javap output 
        String found = out.replaceAll("(?s).*\n(.* Test[^{]+?) *\\{.*", "$1");
 
        checkEqual("class signature", expect, found);
 
        return errors;
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
		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)
			return; 
 
		 
		Class<?> clazz = CompilerUtils.getClassByName("com.test.Say");
		Object obj = clazz.newInstance();
		Method method = clazz.getMethod("hello");
		String str = (String)method.invoke(obj);
		Assert.assertThat(str, is("world"));
		 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
                compiler.getStandardFileManager(null, null, null);
        File emptyFile = File.createTempFile("Empty", ".java");
        File[] files = new File[] { emptyFile, emptyFile };
        CompilationTask task = compiler.getTask(null, fm, diag,
                null, null, fm.getJavaFileObjects(files));
        if (! task.call()) {
            throw new AssertionError("compilation failed");
        } 
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
                             new ExceptionalFileManager(fm),
                             null, 
                             Arrays.asList("-proc:only"),
                             null, 
                             fm.getJavaFileObjectsFromFiles(Arrays.asList(source)));
        if (!task.call())
            throw new RuntimeException("Unexpected compilation failure");
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
        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 {
        JavaSource(String name, String text) {
            super(URI.create("js://" + name), JavaFileObject.Kind.SOURCE);
            this.text = text;
        } 
        @Override 
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
            return text;
        } 
        final String text;
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
        fileManager,
        null, 
        buildArguments(Arrays.asList(ErrorProneOptions.processArgs(args).getRemainingArgs())),
        null, 
        sources);
    boolean result = task.call();
    assertTrue(String.format("Test program failed to compile with non error-prone error: %s",
        outputStream.toString()), result);
  } 
 
  public static <T> com.sun.tools.javac.util.List<T> asJavacList(Iterable<? extends T> xs) {
    com.sun.tools.javac.util.List<T> result = com.sun.tools.javac.util.List.nil(); 
    for (T x : xs) {
      result = result.append(x);
    } 
    return result; 
  } 
 
} 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
	private void compile(File file) throws IOException {
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
		StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
		Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file);
		CompilationTask task = compiler.getTask(null, fileManager, null, this.compilerOptions, null, compilationUnits);
		task.call();
	} 
 
	public void load(File handlerClass) {
		String className = handlerClass.getName().substring(0, handlerClass.getName().lastIndexOf("."));
		String useName = className.replaceAll("Handler$", "");
		try { 
			@SuppressWarnings("resource") 
			ClassLoader loader = new URLClassLoader(new URL[] { handlerClass.getParentFile().toURI().toURL() }, GenericHandler.class.getClassLoader());
			Class<?> clazz = loader.loadClass(className);
			Object object = clazz.newInstance();
			if (!(object instanceof GenericHandler)) { 
				this.plugin.getUtilsManager().log("Not a handler: " + useName, Level.WARNING);
			} else { 
				GenericHandler handler = (GenericHandler) object;
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
 
		List<String> options = new ArrayList<String>();
		options.add(includeDebugInfo ? "-g" : "-g:none");
		options.addAll(COMMON_ARGS);
		CompilationTask task = compiler.getTask(null, staticFileManager, null, options, null, compilationUnits);
		Boolean result = task.call();
		fileManager.close();
		if (Boolean.TRUE.equals(result)) {
			return staticFileManager.outputFiles();
		} 
		return Collections.emptyList();
	} 
 
	private static class StaticFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
		private List<File> files = new ArrayList<File>();
		private File outDir;
 
		protected StaticFileManager(StandardJavaFileManager fileManager, File outDir) {
			super(fileManager);
			this.outDir = outDir;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:call
        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 {
        JavaSource(String name, String text) {
            super(URI.create("js://" + name), JavaFileObject.Kind.SOURCE);
            this.text = text;
        } 
        @Override 
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
            return text;
        } 
        final String text;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 JavaCompiler.CompilationTask Methods: