Java Code Examples for com.sun.tools.javac.code.Symtab#instance()
The following examples show how to use
com.sun.tools.javac.code.Symtab#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: MakeLiteralTest.java From openjdk-8-source 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 2
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 3
Source File: TransTypes.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected TransTypes(Context context) { context.put(transTypesKey, this); compileStates = CompileStates.instance(context); names = Names.instance(context); log = Log.instance(context); syms = Symtab.instance(context); enter = Enter.instance(context); bridgeSpans = new HashMap<>(); types = Types.instance(context); make = TreeMaker.instance(context); resolve = Resolve.instance(context); Source source = Source.instance(context); allowInterfaceBridges = source.allowDefaultMethods(); allowGraphInference = source.allowGraphInference(); annotate = Annotate.instance(context); attr = Attr.instance(context); }
Example 4
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 5
Source File: TestInvokeDynamic.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void run() { int id = checkCount.incrementAndGet(); JavaSource source = new JavaSource(id); JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, fm.get(), dc, Arrays.asList("-g"), null, Arrays.asList(source)); Context context = ct.getContext(); Symtab syms = Symtab.instance(context); Names names = Names.instance(context); Types types = Types.instance(context); ct.addTaskListener(new Indifier(syms, names, types)); try { ct.generate(); } catch (Throwable t) { t.printStackTrace(); throw new AssertionError( String.format("Error thrown when compiling following code\n%s", source.source)); } if (dc.diagFound) { throw new AssertionError( String.format("Diags found when compiling following code\n%s\n\n%s", source.source, dc.printDiags())); } verifyBytecode(id); }
Example 6
Source File: MakeQualIdent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String... args) throws Exception { JavacTool tool = JavacTool.create(); JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, null); Context ctx = ((JavacTaskImpl)task).getContext(); TreeMaker treeMaker = TreeMaker.instance(ctx); Symtab syms = Symtab.instance(ctx); String stringTree = printTree(treeMaker.QualIdent(syms.stringType.tsym)); if (!"java.lang.String".equals(stringTree)) { throw new IllegalStateException(stringTree); } }
Example 7
Source File: T6400303.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String... args) { javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null); Symtab syms = Symtab.instance(task.getContext()); task.ensureEntered(); JavaCompiler compiler = JavaCompiler.instance(task.getContext()); try { compiler.resolveIdent(syms.unnamedModule, "Test$1").complete(); } catch (CompletionFailure ex) { System.err.println("Got expected completion failure: " + ex.getLocalizedMessage()); return; } throw new AssertionError("No error reported"); }
Example 8
Source File: TestInvokeDynamic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void doWork() throws IOException { ComboTask comboTask = newCompilationTask() .withOption("-g") .withSourceFromTemplate(source_template); JavacTaskImpl ct = (JavacTaskImpl)comboTask.getTask(); Context context = ct.getContext(); Symtab syms = Symtab.instance(context); Names names = Names.instance(context); Types types = Types.instance(context); ct.addTaskListener(new Indifier(syms, names, types)); verifyBytecode(comboTask.generate()); }
Example 9
Source File: JNIWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void lazyInit() { if (types == null) types = Types.instance(context); if (syms == null) syms = Symtab.instance(context); }
Example 10
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected JavacElements(Context context) { context.put(JavacElements.class, this); javaCompiler = JavaCompiler.instance(context); syms = Symtab.instance(context); modules = Modules.instance(context); names = Names.instance(context); types = Types.instance(context); enter = Enter.instance(context); resolve = Resolve.instance(context); JavacTask t = context.get(JavacTask.class); javacTaskImpl = t instanceof JavacTaskImpl ? (JavacTaskImpl) t : null; log = Log.instance(context); Source source = Source.instance(context); allowModules = source.allowModules(); }
Example 11
Source File: NBEnter.java From netbeans with Apache License 2.0 | 5 votes |
public NBEnter(Context context) { super(context); cancelService = CancelService.instance(context); syms = Symtab.instance(context); JavaCompiler c = JavaCompiler.instance(context); compiler = c instanceof NBJavaCompiler ? (NBJavaCompiler) c : null; }
Example 12
Source File: CompileModulePatchTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Symtab syms = Symtab.instance(((JavacProcessingEnvironment) processingEnv).getContext()); Elements elements = processingEnv.getElementUtils(); ModuleElement unnamedModule = syms.unnamedModule; ModuleElement mModule = elements.getModuleElement("m"); assertNonNull("mModule found", mModule); assertNonNull("src.Src from m", elements.getTypeElement(mModule, "src.Src")); assertNull("cp.CP not from m", elements.getTypeElement(mModule, "cp.CP")); assertNull("src.Src not from unnamed", elements.getTypeElement(unnamedModule, "src.Src")); assertNonNull("cp.CP from unnamed", elements.getTypeElement(unnamedModule, "cp.CP")); return false; }
Example 13
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Construct a new class reader. */ protected ClassReader(Context context) { context.put(classReaderKey, this); annotate = Annotate.instance(context); names = Names.instance(context); syms = Symtab.instance(context); types = Types.instance(context); fileManager = context.get(JavaFileManager.class); if (fileManager == null) throw new AssertionError("FileManager initialization error"); diagFactory = JCDiagnostic.Factory.instance(context); log = Log.instance(context); Options options = Options.instance(context); verbose = options.isSet(Option.VERBOSE); Source source = Source.instance(context); allowSimplifiedVarargs = source.allowSimplifiedVarargs(); allowModules = source.allowModules(); saveParameterNames = options.isSet(PARAMETERS); profile = Profile.instance(context); typevars = WriteableScope.create(syms.noSymbol); lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE); initAttributeReaders(); }
Example 14
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 15
Source File: JavacAST.java From EasyMPermission with MIT License | 5 votes |
/** * Creates a new JavacAST of the provided Compilation Unit. * * @param messager A Messager for warning and error reporting. * @param context A Context object for interfacing with the compiler. * @param top The compilation unit, which serves as the top level node in the tree to be built. */ public JavacAST(Messager messager, Context context, JCCompilationUnit top) { super(sourceName(top), packageDeclaration(top), new JavacImportList(top)); setTop(buildCompilationUnit(top)); this.context = context; this.messager = messager; this.log = Log.instance(context); this.elements = JavacElements.instance(context); this.treeMaker = new JavacTreeMaker(TreeMaker.instance(context)); this.symtab = Symtab.instance(context); this.javacTypes = JavacTypes.instance(context); clearChanged(); }
Example 16
Source File: TypeHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
protected TypeHarness() { Context ctx = new Context(); JavacFileManager.preRegister(ctx); types = Types.instance(ctx); chk = Check.instance(ctx); predef = Symtab.instance(ctx); names = Names.instance(ctx); fac = new Factory(); }
Example 17
Source File: TestResolveIdent.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IOException { javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null); JavaCompiler compiler = JavaCompiler.instance(task.getContext()); Symtab syms = Symtab.instance(task.getContext()); task.ensureEntered(); System.out.println(compiler.resolveIdent(syms.unnamedModule, getDeprecatedClass().getCanonicalName())); }
Example 18
Source File: ClassReader.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * Construct a new class reader, optionally treated as the * definitive classreader for this invocation. */ protected ClassReader(Context context, boolean definitive) { if (definitive) context.put(classReaderKey, this); names = Names.instance(context); syms = Symtab.instance(context); types = Types.instance(context); fileManager = context.get(JavaFileManager.class); if (fileManager == null) throw new AssertionError("FileManager initialization error"); diagFactory = JCDiagnostic.Factory.instance(context); init(syms, definitive); log = Log.instance(context); Options options = Options.instance(context); annotate = Annotate.instance(context); verbose = options.isSet(VERBOSE); checkClassFile = options.isSet("-checkclassfile"); Source source = Source.instance(context); allowGenerics = source.allowGenerics(); allowVarargs = source.allowVarargs(); allowAnnotations = source.allowAnnotations(); allowSimplifiedVarargs = source.allowSimplifiedVarargs(); saveParameterNames = options.isSet("save-parameter-names"); cacheCompletionFailure = options.isUnset("dev"); preferSource = "source".equals(options.get("-Xprefer")); completionFailureName = options.isSet("failcomplete") ? names.fromString(options.get("failcomplete")) : null; typevars = new Scope(syms.noSymbol); lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE); initAttributeReaders(); }
Example 19
Source File: JNIWriter.java From TencentKona-8 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 20
Source File: ClassReader.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** Construct a new class reader, optionally treated as the * definitive classreader for this invocation. */ protected ClassReader(Context context, boolean definitive) { if (definitive) context.put(classReaderKey, this); names = Names.instance(context); syms = Symtab.instance(context); types = Types.instance(context); fileManager = context.get(JavaFileManager.class); if (fileManager == null) throw new AssertionError("FileManager initialization error"); diagFactory = JCDiagnostic.Factory.instance(context); init(syms, definitive); log = Log.instance(context); Options options = Options.instance(context); annotate = Annotate.instance(context); verbose = options.isSet(VERBOSE); checkClassFile = options.isSet("-checkclassfile"); Source source = Source.instance(context); allowGenerics = source.allowGenerics(); allowVarargs = source.allowVarargs(); allowAnnotations = source.allowAnnotations(); allowSimplifiedVarargs = source.allowSimplifiedVarargs(); saveParameterNames = options.isSet("save-parameter-names"); cacheCompletionFailure = options.isUnset("dev"); preferSource = "source".equals(options.get("-Xprefer")); profile = Profile.instance(context); completionFailureName = options.isSet("failcomplete") ? names.fromString(options.get("failcomplete")) : null; typevars = new Scope(syms.noSymbol); lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE); initAttributeReaders(); }