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(); } } }
private ManLog_8( Context ctx, DiagnosticHandler diagnosticHandler, DiagnosticSource source, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter ) { super( ctx, errWriter, warnWriter, noticeWriter ); ReflectUtil.field( this, "diagnosticHandler" ).set( diagnosticHandler ); ReflectUtil.field( this, "source" ).set( source ); _suspendedIssues = new HashMap<>(); _extensionTransformerClass = LocklessLazyVar.make( () -> ReflectUtil.type( "manifold.ext.ExtensionTransformer" ) ); reassignAllEarlyHolders( ctx ); }
newRequires.add( addedRequires ); requires = com.sun.tools.javac.util.List.from( newRequires ); ReflectUtil.field( rootModule, "requires" ).set( requires ); ReflectUtil.field( moduleToOpen, "exports" ).set( com.sun.tools.javac.util.List.from( exports ) ); ReflectUtil.field( moduleToOpen, "readModules" ).set( readModules );
newRequires.add( addedRequires ); requires = com.sun.tools.javac.util.List.from( newRequires ); ReflectUtil.field( rootModule, "requires" ).set( requires ); ReflectUtil.field( moduleToOpen, "exports" ).set( com.sun.tools.javac.util.List.from( exports ) ); ReflectUtil.field( moduleToOpen, "readModules" ).set( readModules );
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 );
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 );
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 );
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 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 ); }
private TypeAnnotationPosition getTypeAnnotationPosition( List<TypeAnnotationPosition.TypePathEntry> attrLocationCopy ) { TypeAnnotationPosition posCopy; //noinspection ConstantConditions if( isJava8() ) { posCopy = (TypeAnnotationPosition)ReflectUtil.constructor( "com.sun.tools.javac.code.TypeAnnotationPosition" ).newInstance(); ReflectUtil.field( posCopy, "location" ).set( attrLocationCopy ); } else { posCopy = (TypeAnnotationPosition)ReflectUtil .method( TypeAnnotationPosition.class, "methodReceiver", List.class ).invokeStatic( attrLocationCopy ); } return posCopy; }
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 ); }
@SuppressWarnings("UnusedReturnValue") public static Object setField_Object( Object receiver, String name, Object value ) { ReflectUtil.field( receiver, name ).set( value ); return value; }
@SuppressWarnings("UnusedReturnValue") public static Object setField_Object( Object receiver, String name, Object value ) { ReflectUtil.field( receiver, name ).set( value ); return value; }