Java Code Examples for com.sun.tools.javac.util.Context#put()
The following examples show how to use
com.sun.tools.javac.util.Context#put() .
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: JStructPlugin.java From junion with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 2
Source File: Infer.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected Infer(Context context) { context.put(inferKey, this); rs = Resolve.instance(context); chk = Check.instance(context); syms = Symtab.instance(context); types = Types.instance(context); diags = JCDiagnostic.Factory.instance(context); log = Log.instance(context); inferenceException = new InferenceException(diags); Options options = Options.instance(context); allowGraphInference = Source.instance(context).allowGraphInference() && options.isUnset("useLegacyInference"); dependenciesFolder = options.get("debug.dumpInferenceGraphsTo"); pendingGraphs = List.nil(); emptyContext = new InferenceContext(this, List.nil()); }
Example 3
Source File: JavacFileManager.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Create a JavacFileManager using a given context, optionally registering * it as the JavaFileManager for that context. */ public JavacFileManager(Context context, boolean register, Charset charset) { super(charset); if (register) context.put(JavaFileManager.class, this); setContext(context); }
Example 4
Source File: JavacTool.java From hottub with GNU General Public License v2.0 | 5 votes |
public JavacFileManager getStandardFileManager( DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) { Context context = new Context(); context.put(Locale.class, locale); if (diagnosticListener != null) context.put(DiagnosticListener.class, diagnosticListener); PrintWriter pw = (charset == null) ? new PrintWriter(System.err, true) : new PrintWriter(new OutputStreamWriter(System.err, charset), true); context.put(Log.outKey, pw); return new JavacFileManager(context, true, charset); }
Example 5
Source File: JavacFileManager.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Register a Context.Factory to create a JavacFileManager. */ public static void preRegister(Context context) { context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { public JavaFileManager make(Context c) { return new JavacFileManager(c, true, null); } }); }
Example 6
Source File: T7021650.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static void preRegister(Context context, final Counter counter) { context.put(Demo.class, new Context.Factory<Demo>() { public Demo make(Context c) { counter.count++; return new Demo(c); } }); }
Example 7
Source File: ClassFinder.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Construct a new class finder. */ protected ClassFinder(Context context) { context.put(classFinderKey, this); reader = ClassReader.instance(context); names = Names.instance(context); syms = Symtab.instance(context); fileManager = context.get(JavaFileManager.class); dependencies = Dependencies.instance(context); if (fileManager == null) throw new AssertionError("FileManager initialization error"); diagFactory = JCDiagnostic.Factory.instance(context); log = Log.instance(context); annotate = Annotate.instance(context); Options options = Options.instance(context); verbose = options.isSet(Option.VERBOSE); cacheCompletionFailure = options.isUnset("dev"); preferSource = "source".equals(options.get("-Xprefer")); userPathsFirst = options.isSet(Option.XXUSERPATHSFIRST); allowSigFiles = context.get(PlatformDescription.class) != null; completionFailureName = options.isSet("failcomplete") ? names.fromString(options.get("failcomplete")) : null; profile = Profile.instance(context); }
Example 8
Source File: JavaCompilerWithDeps.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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; } }); }
Example 9
Source File: JavacProcessingEnvironment.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected JavacProcessingEnvironment(Context context) { this.context = context; context.put(JavacProcessingEnvironment.class, this); log = Log.instance(context); source = Source.instance(context); diags = JCDiagnostic.Factory.instance(context); options = Options.instance(context); printProcessorInfo = options.isSet(XPRINTPROCESSORINFO); printRounds = options.isSet(XPRINTROUNDS); verbose = options.isSet(VERBOSE); lint = Lint.instance(context).isEnabled(PROCESSING); if (options.isSet(PROC, "only") || options.isSet(XPRINT)) { JavaCompiler compiler = JavaCompiler.instance(context); compiler.shouldStopPolicyIfNoError = CompileState.PROCESS; } fatalErrors = options.isSet("fatalEnterError"); showResolveErrors = options.isSet("showResolveErrors"); werror = options.isSet(WERROR); platformAnnotations = initPlatformAnnotations(); // Initialize services before any processors are initialized // in case processors use them. filer = new JavacFiler(context); messager = new JavacMessager(context, this); elementUtils = JavacElements.instance(context); typeUtils = JavacTypes.instance(context); processorOptions = initProcessorOptions(context); unmatchedProcessorOptions = initUnmatchedProcessorOptions(); messages = JavacMessages.instance(context); taskListener = MultiTaskListener.instance(context); initProcessorClassLoader(); }
Example 10
Source File: TypeAnnotations.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected TypeAnnotations(Context context) { context.put(typeAnnosKey, this); names = Names.instance(context); log = Log.instance(context); syms = Symtab.instance(context); annotate = Annotate.instance(context); attr = Attr.instance(context); Options options = Options.instance(context); }
Example 11
Source File: JavapFileManager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static JavapFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) { Context javac_context = new Context(); if (dl != null) javac_context.put(DiagnosticListener.class, dl); javac_context.put(com.sun.tools.javac.util.Log.outKey, log); return new JavapFileManager(javac_context, null); }
Example 12
Source File: JavahFileManager.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static JavahFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) { Context javac_context = new Context(); if (dl != null) javac_context.put(DiagnosticListener.class, dl); javac_context.put(com.sun.tools.javac.util.Log.outKey, log); return new JavahFileManager(javac_context, null); }
Example 13
Source File: JavadocEnter.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void preRegister(Context context) { context.put(enterKey, new Context.Factory<Enter>() { public Enter make(Context c) { return new JavadocEnter(c); } }); }
Example 14
Source File: GenStubs.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
ImportCleaner(JavaFileManager fm) { // ImportCleaner itself doesn't require a filemanager, but instantiating // a TreeMaker does, indirectly (via ClassReader, sigh) Context c = new Context(); c.put(JavaFileManager.class, fm); m = TreeMaker.instance(c); }
Example 15
Source File: StringConcat.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected StringConcat(Context context) { context.put(concatKey, this); gen = Gen.instance(context); syms = Symtab.instance(context); types = Types.instance(context); names = Names.instance(context); make = TreeMaker.instance(context); rs = Resolve.instance(context); sbAppends = new HashMap<>(); }
Example 16
Source File: CacheFSInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Register a Context.Factory to create a CacheFSInfo. */ public static void preRegister(Context context) { context.put(FSInfo.class, (Factory<FSInfo>)c -> { FSInfo instance = new CacheFSInfo(); c.put(FSInfo.class, instance); return instance; }); }
Example 17
Source File: ManParserFactory.java From manifold with Apache License 2.0 | 5 votes |
public static ScannerFactory instance( Context ctx, ManParserFactory parserFactory ) { ScannerFactory scannerFactory = ctx.get( scannerFactoryKey ); if( !(scannerFactory instanceof ManScannerFactory) ) { ctx.put( scannerFactoryKey, (ScannerFactory)null ); scannerFactory = new ManScannerFactory( ctx, parserFactory ); } return scannerFactory; }
Example 18
Source File: DeferredLintHandler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
protected DeferredLintHandler(Context context) { context.put(deferredLintHandlerKey, this); this.currentPos = IMMEDIATE_POSITION; }
Example 19
Source File: ParserTest.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
public void test1() { final String src = "package com.duy;\n" + "\n" + "import java.util.ArrayList;\n" + "/** * Created by Duy on 17-Jul-17. */\n" + "public class Main {\n" + " public static void main(String[] args) {\n" + " ArrayList list = new ArrayList();\n" + " for (int i = 0; i < 1000; i++) {\n" + " list.add(i);\n" + " }\n" + " }\n" + "\n"; Context context = new Context(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); context.put(DiagnosticListener.class, diagnostics); Options.instance(context).put("allowStringFolding", "false"); JCTree.JCCompilationUnit unit; JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8); try { fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.<File>of()); } catch (IOException e) { // impossible throw new IOError(e); } SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return src; } }; Log.instance(context).useSource(source); ParserFactory parserFactory = ParserFactory.instance(context); Parser parser = parserFactory.newParser( src, /*keepDocComments=*/ true, /*keepEndPos=*/ true, /*keepLineMap=*/ true); unit = parser.parseCompilationUnit(); System.out.println(unit.getImports()); }
Example 20
Source File: DeferredLintHandler.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
protected DeferredLintHandler(Context context) { context.put(deferredLintHandlerKey, this); this.currentPos = IMMEDIATE_POSITION; }