private List<URL> getClasspathUrls() { try { Object urls = _getURLs.invoke(); urls = urls == null ? Collections.<URL>emptyList() : urls.getClass().isArray() ? Arrays.asList( (URL[])urls ) : urls; //noinspection unchecked return (List)urls; } catch( Exception e ) { throw new RuntimeException( e ); } } }
@Override public Object invoke( Object proxy, Method method, Object[] args ) { return ReflectUtil.method( _wrapper, method.getName(), method.getParameterTypes() ).invoke( args ); } }
public Iterable<? extends Path> getLocationAsPaths( Location location ) { try { //noinspection unchecked return (Iterable)ReflectUtil.method( fileManager, "getLocationAsPaths", Location.class ).invoke( location ); } catch( Exception e ) { throw new RuntimeException( e ); } }
public static boolean isJava9Modular_runtime() { if( _modularRuntime == null ) { if( isJava8() ) { _modularRuntime = false; } else { //noinspection ConstantConditions Object /*Module*/ manifoldModule = ReflectUtil.method( Class.class, "getModule" ).invoke( JreUtil.class ); _modularRuntime = (boolean)ReflectUtil.method( manifoldModule, "isNamed" ).invoke(); } } return _modularRuntime; } }
public static boolean isJava9Modular_compiler( Object/*Context*/ ctx ) { if( _modular == null ) { if( isJava8() ) { _modular = false; } else { //noinspection ConstantConditions Object modulesUtil = ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.Modules" ), "instance", ReflectUtil.type( "com.sun.tools.javac.util.Context" ) ).invokeStatic( ctx ); Object defModule = ReflectUtil.method( modulesUtil, "getDefaultModule" ).invoke(); _modular = defModule != null && !(boolean)ReflectUtil.method( defModule, "isNoModule" ).invoke() && !(boolean)ReflectUtil.method( defModule, "isUnnamed" ).invoke(); } } return _modular; }
/** * @since 9 */ public <S> ServiceLoader<S> getServiceLoader( Location location, Class<S> service ) throws IOException { //return fileManager.getServiceLoader(location, service); try { ReflectUtil.LiveMethodRef getServiceLoader = ReflectUtil.method( fileManager, "getServiceLoader", Location.class, Class.class ); //noinspection unchecked return (ServiceLoader)getServiceLoader.invoke( location, service ); } catch( Exception e ) { throw new IOException( e ); } }
/** * @since 9 */ public Location getLocationForModule( Location location, String moduleName ) throws IOException { //return fileManager.getLocationForModule(location, moduleName); try { ReflectUtil.LiveMethodRef getLocationForModule = ReflectUtil.method( fileManager, "getLocationForModule", Location.class, String.class ); return (Location)getLocationForModule.invoke( location, moduleName ); } catch( Exception e ) { throw new RuntimeException( e ); } }
/** * @since 9 */ public String inferModuleName( Location location ) { //return fileManager.inferModuleName( location ); try { ReflectUtil.LiveMethodRef inferModuleName = ReflectUtil.method( fileManager, "inferModuleName", Location.class ); return (String)inferModuleName.invoke( location ); } catch( Exception e ) { throw new RuntimeException( e ); } }
/** * @since 9 */ public Location getLocationForModule( Location location, JavaFileObject fo ) throws IOException { //return fileManager.getLocationForModule(location, fo); try { ReflectUtil.LiveMethodRef getLocationForModule = ReflectUtil.method( fileManager, "getLocationForModule", Location.class, JavaFileObject.class ); return (Location)getLocationForModule.invoke( location, fo ); } catch( Exception e ) { throw new RuntimeException( e ); } }
/** * @since 9 */ public Iterable<Set<Location>> listLocationsForModules( Location location ) throws IOException { //return fileManager.listLocationsForModules( location ); try { ReflectUtil.LiveMethodRef listLocationsForModules = ReflectUtil.method( fileManager, "listLocationsForModules", Location.class ); //noinspection unchecked return (Iterable)listLocationsForModules.invoke( location ); } catch( Exception e ) { throw new IOException( e ); } }
void addURL( URL url ) { try { _addUrl.invoke( url ); if( JreUtil.isJava9Modular_runtime() ) { wrapReaders(); } IjPluginIntegration.addUrlToIntelliJPluginClassLoader( _loader, url ); } catch( Exception e ) { throw new RuntimeException( e ); } }
public Stream<String> list() { return (Stream<String>)ReflectUtil.method( _delegate, "list" ).invoke(); }
public Optional<InputStream> open( String name ) { Optional<InputStream> input = (Optional<InputStream>)ReflectUtil.method( _delegate, "open", String.class ).invoke( name ); if( !input.isPresent() ) { Object/*Resource*/ resource = ReflectUtil.method( _ucp, "getResource", String.class, boolean.class ).invoke( name, false ); if( resource != null ) { input = Optional.of( (InputStream)ReflectUtil.method( resource, "getInputStream" ).invoke() ); } } return input; }
public static Object invoke_Object( Object receiver, String name, Class[] paramTypes, Object[] args ) { return ReflectUtil.method( receiver, name, paramTypes ).invoke( args ); }
public static Object invoke_Object( Object receiver, String name, Class[] paramTypes, Object[] args ) { return ReflectUtil.method( receiver, name, paramTypes ).invoke( args ); }
public Optional<ByteBuffer> read( String name ) throws IOException { Optional<ByteBuffer> buffer = (Optional<ByteBuffer>)ReflectUtil.method( _delegate, "read", String.class ).invoke( name ); if( !buffer.isPresent() ) { Object/*Resource*/ resource = ReflectUtil.method( _ucp, "getResource", String.class, boolean.class ).invoke( name, false ); if( resource != null ) { ByteBuffer bytes = ByteBuffer.wrap( StreamUtil.getContent( (InputStream)ReflectUtil.method( resource, "getInputStream" ).invoke() ) ); buffer = Optional.of( bytes ); } } return buffer; }
public void close() { ReflectUtil.method( _delegate, "close" ).invoke(); } }
public void release( ByteBuffer bb ) { try { ReflectUtil.method( _delegate, "release", ByteBuffer.class ).invoke( bb ); } catch( Exception ignore ) { } }
private static Class defineClass( ClassLoader cl, String fqn ) throws IOException { InputStream stream = cl.getResourceAsStream( fqn ); byte[] bytes = StreamUtil.getContent( stream ); ClassLoader parent = (ClassLoader)Array.get( ReflectUtil.field( cl, "myParents" ).get(), 0 ); return (Class)ReflectUtil.method( parent, "defineClass", byte[].class, int.class, int.class ).invoke( bytes, 0, bytes.length ); }
private Location makeModuleLocation( ManPatchModuleLocation location ) { // Module module = Modules.instance( _ctx ).getObservableModule( Names.instance( _ctx ).fromString( location.getName() ) ); // return module.classLocation; Symbol moduleElement = (Symbol)ReflectUtil.method( Symtab.instance( _ctx ), "getModule", Name.class ) .invoke( Names.instance( _ctx ).fromString( location.getName() ) ); if( moduleElement == null ) { return null; } return (Location)ReflectUtil.field( moduleElement, "classLocation" ).get(); }