本文整理汇总了Java中com.sun.tools.javac.code.Symbol.complete方法的典型用法代码示例。如果您正苦于以下问题:Java Symbol.complete方法的具体用法?Java Symbol.complete怎么用?Java Symbol.complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.code.Symbol
的用法示例。
在下文中一共展示了Symbol.complete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
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]);
}
}
示例2: NumberType
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
Type NumberType() {
Symbol s = box(predef.intType).tsym;
s.complete();
return ((ClassType)s.type).supertype_field;
}
示例3: openModule
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
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 );
}
}