Package com.sun.source.util

Examples of com.sun.source.util.JavacTask


            return source;
        }
    }

    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
                null, null, Arrays.asList(source));
        ct.analyze();
        check();
    }
View Full Code Here


            args.add("-Xlint:serial");
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
        task.setProcessors(Arrays.asList(new AnnoProc()));
        boolean ok = task.call();
        pw.close();

        System.err.println("ok:" + ok + " diags:" + dl.counts);
        if (sw.toString().length() > 0) {
            System.err.println("output:\n" + sw.toString());
View Full Code Here

            }
        }
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
        List<JavaFileObject> compilationUnits =
                Collections.<JavaFileObject>singletonList(new MyFileObject());
        JavacTask task = (JavacTask)javac.getTask(null, null, null, null, null, compilationUnits);
        Trees trees = Trees.instance(task);
        CompilationUnitTree toplevel = task.parse().iterator().next();
        ClassTree classTree = (ClassTree)toplevel.getTypeDecls().get(0);
        List<? extends Tree> annotations = classTree.getModifiers().getAnnotations();
        Tree tree1 = annotations.get(0);
        Tree tree2 = annotations.get(1);
        long pos = trees.getSourcePositions().getStartPosition(toplevel, tree1);
View Full Code Here

            }
        }
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
        List<JavaFileObject> compilationUnits =
                Collections.<JavaFileObject>singletonList(new MyFileObject());
        JavacTask task = (JavacTask)javac.getTask(null, null, null, null, null,
                                                  compilationUnits);
        Trees trees = Trees.instance(task);
        CompilationUnitTree toplevel = task.parse().iterator().next();
        Tree tree = ((ClassTree)toplevel.getTypeDecls().get(0)).getMembers().get(0);
        long pos = trees.getSourcePositions().getStartPosition(toplevel, tree);
        if (pos != 13)
            throw new AssertionError(String.format("Start pos for %s is incorrect (%s)!",
                                                   tree, pos));
View Full Code Here

        JavacTool tool = JavacTool.create();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

        File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
        JavacTask task = tool.getTask(null, fm, null, null, null, fos);
        Iterable<? extends CompilationUnitTree> cus = task.parse();

        TestScanner s = new TestScanner();
        s.scan(cus, task);

        if (errors > 0)
View Full Code Here

    }
   
    private void compile(String pathname, String destDir, String moduleName) throws Exception {
        CeyloncTool compiler = new CeyloncTool();
        List<String> options = Arrays.asList("-src", pathname, "-out", destDir, "-cp", CompilerTest.getClassPathAsPath());
        JavacTask task = compiler.getTask(null, null, null, options, Arrays.asList(moduleName), null);
        Boolean ret = task.call();
        Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
    }
View Full Code Here

        List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
        for(String name : fileNames){
            qualifiedNames.add(pathname + File.separator + name);
        }
        Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
        JavacTask task = compiler.getTask(null, null, null, options, null, fileObjects);
        Boolean ret = task.call();
        Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
    }
View Full Code Here

  }

  private <JS> CompilationUnitTree parseAndResolve(File inputFile, GenerationContext<JS> context, ClassLoader builtProjectClassLoader,
      String sourceEncoding) {
    JavaCompiler.CompilationTask task = null;
    JavacTask javacTask = null;
    try {
      JavaCompiler compiler = getCompiler(builtProjectClassLoader, sourceEncoding);
      Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromFiles(Collections.singleton(inputFile));
      List<String> options = Arrays.asList("-proc:none");
      task = compiler.getTask(null, classLoaderFileManager, null, options, null, fileObjects);
      javacTask = (JavacTask) task;

      context.setTrees(Trees.instance(javacTask));
      context.setElements(javacTask.getElements());
      context.setTypes(javacTask.getTypes());

      Timers.start("parse-java");
      CompilationUnitTree cu = javacTask.parse().iterator().next();
      Timers.end("parse-java");

      Timers.start("analyze-java");
      javacTask.analyze();
      Timers.end("analyze-java");

      context.setCompilationUnit(cu);

      return cu;
View Full Code Here

   
    List<File> files = new ArrayList<File>();
    constructFileTree(sourceRoot, files);
   
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavacTask task = (JavacTask)compiler.getTask(null, null, null, null, null,
        compiler.getStandardFileManager(null, null, null)
        .getJavaFileObjectsFromFiles(files));
   
    for (CompilationUnitTree c : task.parse()) {
      boolean pkgConsider = true;
      String currentPkg = c.getPackageName().toString();
      for (String pkgname : exclusionPkgs)
        if (currentPkg.startsWith(pkgname)) {
          pkgConsider = false;
View Full Code Here

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    DiagnosticCollector<JavaFileObject> diagnosticCollector =
        new DiagnosticCollector<JavaFileObject>();
    InMemoryJavaFileManager fileManager = new InMemoryJavaFileManager(
        compiler.getStandardFileManager(diagnosticCollector, Locale.getDefault(), UTF_8));
    JavacTask task = ((JavacTool) compiler).getTask(
        null, // explicitly use the default because old versions of javac log some output on stderr
        fileManager,
        diagnosticCollector,
        ImmutableSet.<String>of(),
        ImmutableSet.<String>of(),
        sources);
    try {
      Iterable<? extends CompilationUnitTree> parsedCompilationUnits = task.parse();
      List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticCollector.getDiagnostics();
      for (Diagnostic<?> diagnostic : diagnostics) {
        if (Diagnostic.Kind.ERROR == diagnostic.getKind()) {
          throw new IllegalStateException("error while parsing:\n"
              + Diagnostics.toString(diagnostics));
View Full Code Here

TOP

Related Classes of com.sun.source.util.JavacTask

Copyright © 2018 www.massapicom. 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.