本文整理汇总了Java中com.sun.tools.javac.code.Symbol.PackageSymbol方法的典型用法代码示例。如果您正苦于以下问题:Java Symbol.PackageSymbol方法的具体用法?Java Symbol.PackageSymbol怎么用?Java Symbol.PackageSymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.code.Symbol
的用法示例。
在下文中一共展示了Symbol.PackageSymbol方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TypeProcessor
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
/** Main constructor. */
public TypeProcessor(@NonNull final Element element, @NonNull final Messager logger) {
this.element = element;
this.logger = logger;
elementName = element.getSimpleName();
flatClassName = flatName(element);
final Symbol.PackageSymbol packageInfo = (Symbol.PackageSymbol) findPackage(element);
packageName = packageInfo.getQualifiedName();
elementType = element.asType();
final Attribute.Compound ap = findAutoProxy(element.getAnnotationMirrors());
this.annotation = extractAnnotation(ap);
methods = new ArrayList<>();
}
示例2: 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 );
}
}
示例3: inferModuleName
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
public String inferModuleName( Context ctx )
{
if( !(_fo instanceof GeneratedJavaStubFileObject) )
{
return null;
}
Names names = Names.instance( ctx );
GeneratedJavaStubFileObject fo = (GeneratedJavaStubFileObject)_fo;
String packageName = getPackageName( fo );
JavacElements elementUtils = JavacElements.instance( ctx );
for( Object /*ModuleElement*/ ms : (Iterable)ReflectUtil.method( elementUtils, "getAllModuleElements" ).invoke() )
{
if( (boolean)ReflectUtil.method( ms, "isUnnamed" ).invoke() )
{
continue;
}
if( ms.getClass().getSimpleName().equals( "ModuleSymbol" ) )
{
//noinspection unchecked
for( Symbol pkg : (Iterable<Symbol>)ReflectUtil.field( ms, "enclosedPackages" ).get() )
{
if( !(pkg instanceof Symbol.PackageSymbol) )
{
continue;
}
if( pkg.toString().equals( packageName ) )
{
//noinspection unchecked,RedundantCast
Iterable<Symbol> symbolsByName = (Iterable<Symbol>)ReflectUtil.method( ReflectUtil.method( pkg, "members" ).invoke(), "getSymbolsByName", Name.class ).invoke( names.fromString( getClassName( fo ) ) );
if( symbolsByName.iterator().hasNext() )
{
return ReflectUtil.method( ms, "getQualifiedName" ).invoke().toString();
}
}
}
}
}
return null;
}