ReflectUtil.field( type.tsym.owner, "kind" ).get() == ReflectUtil.field( "com.sun.tools.javac.code.Kinds$Kind", "TYP" ).getStatic() )
static void addUrlToIntelliJPluginClassLoader( ClassLoader cl, URL url ) { if( cl.getClass().getTypeName().equals( "com.intellij.ide.plugins.cl.PluginClassLoader" ) ) { try { Object classPath = ReflectUtil.method( cl, "getClassPath" ).invoke(); ReflectUtil.field( classPath, "myCanUseCache" ).set( false ); Object urlLoader = makeUrlLoader( cl, url ); ReflectUtil.method( ReflectUtil.field( classPath, "myLoaders" ).get(), "add", Object.class ).invoke( urlLoader ); ReflectUtil.method( ReflectUtil.field( classPath, "myLoadersMap" ).get(), "put", Object.class, Object.class ).invoke( url, urlLoader ); //ReflectUtil.method( classPath, "initLoader", URL.class, ReflectUtil.type( "com.intellij.util.lang.Loader" ) ).invoke( url, urlLoader ); } catch( Exception e ) { //## todo: log error e.printStackTrace(); } } }
public static LiveFieldRef field( Object receiver, String name ) { FieldRef ref = ReflectUtil.field( receiver.getClass(), name ); if( ref == null ) { return null; } return new LiveFieldRef( ref._field, receiver ); }
ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.Modules" ), "instance", Context.class ).invokeStatic( context ), "allModules" ).get(); 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() ) 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 );
ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.Modules" ), "instance", Context.class ).invokeStatic( context ), "allModules" ).get(); 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() ) 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 );
private void _visitApply( JCTree.JCMethodInvocation tree ) Env<AttrContext> env = (Env<AttrContext>)ReflectUtil.field( this, "env" ).get(); typeargtypes = attribAnyTypes( tree.typeargs, localEnv ); Object resultInfo = ReflectUtil.field( this, "resultInfo" ).get(); Type mpt = newMethodTemplate( (Type)ReflectUtil.field( resultInfo, "pt" ).get(), argtypes, typeargtypes ); ReflectUtil.field( localEnv.info, "pendingResolutionPhase" ).set( null ); Type mtype = (Type)attribTree.invoke( this, tree.meth, localEnv, resultInfoCtor.newInstance( this, kind, mpt, ReflectUtil.field( resultInfo, "checkContext" ).get() ) ); ReflectUtil.field( this, "result" ).set( restype ); validate.invoke( _chk, tree.typeargs, localEnv );
Object classLocation = ReflectUtil.field( m, "classLocation" ).get(); if( classLocation == null )
Map/*<String, ModuleReference>*/nameToModule = (Map)nameToModuleField.get(); for( Object mr: nameToModule.values() )
ReflectUtil.field( JavaCompiler.instance( getContext() ), "writer" ).set( manClassWriter ); ? ReflectUtil.method( "manifold.internal.javac.ManAttr_8", "instance", Context.class ).invokeStatic( getContext() ) : ReflectUtil.method( "manifold.internal.javac.ManAttr_9", "instance", Context.class ).invokeStatic( getContext() )); ReflectUtil.field( JavaCompiler.instance( getContext() ), "attr" ).set( manAttr ); Symbol module = (Symbol)ReflectUtil.field( compilationUnit, "modle" ).get(); if( module == null )
RelativePath relativePath = (RelativePath)ReflectUtil.field( fileObj, "relativePath" ).get(); return removeExtension( relativePath.getPath() ).replace( File.separatorChar, '.' ).replace( '/', '.' ); FileObject fileObject = (FileObject)ReflectUtil.field( fileObj, "fileObject" ).get(); return fileObject instanceof JavaFileObject ? inferBinaryName( location, (JavaFileObject)fileObject ) : null;
ReflectUtil.field( ClassReader.instance( getContext() ), "fileManager" ).set( _manFileManager ); ReflectUtil.field( classFinder, "fileManager" ).set( _manFileManager ); ReflectUtil.field( classFinder, "preferSource" ).set( true ); ReflectUtil.field( modules, "fileManager" ).set( _manFileManager ); ReflectUtil.field( moduleFinder, "fileManager" ).set( _manFileManager ); ReflectUtil.field( classFinder, "fileManager" ).set( _manFileManager ); ReflectUtil.field( modules, "fileManager" ).set( _manFileManager ); ReflectUtil.field( moduleFinder, "fileManager" ).set( _manFileManager ); ReflectUtil.field( ClassWriter.instance( getContext() ), "fileManager" ).set( _manFileManager ); ReflectUtil.field( Enter.instance( getContext() ), "fileManager" ).set( _manFileManager );
for( Symbol pkg : (Iterable<Symbol>)ReflectUtil.field( ms, "enclosedPackages" ).get() )
private void wrapReaders() { Map/*<ModuleReference, ModuleReader>*/ moduleToReader = (Map)ReflectUtil.field( _loader, "moduleToReader" ).get(); for( Object mr: moduleToReader.keySet() ) { //noinspection unchecked Optional<URI> location = (Optional<URI>)ReflectUtil.method( mr, "location" ).invoke(); URI uri = location.orElse( null ); if( uri == null ) { continue; } //## note: "jmod" files are not supported here because they are currently (2018) supported exclusively at compiler/linker time String scheme = uri.getScheme(); if( scheme.equalsIgnoreCase( "file" ) || scheme.equalsIgnoreCase( "jar" ) ) { Object reader = moduleToReader.get( mr ); Class<?> moduleReaderClass = ReflectUtil.type( "java.lang.module.ModuleReader" ); ManModuleReader wrapper = new ManModuleReader( reader, ReflectUtil.field( _loader, "ucp" ).get() ); Object/*ModuleReader*/ proxy = Proxy.newProxyInstance( moduleReaderClass.getClassLoader(), new Class<?>[]{moduleReaderClass}, new ManModuleReaderInvocationHandler( wrapper ) ); //noinspection unchecked moduleToReader.put( mr, proxy ); } } }
private void reassignAllEarlyHolders( Context ctx ) { Object[] earlyAttrHolders = { Resolve.instance( ctx ), DeferredAttr.instance( ctx ), MemberEnter.instance( ctx ), Lower.instance( ctx ), TransTypes.instance( ctx ), Annotate.instance( ctx ), TypeAnnotations.instance( ctx ), JavacTrees.instance( ctx ), JavaCompiler.instance( ctx ), }; for( Object instance: earlyAttrHolders ) { ReflectUtil.LiveFieldRef attr = ReflectUtil.WithNull.field( instance, "attr" ); if( attr != null ) { attr.set( this ); } } }
private void reassignAllEarlyHolders( Context ctx ) { Object[] earlyAttrHolders = { Resolve.instance( ctx ), DeferredAttr.instance( ctx ), Enter.instance( ctx ), MemberEnter.instance( ctx ), Lower.instance( ctx ), Flow.instance( ctx ), //## todo: some of these need their original Log, e.g., compile this "java.util.Date date = new java.util.Date( asdfg );" and see the fatal error report // TransTypes.instance( ctx ), // Annotate.instance( ctx ), // TypeAnnotations.instance( ctx ), // JavacTrees.instance( ctx ), // JavaCompiler.instance( ctx ), }; for( Object instance: earlyAttrHolders ) { ReflectUtil.LiveFieldRef log = ReflectUtil.WithNull.field( instance, "log" ); if( log != null ) { log.set( this ); } } }
private static LiveMethodRef getURLsMethod( Object receiver ) { LiveMethodRef getURLs = ReflectUtil.WithNull.methodWithReturn( receiver, "getURLs|getUrls", URL[].class ); if( getURLs == null ) { getURLs = ReflectUtil.WithNull.methodWithReturn( receiver, "getURLs|getUrls", List.class ); if( getURLs == null && receiver instanceof ClassLoader ) { ReflectUtil.LiveFieldRef ucpField = ReflectUtil.WithNull.field( receiver, "ucp" ); if( ucpField != null ) { Object ucp = ucpField.get(); if( ucp != null ) { getURLs = getURLsMethod( ucp ); } } } } return getURLs; }
private void reassignEarlyHolders( Context context ) { ReflectUtil.field( _attr, "rs" ).set( this ); ReflectUtil.field( DeferredAttr.instance( context ), "rs" ).set( this ); ReflectUtil.field( Check.instance( context ), "rs" ).set( this ); ReflectUtil.field( Infer.instance( context ), "rs" ).set( this ); ReflectUtil.field( Flow.instance( context ), "rs" ).set( this ); ReflectUtil.field( LambdaToMethod.instance( context ), "rs" ).set( this ); ReflectUtil.field( Lower.instance( context ), "rs" ).set( this ); ReflectUtil.field( Gen.instance( context ), "rs" ).set( this ); ReflectUtil.field( ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.jvm.StringConcat" ), "instance", Context.class ) .invokeStatic( context ), "rs" ) .set( this ); ReflectUtil.field( JavacTrees.instance( context ), "resolve" ).set( this ); ReflectUtil.field( Annotate.instance( context ), "resolve" ).set( this ); ReflectUtil.field( TransTypes.instance( context ), "resolve" ).set( this ); ReflectUtil.field( JavacElements.instance( context ), "resolve" ).set( this ); }
protected boolean testForArg( String name, String[] args ) { boolean isPresent = isArgPresent( name, args ); if( !isPresent ) { // maven doesn't like the -Xplugin:"Manifold strings", it doesn't parse "Manifold string" as plugin name and argument, so we do it here: try { String[] rawArgs = (String[])ReflectUtil.field( _javacTask, "args" ).get(); isPresent = Arrays.stream( rawArgs ).anyMatch( arg -> arg.contains( "-Xplugin:" ) && arg.contains( "Manifold" ) && arg.contains( name ) ); } catch( Exception ignore ) { } } return isPresent; }
public static ClassLoader getParent( ClassLoader cl ) { if( cl.getClass().getTypeName().equals( "com.intellij.ide.plugins.cl.PluginClassLoader" ) ) { try { ClassLoader[] parents = (ClassLoader[])ReflectUtil.field( cl, "myParents" ).get(); return parents.length > 0 ? parents[0] : null; } catch( Exception e ) { //## todo: log error e.printStackTrace(); } } return null; } }
private ManAttr_8( Context ctx ) { super( ctx ); _names = Names.instance( ctx ); _syms = Symtab.instance( ctx ); _chk = Check.instance( ctx ); _selects = new Stack<>(); _annotatedTypes = new Stack<>(); // Override logger to handle final field assignment for @Jailbreak _manLog = (ManLog_8)ManLog_8.instance( ctx ); ReflectUtil.field( this, "log" ).set( _manLog ); ReflectUtil.field( this, "rs" ).set( ManResolve.instance( ctx ) ); reassignAllEarlyHolders( ctx ); }