Java Code Examples for com.sun.tools.javac.util.Context#get()
The following examples show how to use
com.sun.tools.javac.util.Context#get() .
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 File: Enter.java From javaide with GNU General Public License v3.0 | 6 votes |
protected Enter(Context context) { context.put(enterKey, this); log = Log.instance(context); reader = ClassReader.instance(context); make = TreeMaker.instance(context); syms = Symtab.instance(context); chk = Check.instance(context); memberEnter = MemberEnter.instance(context); types = Types.instance(context); annotate = Annotate.instance(context); lint = Lint.instance(context); names = Names.instance(context); predefClassDef = make.ClassDef( make.Modifiers(PUBLIC), syms.predefClass.name, null, null, null, null); predefClassDef.sym = syms.predefClass; todo = Todo.instance(context); fileManager = context.get(JavaFileManager.class); Options options = Options.instance(context); pkginfoOpt = PkgInfo.get(options); }
Example 2
Source File: Enter.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
protected Enter(Context context) { context.put(enterKey, this); log = Log.instance(context); reader = ClassReader.instance(context); make = TreeMaker.instance(context); syms = Symtab.instance(context); chk = Check.instance(context); memberEnter = MemberEnter.instance(context); types = Types.instance(context); annotate = Annotate.instance(context); lint = Lint.instance(context); names = Names.instance(context); predefClassDef = make.ClassDef( make.Modifiers(PUBLIC), syms.predefClass.name, null, null, null, null); predefClassDef.sym = syms.predefClass; todo = Todo.instance(context); fileManager = context.get(JavaFileManager.class); Options options = Options.instance(context); pkginfoOpt = PkgInfo.get(options); }
Example 3
Source File: Messager.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** Get the current messager, which is also the compiler log. */ public static Messager instance0(Context context) { Log instance = context.get(logKey); if (instance == null || !(instance instanceof Messager)) throw new InternalError("no messager instance!"); return (Messager)instance; }
Example 4
Source File: ManCheck.java From manifold with Apache License 2.0 | 5 votes |
public static Check instance( Context ctx ) { Check check = ctx.get( checkKey ); if( !(check instanceof ManCheck) ) { ctx.put( checkKey, (Check)null ); check = new ManCheck( ctx ); } return check; }
Example 5
Source File: ParserFactory.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected ParserFactory(Context context) { super(); context.put(parserFactoryKey, this); this.F = TreeMaker.instance(context); this.docTreeMaker = DocTreeMaker.instance(context); this.log = Log.instance(context); this.names = Names.instance(context); this.tokens = Tokens.instance(context); this.source = Source.instance(context); this.options = Options.instance(context); this.scannerFactory = ScannerFactory.instance(context); this.locale = context.get(Locale.class); }
Example 6
Source File: BlazeJavaCompiler.java From bazel with Apache License 2.0 | 5 votes |
private BlazeJavaCompiler(Context context, Iterable<BlazeJavaCompilerPlugin> plugins) { super(context); BlazeJavacStatistics.Builder statisticsBuilder = context.get(BlazeJavacStatistics.Builder.class); // initialize all plugins for (BlazeJavaCompilerPlugin plugin : plugins) { plugin.init(context, log, this, statisticsBuilder); this.plugins.add(plugin); } }
Example 7
Source File: Start.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public Start(Context context) { this.context = Objects.requireNonNull(context); apiMode = true; defaultDocletClassName = standardDocletClassName; docletParentClassLoader = null; Log log = context.get(Log.logKey); if (log instanceof Messager) messager = (Messager) log; else { PrintWriter out = context.get(Log.errKey); messager = (out == null) ? new Messager(context, javadocName) : new Messager(context, javadocName, out, out, out); } }
Example 8
Source File: CommentCollectingScannerFactory.java From EasyMPermission with MIT License | 5 votes |
@SuppressWarnings("all") public static void preRegister(final Context context) { if (context.get(scannerFactoryKey) == null) { // Careful! There is voodoo magic here! // // Context.Factory is parameterized. make() is for javac6 and below; make(Context) is for javac7 and up. // this anonymous inner class definition is intentionally 'raw' - the return type of both 'make' methods is 'T', // which means the compiler will only generate the correct "real" override method (with returntype Object, which is // the lower bound for T, as a synthetic accessor for the make with returntype ScannerFactory) for that make method which // is actually on the classpath (either make() for javac6-, or make(Context) for javac7+). // // We normally solve this issue via src/stubs, with BOTH make methods listed, but for some reason the presence of a stubbed out // Context (or even a complete copy, it doesn't matter) results in a really strange eclipse bug, where any mention of any kind // of com.sun.tools.javac.tree.TreeMaker in a source file disables ALL usage of 'go to declaration' and auto-complete in the entire // source file. // // Thus, in short: // * Do NOT parameterize the anonymous inner class literal. // * Leave the return types as 'j.l.Object'. // * Leave both make methods intact; deleting one has no effect on javac6- / javac7+, but breaks the other. Hard to test for. // * Do not stub com.sun.tools.javac.util.Context or any of its inner types, like Factory. @SuppressWarnings("all") class MyFactory implements Context.Factory { // This overrides the javac6- version of make. public Object make() { return new CommentCollectingScannerFactory(context); } // This overrides the javac7+ version of make. public Object make(Context c) { return new CommentCollectingScannerFactory(c); } } @SuppressWarnings("unchecked") Context.Factory<Scanner.Factory> factory = new MyFactory(); context.put(scannerFactoryKey, factory); } }
Example 9
Source File: T6597678.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); Log log = Log.instance(context); PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE); PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING); PrintWriter errOut = log.getWriter(Log.WriterKind.ERROR); Locale locale = context.get(Locale.class); JavacMessages messages = context.get(JavacMessages.messagesKey); round++; if (round == 1) { initialLocale = locale; initialMessages = messages; initialNoteWriter = noteOut; initialWarnWriter = warnOut; initialErrWriter = errOut; String writerStringOpt = options.get("WriterString").intern(); checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt); checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt); checkEqual("errWriterString", errOut.toString().intern(), writerStringOpt); } else { checkEqual("locale", locale, initialLocale); checkEqual("messages", messages, initialMessages); checkEqual("noteWriter", noteOut, initialNoteWriter); checkEqual("warnWriter", warnOut, initialWarnWriter); checkEqual("errWriter", errOut, initialErrWriter); } return true; }
Example 10
Source File: Messager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** Get the current messager, which is also the compiler log. */ public static Messager instance0(Context context) { Log instance = context.get(logKey); if (instance == null || !(instance instanceof Messager)) throw new InternalError("no messager instance!"); return (Messager)instance; }
Example 11
Source File: DPrinter.java From hottub with GNU General Public License v2.0 | 5 votes |
public static DPrinter instance(Context context) { DPrinter dp = context.get(DPrinter.class); if (dp == null) { dp = new DPrinter(context); } return dp; }
Example 12
Source File: JNIWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** Construct a class writer, given an options table. */ private JNIWriter(Context context) { context.put(jniWriterKey, this); fileManager = context.get(JavaFileManager.class); log = Log.instance(context); Options options = Options.instance(context); verbose = options.isSet(VERBOSE); checkAll = options.isSet("javah:full"); this.context = context; // for lazyInit() syms = Symtab.instance(context); lineSep = System.getProperty("line.separator"); }
Example 13
Source File: JNIWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** Construct a class writer, given an options table. */ private JNIWriter(Context context) { context.put(jniWriterKey, this); fileManager = context.get(JavaFileManager.class); log = Log.instance(context); Options options = Options.instance(context); verbose = options.isSet(VERBOSE); checkAll = options.isSet("javah:full"); this.context = context; // for lazyInit() }
Example 14
Source File: DPrinter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static DPrinter instance(Context context) { DPrinter dp = context.get(DPrinter.class); if (dp == null) { dp = new DPrinter(context); } return dp; }
Example 15
Source File: JavacTool.java From hottub with GNU General Public License v2.0 | 4 votes |
public JavacTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits, Context context) { try { ClientCodeWrapper ccw = ClientCodeWrapper.instance(context); if (options != null) for (String option : options) option.getClass(); // null check if (classes != null) { for (String cls : classes) if (!SourceVersion.isName(cls)) // implicit null check throw new IllegalArgumentException("Not a valid class name: " + cls); } if (compilationUnits != null) { compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check for (JavaFileObject cu : compilationUnits) { if (cu.getKind() != JavaFileObject.Kind.SOURCE) { String kindMsg = "Compilation unit is not of SOURCE kind: " + "\"" + cu.getName() + "\""; throw new IllegalArgumentException(kindMsg); } } } if (diagnosticListener != null) context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener)); if (out == null) context.put(Log.outKey, new PrintWriter(System.err, true)); else context.put(Log.outKey, new PrintWriter(out, true)); if (fileManager == null) fileManager = getStandardFileManager(diagnosticListener, null, null); fileManager = ccw.wrap(fileManager); context.put(JavaFileManager.class, fileManager); processOptions(context, fileManager, options); Main compiler = new Main("javacTask", context.get(Log.outKey)); return new JavacTaskImpl(compiler, options, context, classes, compilationUnits); } catch (ClientCodeException ex) { throw new RuntimeException(ex.getCause()); } }
Example 16
Source File: JavacTool.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public JavacTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits, Context context) { try { ClientCodeWrapper ccw = ClientCodeWrapper.instance(context); if (options != null) for (String option : options) option.getClass(); // null check if (classes != null) { for (String cls : classes) if (!SourceVersion.isName(cls)) // implicit null check throw new IllegalArgumentException("Not a valid class name: " + cls); } if (compilationUnits != null) { compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check for (JavaFileObject cu : compilationUnits) { if (cu.getKind() != JavaFileObject.Kind.SOURCE) { String kindMsg = "Compilation unit is not of SOURCE kind: " + "\"" + cu.getName() + "\""; throw new IllegalArgumentException(kindMsg); } } } if (diagnosticListener != null) context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener)); if (out == null) context.put(Log.outKey, new PrintWriter(System.err, true)); else context.put(Log.outKey, new PrintWriter(out, true)); if (fileManager == null) fileManager = getStandardFileManager(diagnosticListener, null, null); fileManager = ccw.wrap(fileManager); context.put(JavaFileManager.class, fileManager); processOptions(context, fileManager, options); Main compiler = new Main("javacTask", context.get(Log.outKey)); return new JavacTaskImpl(compiler, options, context, classes, compilationUnits); } catch (ClientCodeException ex) { throw new RuntimeException(ex.getCause()); } }
Example 17
Source File: JavacProcessingEnvironment.java From javaide with GNU General Public License v3.0 | 4 votes |
public JavaCompiler doProcessing(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols, Iterable<? extends PackageSymbol> pckSymbols) { TaskListener taskListener = context.get(TaskListener.class); log = Log.instance(context); Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>(); for (PackageSymbol psym : pckSymbols) specifiedPackages.add(psym); this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages); Round round = new Round(context, roots, classSymbols); boolean errorStatus; boolean moreToDo; do { // Run processors for round n round.run(false, false); // Processors for round n have run to completion. // Check for errors and whether there is more work to do. errorStatus = round.unrecoverableError(); moreToDo = moreToDo(); round.showDiagnostics(errorStatus || showResolveErrors); // Set up next round. // Copy mutable collections returned from filer. round = round.next( new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()), new LinkedHashMap<String,JavaFileObject>(filer.getGeneratedClasses())); // Check for errors during setup. if (round.unrecoverableError()) errorStatus = true; } while (moreToDo && !errorStatus); // run last round round.run(true, errorStatus); round.showDiagnostics(true); filer.warnIfUnclosedFiles(); warnIfUnmatchedOptions(); /* * If an annotation processor raises an error in a round, * that round runs to completion and one last round occurs. * The last round may also occur because no more source or * class files have been generated. Therefore, if an error * was raised on either of the last *two* rounds, the compile * should exit with a nonzero exit code. The current value of * errorStatus holds whether or not an error was raised on the * second to last round; errorRaised() gives the error status * of the last round. */ if (messager.errorRaised() || werror && round.warningCount() > 0 && round.errorCount() > 0) errorStatus = true; Set<JavaFileObject> newSourceFiles = new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()); roots = cleanTrees(round.roots); JavaCompiler compiler = round.finalCompiler(errorStatus); if (newSourceFiles.size() > 0) roots = roots.appendList(compiler.parseFiles(newSourceFiles)); errorStatus = errorStatus || (compiler.errorCount() > 0); // Free resources this.close(); if (taskListener != null) taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); if (errorStatus) { if (compiler.errorCount() == 0) compiler.log.nerrors++; return compiler; } if (procOnly && !foundTypeProcessors) { compiler.todo.clear(); } else { if (procOnly && foundTypeProcessors) compiler.shouldStopPolicy = CompileState.FLOW; compiler.enterTrees(roots); } return compiler; }
Example 18
Source File: JavadocClassReader.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static JavadocClassReader instance0(Context context) { ClassReader instance = context.get(classReaderKey); if (instance == null) instance = new JavadocClassReader(context); return (JavadocClassReader)instance; }
Example 19
Source File: JavacProcessingEnvironment.java From javaide with GNU General Public License v3.0 | 4 votes |
private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) { Log log = Log.instance(context); Iterator<? extends Processor> processorIterator; if (options.isSet(XPRINT)) { try { Processor processor = PrintingProcessor.class.newInstance(); processorIterator = List.of(processor).iterator(); } catch (Throwable t) { AssertionError assertError = new AssertionError("Problem instantiating PrintingProcessor."); assertError.initCause(t); throw assertError; } } else if (processors != null) { processorIterator = processors.iterator(); } else { String processorNames = options.get(PROCESSOR); 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 the "-processor" option is used, search the appropriate * path for the named class. Otherwise, use a service * provider mechanism to create the processor iterator. */ if (processorNames != null) { processorIterator = new NameProcessIterator(processorNames, processorClassLoader, log); } else { processorIterator = new ServiceIterator(processorClassLoader, log); } } catch (SecurityException e) { /* * A security exception will occur if we can't create a classloader. * Ignore the exception if, with hindsight, we didn't need it anyway * (i.e. no processor was specified either explicitly, or implicitly, * in service configuration file.) Otherwise, we cannot continue. */ processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader", e); } } discoveredProcs = new DiscoveredProcessors(processorIterator); }
Example 20
Source File: JavacTask.java From openjdk-8 with GNU General Public License v2.0 | 3 votes |
/** * Get the {@code JavacTask} for a {@code ProcessingEnvironment}. * If the compiler is being invoked using a * {@link javax.tools.JavaCompiler.CompilationTask CompilationTask}, * then that task will be returned. * @param processingEnvironment the processing environment * @return the {@code JavacTask} for a {@code ProcessingEnvironment} * @since 1.8 */ public static JavacTask instance(ProcessingEnvironment processingEnvironment) { if (!processingEnvironment.getClass().getName().equals( "com.sun.tools.javac.processing.JavacProcessingEnvironment")) throw new IllegalArgumentException(); Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext(); JavacTask t = c.get(JavacTask.class); return (t != null) ? t : new BasicJavacTask(c, true); }