Java Code Examples for com.sun.tools.javac.model.JavacTypes#instance()
The following examples show how to use
com.sun.tools.javac.model.JavacTypes#instance() .
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: TestSymtabItems.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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; //both noModule and unnamedModule claim the unnamed package, ignore noModule for now: if (f.getName().equals("noModule")) continue; f.setAccessible(true); 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 2
Source File: ElementsService.java From netbeans with Apache License 2.0 | 5 votes |
protected ElementsService(Context context) { context.put(KEY, this); jctypes = com.sun.tools.javac.code.Types.instance(context); names = Names.instance(context); types = JavacTypes.instance(context); allowDefaultMethods = SourceLevelUtils.allowDefaultMethods(Source.instance(context)); }
Example 3
Source File: TreeFactory.java From netbeans with Apache License 2.0 | 5 votes |
protected TreeFactory(Context context) { context.put(contextKey, this); model = ASTService.instance(context); names = Names.instance(context); classReader = ClassReader.instance(context); make = com.sun.tools.javac.tree.TreeMaker.instance(context); docMake = com.sun.tools.javac.tree.DocTreeMaker.instance(context); elements = JavacElements.instance(context); types = JavacTypes.instance(context); chs = CommentHandlerService.instance(context); make.toplevel = null; }
Example 4
Source File: JavacProcessingEnvironment.java From javaide with GNU General Public License v3.0 | 5 votes |
public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) { this.context = context; 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); procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT); fatalErrors = options.isSet("fatalEnterError"); showResolveErrors = options.isSet("showResolveErrors"); werror = options.isSet(WERROR); platformAnnotations = initPlatformAnnotations(); foundTypeProcessors = false; // 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); initProcessorIterator(context, processors); }
Example 5
Source File: JNIWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
private void lazyInit() { if (mangler == null) { elements = JavacElements.instance(context); types = JavacTypes.instance(context); mangler = new Mangle(elements, types); } }
Example 6
Source File: ScopeTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void verifyLambdaScopeCorrect(final String packageClause) throws Exception { JavacTool tool = JavacTool.create(); JavaFileObject source = new SimpleJavaFileObject(URI.create("mem://Test.java"), Kind.SOURCE) { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return packageClause + SOURCE_CODE; } @Override public boolean isNameCompatible(String simpleName, Kind kind) { return true; } }; Iterable<? extends JavaFileObject> fos = Collections.singletonList(source); JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, fos); final Types types = JavacTypes.instance(((JavacTaskImpl) task).getContext()); final Trees trees = Trees.instance(task); CompilationUnitTree cu = task.parse().iterator().next(); task.analyze(); new TreePathScanner<Void, Void>() { @Override public Void visitMemberSelect(MemberSelectTree node, Void p) { if (node.getIdentifier().contentEquals("correct")) { TypeMirror xType = trees.getTypeMirror(new TreePath(getCurrentPath(), node.getExpression())); Scope scope = trees.getScope(getCurrentPath()); for (Element l : scope.getLocalElements()) { if (!l.getSimpleName().contentEquals("x")) continue; if (!types.isSameType(xType, l.asType())) { throw new IllegalStateException("Incorrect variable type in scope: " + l.asType() + "; should be: " + xType); } } } return super.visitMemberSelect(node, p); } }.scan(cu, null); }
Example 7
Source File: TestSymtabItems.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 8
Source File: Transformer.java From netbeans with Apache License 2.0 | 5 votes |
/** * Initialize and associate this Query instance with the * specified QueryEnvironment. */ public void attach(Context context, WorkingCopy copy) { make = copy.getTreeMaker(); types = JavacTypes.instance(context); commentHandler = CommentHandlerService.instance(context); model = ASTService.instance(context); this.copy = copy; }
Example 9
Source File: JavacProcessingEnvironment.java From hottub 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: JNIWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void lazyInit() { if (mangler == null) { elements = JavacElements.instance(context); types = JavacTypes.instance(context); mangler = new Mangle(elements, types); } }
Example 11
Source File: JavacProcessingEnvironment.java From openjdk-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 12
Source File: ScopeTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static void verifyLambdaScopeCorrect(final String packageClause) throws Exception { JavacTool tool = JavacTool.create(); JavaFileObject source = new SimpleJavaFileObject(URI.create("mem://Test.java"), Kind.SOURCE) { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return packageClause + SOURCE_CODE; } @Override public boolean isNameCompatible(String simpleName, Kind kind) { return true; } }; Iterable<? extends JavaFileObject> fos = Collections.singletonList(source); JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, fos); final Types types = JavacTypes.instance(((JavacTaskImpl) task).getContext()); final Trees trees = Trees.instance(task); CompilationUnitTree cu = task.parse().iterator().next(); task.analyze(); new TreePathScanner<Void, Void>() { @Override public Void visitMemberSelect(MemberSelectTree node, Void p) { if (node.getIdentifier().contentEquals("correct")) { TypeMirror xType = trees.getTypeMirror(new TreePath(getCurrentPath(), node.getExpression())); Scope scope = trees.getScope(getCurrentPath()); for (Element l : scope.getLocalElements()) { if (!l.getSimpleName().contentEquals("x")) continue; if (!types.isSameType(xType, l.asType())) { throw new IllegalStateException("Incorrect variable type in scope: " + l.asType() + "; should be: " + xType); } } } return super.visitMemberSelect(node, p); } }.scan(cu, null); }
Example 13
Source File: JavacProcessingEnvironment.java From openjdk-jdk8u-backup 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 14
Source File: JavacProcessingEnvironment.java From jdk8u60 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 15
Source File: TestSymtabItems.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 16
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 17
Source File: BasicJavacTask.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public Types getTypes() { return JavacTypes.instance(context); }
Example 18
Source File: BasicJavacTask.java From hottub with GNU General Public License v2.0 | 4 votes |
@Override public Types getTypes() { return JavacTypes.instance(context); }
Example 19
Source File: BasicJavacTask.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public Types getTypes() { return JavacTypes.instance(context); }
Example 20
Source File: BasicJavacTask.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public Types getTypes() { return JavacTypes.instance(context); }