com.sun.tools.javac.main.JavaCompiler Java Examples

The following examples show how to use com.sun.tools.javac.main.JavaCompiler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: openjdk-8   Author: bpupadhyaya   File: JavacTaskImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * For internal use only.  This method will be
 * removed without warning.
 */
public Type parseType(String expr, TypeElement scope) {
    if (expr == null || expr.equals(""))
        throw new IllegalArgumentException();
    compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(null);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Attr attr = Attr.instance(context);
    try {
        CharBuffer buf = CharBuffer.wrap((expr+"\u0000").toCharArray(), 0, expr.length());
        Parser parser = parserFactory.newParser(buf, false, false, false);
        JCTree tree = parser.parseType();
        return attr.attribType(tree, (Symbol.TypeSymbol)scope);
    } finally {
        compiler.log.useSource(prev);
    }
}
 
Example #2
Source Project: TencentKona-8   Author: Tencent   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example #3
Source Project: openjdk-8   Author: bpupadhyaya   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #4
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T4910483.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) {
    JavaCompiler compiler = JavaCompiler.instance(new Context());
    compiler.keepComments = true;

    String testSrc = System.getProperty("test.src");
    JavacFileManager fm = new JavacFileManager(new Context(), false, null);
    JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + "T4910483.java");

    JCTree.JCCompilationUnit cu = compiler.parse(f);
    JCTree classDef = cu.getTypeDecls().head;
    String commentText = cu.docComments.getCommentText(classDef);

    String expected = "Test comment abc*\\\\def"; // 4 '\' escapes to 2 in a string literal
    if (!expected.equals(commentText)) {
        throw new AssertionError("Incorrect comment text: [" + commentText + "], expected [" + expected + "]");
    }
}
 
Example #5
Source Project: openjdk-8   Author: bpupadhyaya   File: T6358166.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void initProcessorClassLoader() {
    JavaFileManager fileManager = context.get(JavaFileManager.class);
    try {
        // If processorpath is not explicitly set, use the classpath.
        processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
            ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
            : fileManager.getClassLoader(CLASS_PATH);

        if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
            JavaCompiler compiler = JavaCompiler.instance(context);
            compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader);
        }
    } catch (SecurityException e) {
        processorClassLoaderException = e;
    }
}
 
Example #7
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: PubApiExtractor.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
     * Setup a compilation context, used for reading public apis of classes on the classpath
     * as well as annotation processors.
     */
    public PubApiExtractor(Options options) {
        JavacTool compiler = com.sun.tools.javac.api.JavacTool.create();
        fileManager = new SmartFileManager(compiler.getStandardFileManager(null, null, null));
        context = new com.sun.tools.javac.util.Context();
        String[] args = options.prepJavacArgs();
        task = compiler.getTask(new PrintWriter(System.err),
                                fileManager,
                                null,
                                Arrays.asList(args),
                                null,
                                null,
                                context);
        // Trigger a creation of the JavaCompiler, necessary to get a sourceCompleter for ClassFinder.
        // The sourceCompleter is used for build situations where a classpath class references other classes
        // that happens to be on the sourcepath.
        JavaCompiler.instance(context);

//        context.put(JavaFileManager.class, fileManager);
    }
 
Example #8
Source Project: jdk8u60   Author: chenghanpeng   File: T6358166.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example #9
Source Project: jdk8u60   Author: chenghanpeng   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #10
Source Project: jdk8u60   Author: chenghanpeng   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #11
Source Project: junion   Author: TehLeo   File: JStructPlugin.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void wrapCompiler(Context c) throws Exception {
	Context.Key<JavaCompiler> compilerKey = read(JavaCompiler.class, "compilerKey");
	JavaCompiler comp = c.get(compilerKey);
	
	Unsafe u = getUnsafe();
	JavaCompilerWrapper jcw = (JavaCompilerWrapper)u.allocateInstance(JavaCompilerWrapper.class);
	//now gotta copy all the nonstatic fields
	Class jc = JavaCompiler.class;
	Field[] fs = jc.getDeclaredFields();
	for(Field f : fs) {
		if(!Modifier.isStatic(f.getModifiers())) {
			f.setAccessible(true);
			f.set(jcw, f.get(comp));
		}
	}
	c.put(compilerKey, (JavaCompiler)null);
	c.put(compilerKey, (JavaCompiler)jcw);
}
 
Example #12
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example #13
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Create a round (common code). */
private Round(Context context, int number, int priorErrors, int priorWarnings,
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
    this.context = context;
    this.number = number;

    compiler = JavaCompiler.instance(context);
    log = Log.instance(context);
    log.nerrors = priorErrors;
    log.nwarnings = priorWarnings;
    if (number == 1) {
        Assert.checkNonNull(deferredDiagnosticHandler);
        this.deferredDiagnosticHandler = deferredDiagnosticHandler;
    } else {
        this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
    }

    // the following is for the benefit of JavacProcessingEnvironment.getContext()
    JavacProcessingEnvironment.this.context = context;

    // the following will be populated as needed
    topLevelClasses  = List.nil();
    packageInfoFiles = List.nil();
}
 
Example #14
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Dependencies.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a Dependencies instance.
 */
GraphDependencies(Context context) {
    super(context);
    //fetch filename
    Options options = Options.instance(context);
    String[] modes = options.get("debug.completionDeps").split(",");
    for (String mode : modes) {
        if (mode.startsWith("file=")) {
            dependenciesFile = mode.substring(5);
        }
    }
    //parse modes
    dependenciesModes = DependenciesMode.getDependenciesModes(modes);
    //add to closeables
    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.closeables = compiler.closeables.prepend(this);
}
 
Example #15
Source Project: javaide   Author: tranleduy2000   File: JavacTaskImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * For internal use only.  This method will be
 * removed without warning.
 */
public Type parseType(String expr, TypeElement scope) {
    if (expr == null || expr.equals(""))
        throw new IllegalArgumentException();
    compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(null);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Attr attr = Attr.instance(context);
    try {
        CharBuffer buf = CharBuffer.wrap((expr+"\u0000").toCharArray(), 0, expr.length());
        Parser parser = parserFactory.newParser(buf, false, false, false);
        JCTree tree = parser.parseType();
        return attr.attribType(tree, (TypeSymbol)scope);
    } finally {
        compiler.log.useSource(prev);
    }
}
 
Example #16
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #17
Source Project: openjdk-8-source   Author: keerath   File: T6358166.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example #18
Source Project: bazel   Author: bazelbuild   File: BlazeJavaCompiler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adds an initialization hook to the Context, such that requests for a JavaCompiler (i.e., a
 * lookup for 'compilerKey' of our superclass, JavaCompiler) will actually construct and return
 * BlazeJavaCompiler.
 *
 * <p>This is the preferred way for extending behavior within javac, per the documentation in
 * {@link Context}.
 *
 * <p>Prior to JDK-8038455 additional JavaCompilers were created for annotation processing rounds,
 * but we now expect a single compiler instance per compilation. The factory is still seems to be
 * necessary to avoid context-ordering issues, but we assert that the factory is only called once,
 * and save the output after its call for introspection.
 */
public static void preRegister(
    final Context context, final Iterable<BlazeJavaCompilerPlugin> plugins) {
  context.put(
      compilerKey,
      new Context.Factory<JavaCompiler>() {
        boolean first = true;

        @Override
        public JavaCompiler make(Context c) {
          if (!first) {
            throw new AssertionError("Expected a single creation of BlazeJavaCompiler.");
          }
          first = false;
          return new BlazeJavaCompiler(c, plugins);
        }
      });
}
 
Example #19
Source Project: lua-for-android   Author: qtiuto   File: JavacTaskImpl.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * For internal use only.  This method will be
 * removed without warning.
 * @param expr the type expression to be analyzed
 * @param scope the scope in which to analyze the type expression
 * @return the type
 * @throws IllegalArgumentException if the type expression of null or empty
 */
public Type parseType(String expr, TypeElement scope) {
    if (expr == null || expr.equals(""))
        throw new IllegalArgumentException();
    compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(null);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Attr attr = Attr.instance(context);
    try {
        CharBuffer buf = CharBuffer.wrap((expr+"\u0000").toCharArray(), 0, expr.length());
        Parser parser = parserFactory.newParser(buf, false, false, false);
        JCTree tree = parser.parseType();
        return attr.attribType(tree, (Symbol.TypeSymbol)scope);
    } finally {
        compiler.log.useSource(prev);
    }
}
 
Example #20
Source Project: hottub   Author: dsrg-uoft   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #21
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, List<JavaFileObject> files) throws Throwable {
    Context context = new Context();

    String[] args = { "-d", "." };

    JavacTool tool = JavacTool.create();
    JavacTask task = tool.getTask(null, fm, null, List.from(args), null, files, context);
    // no need in this simple case to call task.prepareCompiler(false)

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(files);
    try {
        compiler.compile(files);
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #22
Source Project: hottub   Author: dsrg-uoft   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #23
Source Project: hottub   Author: dsrg-uoft   File: PackageProcessor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(compiler.shouldStopPolicyIfNoError,
            CompileState.FLOW);
}
 
Example #24
Source Project: hottub   Author: dsrg-uoft   File: T6400303.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
    JavaCompiler compiler = JavaCompiler.instance(task.getContext());
    try {
        compiler.resolveIdent("Test$1").complete();
    } catch (CompletionFailure ex) {
        System.err.println("Got expected completion failure: " + ex.getLocalizedMessage());
        return;
    }
    throw new AssertionError("No error reported");
}
 
Example #25
Source Project: TencentKona-8   Author: Tencent   File: JavacElements.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Use a new context.  May be called from outside to update
 * internal state for a new annotation-processing round.
 */
public void setContext(Context context) {
    context.put(JavacElements.class, this);
    javaCompiler = JavaCompiler.instance(context);
    syms = Symtab.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);
    enter = Enter.instance(context);
}
 
Example #26
Source Project: hottub   Author: dsrg-uoft   File: TestSymtabItems.java    License: GNU General Public License v2.0 5 votes vote down vote up
void run() throws Exception {
        Context c = new Context();
        JavacFileManager.preRegister(c);
        Symtab syms = Symtab.instance(c);
        JavacTypes types = JavacTypes.instance(c);
        JavaCompiler.instance(c);  // will init ClassReader.sourceCompleter

//        print("noSymbol", syms.noSymbol);
//        print("errSymbol", syms.errSymbol);
//        print("unknownSymbol", syms.unknownSymbol);
//        print("botType", syms.botType);
//        print("errType", syms.errType);
//        print("unknownType", syms.unknownType);

        for (Field f: Symtab.class.getDeclaredFields()) {
//            System.err.println(f.getType() + " " + f.getName());

            // Temporarily ignore methodHandle and transientMethodHandle
            // during API evolution
            if (f.getName().toLowerCase().contains("methodhandle"))
                continue;

            Class<?> ft = f.getType();
            if (TypeMirror.class.isAssignableFrom(ft))
                print(f.getName(), (TypeMirror) f.get(syms), types);
            else if(Element.class.isAssignableFrom(ft))
                print(f.getName(), (Element) f.get(syms));
        }

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }
 
Example #27
Source Project: bazel   Author: bazelbuild   File: BlazeJavaCompilerPlugin.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the plugin. Called by {@link
 * com.google.devtools.build.buildjar.javac.BlazeJavaCompiler}'s constructor.
 *
 * @param context The Context object from the enclosing BlazeJavaCompiler instance
 * @param log The Log object from the enclosing BlazeJavaCompiler instance
 * @param compiler The enclosing BlazeJavaCompiler instance
 * @param statisticsBuilder The builder object for statistics, so that this plugin may report
 *     performance or auxiliary information.
 */
public void init(
    Context context,
    Log log,
    JavaCompiler compiler,
    BlazeJavacStatistics.Builder statisticsBuilder) {
  this.context = context;
  this.log = log;
  this.compiler = compiler;
  this.statisticsBuilder = statisticsBuilder;
}
 
Example #28
Source Project: Refaster   Author: google   File: Inliner.java    License: Apache License 2.0 5 votes vote down vote up
public ClassSymbol resolveClass(String qualifiedClass) throws CouldNotResolveImportException {
  Symbol symbol = JavaCompiler.instance(context).resolveIdent(qualifiedClass);
  if (symbol.equals(symtab().errSymbol) || !(symbol instanceof ClassSymbol)) {
    throw new CouldNotResolveImportException(qualifiedClass);
  } else {
    return (ClassSymbol) symbol;
  }
}
 
Example #29
Source Project: TencentKona-8   Author: Tencent   File: T6400303.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
    JavaCompiler compiler = JavaCompiler.instance(task.getContext());
    try {
        compiler.resolveIdent("Test$1").complete();
    } catch (CompletionFailure ex) {
        System.err.println("Got expected completion failure: " + ex.getLocalizedMessage());
        return;
    }
    throw new AssertionError("No error reported");
}
 
Example #30
Source Project: openjdk-8-source   Author: keerath   File: JavaCompilerWithDeps.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void preRegister(Context context, final CompilerThread t) {
    context.put(compilerKey, new Context.Factory<JavaCompiler>() {
        public JavaCompiler make(Context c) {
            JavaCompiler instance = new JavaCompilerWithDeps(c, t);
            c.put(JavaCompiler.class, instance);
            return instance;
        }
    });
}