com.sun.tools.javac.util.Context Java Examples
The following examples show how to use
com.sun.tools.javac.util.Context.
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: JavadocTool.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Construct a new javadoc tool. */ public static JavadocTool make0(Context context) { Messager messager = null; try { // force the use of Javadoc's class reader JavadocClassReader.preRegister(context); // force the use of Javadoc's own enter phase JavadocEnter.preRegister(context); // force the use of Javadoc's own member enter phase JavadocMemberEnter.preRegister(context); // force the use of Javadoc's own todo phase JavadocTodo.preRegister(context); // force the use of Messager as a Log messager = Messager.instance0(context); return new JavadocTool(context); } catch (CompletionFailure ex) { messager.error(Position.NOPOS, ex.getMessage()); return null; } }
Example #2
Source File: DocEnv.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Constructor * * @param context Context for this javadoc instance. */ protected DocEnv(Context context) { context.put(docEnvKey, this); this.context = context; messager = Messager.instance0(context); syms = Symtab.instance(context); reader = JavadocClassReader.instance0(context); enter = JavadocEnter.instance0(context); names = Names.instance(context); externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable")); chk = Check.instance(context); types = Types.instance(context); fileManager = context.get(JavaFileManager.class); if (fileManager instanceof JavacFileManager) { ((JavacFileManager)fileManager).setSymbolFileEnabled(false); } // Default. Should normally be reset with setLocale. this.doclocale = new DocLocale(this, "", breakiterator); source = Source.instance(context); }
Example #3
Source File: T7018098.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); FSInfo fsInfo = context.get(FSInfo.class); round++; if (round == 1) { boolean expect = Boolean.valueOf(options.get("expect")); checkEqual("cache result", fsInfo.isDirectory(testDir.toPath()), expect); initialFSInfo = fsInfo; } else { checkEqual("fsInfo", fsInfo, initialFSInfo); } return true; }
Example #4
Source File: Start.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public Start(Context context) { context.getClass(); // null check this.context = 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.outKey); messager = (out == null) ? new Messager(context, javadocName) : new Messager(context, javadocName, out, out, out); } }
Example #5
Source File: Start.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public Start(Context context) { context.getClass(); // null check this.context = 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.outKey); messager = (out == null) ? new Messager(context, javadocName) : new Messager(context, javadocName, out, out, out); } }
Example #6
Source File: GetTask_FileManagerTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Verify that an alternate file manager can be specified: * in this case, a PathFileManager. */ @Test public void testFileManager() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); PathFileManager fm = new JavacPathFileManager(new Context(), false, null); Path outDir = getOutDir().toPath(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, null, null, files); if (t.call()) { System.err.println("task succeeded"); checkFiles(outDir, standardExpectFiles); } else { throw new Exception("task failed"); } }
Example #7
Source File: MakeLiteralTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
void run() throws Exception { Context context = new Context(); JavacFileManager.preRegister(context); Symtab syms = Symtab.instance(context); maker = TreeMaker.instance(context); types = Types.instance(context); test("abc", CLASS, syms.stringType, "abc"); test(Boolean.FALSE, BOOLEAN, syms.booleanType, Integer.valueOf(0)); test(Boolean.TRUE, BOOLEAN, syms.booleanType, Integer.valueOf(1)); test(Byte.valueOf((byte) 1), BYTE, syms.byteType, Byte.valueOf((byte) 1)); test(Character.valueOf('a'), CHAR, syms.charType, Integer.valueOf('a')); test(Double.valueOf(1d), DOUBLE, syms.doubleType, Double.valueOf(1d)); test(Float.valueOf(1f), FLOAT, syms.floatType, Float.valueOf(1f)); test(Integer.valueOf(1), INT, syms.intType, Integer.valueOf(1)); test(Long.valueOf(1), LONG, syms.longType, Long.valueOf(1)); test(Short.valueOf((short) 1), SHORT, syms.shortType, Short.valueOf((short) 1)); if (errors > 0) throw new Exception(errors + " errors found"); }
Example #8
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private LambdaToMethod(Context context) { context.put(unlambdaKey, this); diags = JCDiagnostic.Factory.instance(context); log = Log.instance(context); lower = Lower.instance(context); names = Names.instance(context); syms = Symtab.instance(context); rs = Resolve.instance(context); operators = Operators.instance(context); make = TreeMaker.instance(context); types = Types.instance(context); transTypes = TransTypes.instance(context); analyzer = new LambdaAnalyzerPreprocessor(); Options options = Options.instance(context); dumpLambdaToMethodStats = options.isSet("debug.dumpLambdaToMethodStats"); attr = Attr.instance(context); forceSerializable = options.isSet("forceSerializable"); }
Example #9
Source File: JavacProcessingEnvironment.java From hottub with GNU General Public License v2.0 | 6 votes |
/** 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 #10
Source File: JavacProcessingEnvironment.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** Create the first round. */ Round(Context context, List<JCCompilationUnit> roots, List<ClassSymbol> classSymbols, Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { this(context, 1, 0, 0, deferredDiagnosticHandler); this.roots = roots; genClassFiles = new HashMap<String,JavaFileObject>(); compiler.todo.clear(); // free the compiler's resources // The reverse() in the following line is to maintain behavioural // compatibility with the previous revision of the code. Strictly speaking, // it should not be necessary, but a javah golden file test fails without it. topLevelClasses = getTopLevelClasses(roots).prependList(classSymbols.reverse()); packageInfoFiles = getPackageInfoFiles(roots); findAnnotationsPresent(); }
Example #11
Source File: JavacFileManager.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Set the context for JavacFileManager. */ @Override public void setContext(Context context) { super.setContext(context); fsInfo = FSInfo.instance(context); contextUseOptimizedZip = options.getBoolean("useOptimizedZip", true); if (contextUseOptimizedZip) zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); mmappedIO = options.isSet("mmappedIO"); symbolFileEnabled = !options.isSet("ignore.symbol.file"); String sf = options.get("sortFiles"); if (sf != null) { sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD); } }
Example #12
Source File: T7018098.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); FSInfo fsInfo = context.get(FSInfo.class); round++; if (round == 1) { boolean expect = Boolean.valueOf(options.get("expect")); checkEqual("cache result", fsInfo.isDirectory(testDir), expect); initialFSInfo = fsInfo; } else { checkEqual("fsInfo", fsInfo, initialFSInfo); } return true; }
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: JavacFileManager.java From java-n-IDE-for-Android with Apache License 2.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 #15
Source File: Operators.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected Operators(Context context) { context.put(operatorsKey, this); syms = Symtab.instance(context); names = Names.instance(context); log = Log.instance(context); types = Types.instance(context); noOpSymbol = new OperatorSymbol(names.empty, Type.noType, -1, syms.noSymbol); initOperatorNames(); initUnaryOperators(); initBinaryOperators(); }
Example #16
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 #17
Source File: CompileTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void test(String[] opts, String className) throws Exception { count++; System.err.println("Test " + count + " " + Arrays.asList(opts) + " " + className); Path testSrcDir = Paths.get(System.getProperty("test.src")); Path testClassesDir = Paths.get(System.getProperty("test.classes")); Path classes = Files.createDirectory(Paths.get("classes." + count)); Context ctx = new Context(); PathFileManager fm = new JavacPathFileManager(ctx, true, null); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); List<String> options = new ArrayList<String>(); options.addAll(Arrays.asList(opts)); options.addAll(Arrays.asList( "-verbose", "-XDverboseCompilePolicy", "-d", classes.toString(), "-g" )); Iterable<? extends JavaFileObject> compilationUnits = fm.getJavaFileObjects(testSrcDir.resolve(className + ".java")); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); JavaCompiler.CompilationTask t = compiler.getTask(out, fm, null, options, null, compilationUnits); boolean ok = t.call(); System.err.println(sw.toString()); if (!ok) { throw new Exception("compilation failed"); } File expect = new File("classes." + count + "/" + className + ".class"); if (!expect.exists()) throw new Exception("expected file not found: " + expect); // Note that we explicitly specify -g for compiling both the actual class and the expected class. // This isolates the expected class from javac options that might be given to jtreg. long expectedSize = new File(testClassesDir.toString(), className + ".class").length(); long actualSize = expect.length(); if (expectedSize != actualSize) throw new Exception("wrong size found: " + actualSize + "; expected: " + expectedSize); }
Example #18
Source File: T6877206.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) { Context ctx = new Context(); Options options = Options.instance(ctx); options.put("useOptimizedZip", Boolean.toString(useOptimizedZip)); if (!useSymbolFile) { options.put("ignore.symbol.file", "true"); } return new JavacFileManager(ctx, false, null); }
Example #19
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 #20
Source File: Lint.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected Lint(Context context) { // initialize values according to the lint options Options options = Options.instance(context); values = EnumSet.noneOf(LintCategory.class); for (Map.Entry<String, LintCategory> e: map.entrySet()) { if (options.lint(e.getKey())) values.add(e.getValue()); } suppressedValues = EnumSet.noneOf(LintCategory.class); context.put(lintKey, this); augmentor = new AugmentVisitor(context); }
Example #21
Source File: ManResolve.java From manifold with Apache License 2.0 | 5 votes |
private void reassignEarlyHolders8( Context context ) { ReflectUtil.field( Attr.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( DeferredAttr.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( Check.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( Infer.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( Flow.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( Lower.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( Gen.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( Annotate.instance( context ), RESOLVE_FIELD ).set( this ); ReflectUtil.field( JavacTrees.instance( context ), "resolve" ).set( this ); ReflectUtil.field( TransTypes.instance( context ), "resolve" ).set( this ); }
Example #22
Source File: ClassWriter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Construct a class writer, given an options table. */ protected ClassWriter(Context context) { context.put(classWriterKey, this); log = Log.instance(context); names = Names.instance(context); options = Options.instance(context); target = Target.instance(context); source = Source.instance(context); types = Types.instance(context); fileManager = context.get(JavaFileManager.class); signatureGen = new CWSignatureGenerator(types); verbose = options.isSet(VERBOSE); genCrt = options.isSet(XJCOV); debugstackmap = options.isSet("debug.stackmap"); emitSourceFile = options.isUnset(G_CUSTOM) || options.isSet(G_CUSTOM, "source"); String modifierFlags = options.get("debug.dumpmodifiers"); if (modifierFlags != null) { dumpClassModifiers = modifierFlags.indexOf('c') != -1; dumpFieldModifiers = modifierFlags.indexOf('f') != -1; dumpInnerClassModifiers = modifierFlags.indexOf('i') != -1; dumpMethodModifiers = modifierFlags.indexOf('m') != -1; } }
Example #23
Source File: JavacFileManager.java From jdk8u60 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 #24
Source File: PackageProcessor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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 #25
Source File: CompletenessAnalyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
CompletenessAnalyzer(JShell proc) { this.proc = proc; Context context = new Context(); Log log = CaLog.createLog(context); context.put(Log.class, log); context.put(Source.class, Source.JDK1_9); scannerFactory = ScannerFactory.instance(context); }
Example #26
Source File: JNIWriter.java From hottub 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 #27
Source File: GetTask_FileManagerTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Verify that exceptions from a bad file manager are thrown as expected. */ @Test public void testBadFileManager() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); PathFileManager fm = new JavacPathFileManager(new Context(), false, null) { @Override public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException { throw new UnexpectedError(); } }; Path outDir = getOutDir().toPath(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, null, null, files); try { t.call(); error("call completed without exception"); } catch (RuntimeException e) { Throwable c = e.getCause(); if (c.getClass() == UnexpectedError.class) System.err.println("exception caught as expected: " + c); else throw e; } }
Example #28
Source File: T7021650.java From openjdk-jdk8u-backup 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 #29
Source File: T6877206.java From hottub with GNU General Public License v2.0 | 5 votes |
JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) { Context ctx = new Context(); Options options = Options.instance(ctx); options.put("useOptimizedZip", Boolean.toString(useOptimizedZip)); if (!useSymbolFile) { options.put("ignore.symbol.file", "true"); } return new JavacFileManager(ctx, false, null); }
Example #30
Source File: JavadocTool.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public DocumentationTask getTask( Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Class<?> docletClass, Iterable<String> options, Iterable<? extends JavaFileObject> compilationUnits) { Context context = new Context(); return getTask(out, fileManager, diagnosticListener, docletClass, options, compilationUnits, context); }