Java Code Examples for com.sun.tools.javac.code.Symbol#complete()
The following examples show how to use
com.sun.tools.javac.code.Symbol#complete() .
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: BadClassfile.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 2
Source File: BadClassfile.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 3
Source File: BadClassfile.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 4
Source File: BadClassfile.java From hottub with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 5
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns a symbol given the type's or package's canonical name, * or null if the name isn't found. */ private <S extends Symbol> S nameToSymbol(ModuleSymbol module, String nameStr, Class<S> clazz) { Name name = names.fromString(nameStr); // First check cache. Symbol sym = (clazz == ClassSymbol.class) ? syms.getClass(module, name) : syms.lookupPackage(module, name); try { if (sym == null) sym = javaCompiler.resolveIdent(module, nameStr); sym.complete(); return (sym.kind != ERR && sym.exists() && clazz.isInstance(sym) && name.equals(sym.getQualifiedName())) ? clazz.cast(sym) : null; } catch (CompletionFailure e) { return null; } }
Example 6
Source File: BadClassfile.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 7
Source File: BadClassfile.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 8
Source File: BadClassfile.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 9
Source File: BadClassfile.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void test(String classname, String expected) throws Exception { File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); ClassFile cf = ClassFile.read(classfile); cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, cf.this_class, cf.super_class, cf.interfaces, cf.fields, cf.methods, cf.attributes); new ClassWriter().write(cf, classfile); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); Symtab syms = Symtab.instance(task.getContext()); task.ensureEntered(); try { Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(syms.unnamedModule, classname); clazz.complete(); } catch (BadClassFile f) { JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; assertEquals(expected, embeddedDiag.getCode()); assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); } }
Example 10
Source File: GenericTypeWellFormednessTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }
Example 11
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@DefinedBy(Api.LANGUAGE_MODEL) public boolean isDeprecated(Element e) { Symbol sym = cast(Symbol.class, e); sym.complete(); return sym.isDeprecated(); }
Example 12
Source File: GenericTypeWellFormednessTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }
Example 13
Source File: GenericTypeWellFormednessTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }
Example 14
Source File: GenericTypeWellFormednessTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }
Example 15
Source File: NecessaryEvilUtil.java From manifold with Apache License 2.0 | 4 votes |
public static void openModule( Context context, String moduleName ) { try { Symbol moduleToOpen = (Symbol)ReflectUtil.method( Symtab.instance( context ), "getModule", Name.class ) .invoke( Names.instance( context ).fromString( moduleName ) ); if( moduleToOpen == null ) { // not modular java 9+ return; } moduleToOpen.complete(); Set<Symbol> rootModules = (Set<Symbol>)ReflectUtil.field( ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.Modules" ), "instance", Context.class ).invokeStatic( context ), "allModules" ).get(); for( Symbol rootModule: rootModules ) { rootModule.complete(); List<Object> requires = (List<Object>)ReflectUtil.field( rootModule, "requires" ).get(); List<Object> newRequires = new ArrayList( requires ); Object addedRequires = ReflectUtil.constructor( "com.sun.tools.javac.code.Directive$RequiresDirective", ReflectUtil.type( "com.sun.tools.javac.code.Symbol$ModuleSymbol" ) ).newInstance( moduleToOpen ); newRequires.add( addedRequires ); requires = com.sun.tools.javac.util.List.from( newRequires ); ReflectUtil.field( rootModule, "requires" ).set( requires ); List<Object> exports = new ArrayList<>( (Collection)ReflectUtil.field( moduleToOpen, "exports" ).get() ); for( Symbol pkg : (Iterable<Symbol>)ReflectUtil.field( moduleToOpen, "enclosedPackages" ).get() ) { if( pkg instanceof Symbol.PackageSymbol ) { //System.err.println( "PACKAGE: " + pkg ); Object exp = ReflectUtil.constructor( "com.sun.tools.javac.code.Directive$ExportsDirective", Symbol.PackageSymbol.class, com.sun.tools.javac.util.List.class ).newInstance( pkg, com.sun.tools.javac.util.List.of( rootModule ) ); exports.add( exp ); ((Map)ReflectUtil.field( rootModule, "visiblePackages" ).get()).put( ((Symbol.PackageSymbol)pkg).fullname, pkg ); } } ReflectUtil.field( moduleToOpen, "exports" ).set( com.sun.tools.javac.util.List.from( exports ) ); Set readModules = (Set)ReflectUtil.field( moduleToOpen, "readModules" ).get(); readModules.add( rootModule ); ReflectUtil.field( moduleToOpen, "readModules" ).set( readModules ); } } catch( Throwable e ) { System.err.println( "Failed to reflectively add-exports " + moduleName + "/* to root module[s], you must add the following argument to jave.exe:\n" + " --add-exports=" + moduleName + "/*=<root-module>\n" ); throw new RuntimeException( e ); } }
Example 16
Source File: GenericTypeWellFormednessTest.java From hottub with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }
Example 17
Source File: GenericTypeWellFormednessTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }
Example 18
Source File: GenericTypeWellFormednessTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }
Example 19
Source File: GenericTypeWellFormednessTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
Type NumberType() { Symbol s = box(predef.intType).tsym; s.complete(); return ((ClassType)s.type).supertype_field; }