@SuppressWarnings("unused") public static boolean isJava9orLater() { return !isJava8(); }
public List<URL> getURLs() { if( _loader instanceof URLClassLoader ) { URL[] urls = ((URLClassLoader)_loader).getURLs(); return urls == null ? Collections.emptyList() : Arrays.asList( urls ); } List<URL> allUrls = new ArrayList<>( getClasspathUrls() ); if( JreUtil.isJava9Modular_runtime() ) { allUrls.addAll( getModularUrls() ); } return Collections.unmodifiableList( allUrls ); }
private List<String> deriveClasspath() if( JreUtil.isJava9Modular_compiler( getContext() ) )
private boolean isCorrectModule( Location location, Iterable<JavaFileObject> patchableFiles, JavaFileObject file, String fqn ) { if( !(location instanceof ManPatchModuleLocation) ) { // not a ManPatchModuleLocation means not an extended class if( !JreUtil.isJava9Modular_compiler( _ctx ) ) { return true; } // true if type is not exclusively an extended type Set<ITypeManifold> typeManifoldsFor = getHost().getSingleModule().findTypeManifoldsFor( fqn ); return typeManifoldsFor.stream().anyMatch( tm -> tm.getContributorKind() == Primary ); } if( patchableFiles == null ) { return true; } String cname = inferBinaryName( location, file ); for( JavaFileObject f: patchableFiles ) { String name = inferBinaryName( location, f ); if( cname.equals( name) ) { return true; } } return false; }
@Override public void started( TaskEvent te ) { if( JreUtil.isJava8() ) { return; } CompilationUnitTree compilationUnit = te.getCompilationUnit(); if( !(compilationUnit instanceof JCTree.JCCompilationUnit) ) { return; } if( _done ) { return; } _done = true; openModule( _ctx, "jdk.compiler" ); }
if( javacHook != null && !JreUtil.isJava9Modular_compiler( javacHook.getContext() ) )
void addURL( URL url ) { try { _addUrl.invoke( url ); if( JreUtil.isJava9Modular_runtime() ) { wrapReaders(); } IjPluginIntegration.addUrlToIntelliJPluginClassLoader( _loader, url ); } catch( Exception e ) { throw new RuntimeException( e ); } }
@Override public void started( TaskEvent te ) { if( JreUtil.isJava8() ) { return; } CompilationUnitTree compilationUnit = te.getCompilationUnit(); if( !(compilationUnit instanceof JCTree.JCCompilationUnit) ) { return; } if( _done ) { return; } _done = true; openModule( _ctx, "jdk.compiler" ); }
public static void disableJava9IllegalAccessWarning( ClassLoader cl ) { if( JreUtil.isJava8() ) { return; } try { Class cls = Class.forName( "jdk.internal.module.IllegalAccessLogger", false, cl ); Field logger = cls.getDeclaredField( "logger" ); getUnsafe().putObjectVolatile( cls, getUnsafe().staticFieldOffset( logger ), null ); } catch( Throwable ignore ) { } }
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; } }
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 String typeNoAnnotations( Type type ) if( isJava8() )
private JCExpression makeClassExpr( JCTree tree, Type type ) { BasicJavacTask javacTask = (BasicJavacTask)_tp.getJavacTask(); Types types = Types.instance( javacTask.getContext() ); type = types.erasure( type ); JCExpression classExpr; if( type.isPrimitive() || (JreUtil.isJava8() && type.tsym.getModifiers().contains( javax.lang.model.element.Modifier.PUBLIC )) ) { // class is publicly accessible, assume we can use class literal classExpr = _tp.getTreeMaker().ClassLiteral( type ); } else { // generate `ReflectUtil.type( typeName )` classExpr = classForNameCall( type, tree ); } return classExpr; }
private JCExpression makeClassExpr( JCTree tree, Type type ) { BasicJavacTask javacTask = (BasicJavacTask)_tp.getJavacTask(); Types types = Types.instance( javacTask.getContext() ); type = types.erasure( type ); JCExpression classExpr; if( type.isPrimitive() || (JreUtil.isJava8() && type.tsym.getModifiers().contains( javax.lang.model.element.Modifier.PUBLIC )) ) { // class is publicly accessible, assume we can use class literal classExpr = _tp.getTreeMaker().ClassLiteral( type ); } else { // generate `ReflectUtil.type( typeName )` classExpr = classForNameCall( type, tree ); } return classExpr; }
if( annotationMirrors != null && !annotationMirrors.isEmpty() ) String unannotatedType = isJava8() ? ReflectUtil.method( type, "unannotatedType" ).invoke().toString() : ReflectUtil.method( type, "cloneWithMetadata", ReflectUtil.type( "com.sun.tools.javac.code.TypeMetadata" ) )
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; }
public static void openJavaBase() if( JreUtil.isJava8() )