@Override public boolean accept( IModule module ) { // Dark Java files are intended to be compiled dynamically at runtime, they // should never be compiled statically, otherwise just use normal Java. return module.getHost() instanceof IRuntimeManifoldHost; }
/** * Finds the set of type manifolds that handle a given resource file. * * @param file A resource file * * @return The set of type manifolds that handle {@code file} */ default Set<ITypeManifold> findTypeManifoldsFor( IFile file ) { Set<ITypeManifold> tms = new HashSet<>( 2 ); for( ITypeManifold tm : getTypeManifolds() ) { if( tm.handlesFile( file ) ) { tms.add( tm ); } } return tms; }
private boolean isInnerToPrimaryManifold( String topLevel, String relativeInner ) { //noinspection unchecked Set<ITypeManifold> tms = getModule().findTypeManifoldsFor( topLevel, tm -> tm.getContributorKind() == ContributorKind.Primary && tm instanceof ResourceFileTypeManifold && ((ResourceFileTypeManifold)tm).isInnerType( topLevel, relativeInner ) ); return !tms.isEmpty(); }
protected boolean isDuplicate( IFile file, Set<IFile> files ) { Set<String> fqnForFile = getModule().getPathCache().getFqnForFile( file ); for( IFile f : files ) { Set<String> fqn = getModule().getPathCache().getFqnForFile( f ); if( fqnForFile.equals( fqn ) ) { return true; } } return false; }
private void findExtensionsOnDisk( Set<String> fqns ) { PathCache pathCache = getModule().getPathCache(); for( IFile file : _model.getFiles() ) { Set<String> fqn = pathCache.getFqnForFile( file ); for( String f : fqn ) { if( f != null ) { fqns.add( f ); } } } }
@Override public boolean accept( IModule module ) { // Dark Java files are intended to be compiled dynamically at runtime, they // should never be compiled statically, otherwise just use normal Java. return module.getHost() instanceof IRuntimeManifoldHost; }
private static ITypeManifold findJavascriptManifold( String fileExt ) { ITypeManifold tm = RuntimeManifoldHost.get().getSingleModule().getTypeManifolds().stream() .filter( e -> e.handlesFileExtension( fileExt ) ) .findFirst().orElse( null ); if( tm == null ) { throw new IllegalStateException( "Could not find type manifold for extension: " + fileExt ); } return tm; } }
private boolean isClassFile( TypeName tn ) { String fqn = tn.name; int iDollar = fqn.indexOf( '$' ); if( iDollar > 0 ) { fqn = fqn.substring( 0, iDollar ); } PathCache pathCache = getHost().getSingleModule().getPathCache(); return pathCache.getExtensionCache( "class" ).get( fqn ) != null; }
private boolean isInnerToPrimaryManifold( String topLevel, String relativeInner ) { Set<ITypeManifold> tms = getModule().findTypeManifoldsFor( topLevel ); if( tms != null ) { for( ITypeManifold tm : tms ) { if( tm.getContributorKind() == ContributorKind.Primary && tm instanceof ResourceFileTypeManifold ) { return ((ResourceFileTypeManifold)tm).isInnerType( topLevel, relativeInner ); } } } return false; }
default IFileSystem getFileSystem() { return getHost().getFileSystem(); }
private static ITypeManifold findJavascriptManifold( String fileExt ) { ITypeManifold tm = RuntimeManifoldHost.get().getSingleModule().getTypeManifolds().stream() .filter( e -> e.handlesFileExtension( fileExt ) ) .findFirst().orElse( null ); if( tm == null ) { throw new IllegalStateException( "Could not find type manifold for extension: " + fileExt ); } return tm; } }
@Override public String[] getTypesForFile( IFile file ) { if( !handlesFile( file ) ) { return new String[0]; } Set<String> fqns = getModule().getPathCache().getFqnForFile( file ); Set<String> aliasedFqns = new HashSet<>(); if( fqns != null ) { for( String fqn : fqns ) { fqn = getTypeNameForFile( fqn, file ); if( fqn != null ) { aliasedFqns.add( fqn ); } } } return aliasedFqns.toArray( new String[aliasedFqns.size()] ); }
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 protected Map<String, LocklessLazyVar<Model>> getPeripheralTypes() { return SystemProperties.make( getModule().getHost() ); }
/** * Finds the set of type manifolds that contribute toward the definition of a given type. * * @param fqn A fully qualified type name * @param predicates Zero or more predicates to filter the set of type manifolds available * * @return The set of type manifolds that contribute toward the definition of {@code fqn} */ default Set<ITypeManifold> findTypeManifoldsFor( String fqn, Predicate<ITypeManifold>... predicates ) { Set<ITypeManifold> tms = new HashSet<>( 2 ); Set<ITypeManifold> typeManifolds = getTypeManifolds(); if( predicates != null && predicates.length > 0 ) { typeManifolds = typeManifolds.stream() .filter( e -> Arrays.stream( predicates ) .anyMatch( p -> p.test( e ) ) ) .collect( Collectors.toSet() ); } for( ITypeManifold tm : typeManifolds ) { if( tm.isType( fqn ) ) { tms.add( tm ); } } return tms; }
private void findExtensionsOnDisk( Set<String> fqns ) { PathCache pathCache = getModule().getPathCache(); for( IFile file : _model.getFiles() ) { Set<String> fqn = pathCache.getFqnForFile( file ); for( String f : fqn ) { if( f != null ) { fqns.add( f ); } } } }
@Override public void refreshedTypes( RefreshRequest request ) { super.refreshedTypes( request ); if( request.file == null ) { return; } for( ITypeManifold tm: ExtensionManifold.this.getModule().findTypeManifoldsFor( request.file ) ) { if( tm instanceof IExtensionClassProducer ) { for( String extended: ((IExtensionClassProducer)tm).getExtendedTypesForFile( request.file ) ) { refreshedType( extended, request ); } } } }
@Override protected Model createModel( String extensionFqn, Set<IFile> files ) { return new Model( getModule().getHost(), extensionFqn, files ); }
private void addToPrecompile( Map<String, Set<String>> typeNames, String typeManifoldClassName, String ext, String regex ) { if( typeManifoldClassName != null ) { Set<String> regexes = typeNames.computeIfAbsent( typeManifoldClassName, tm -> new HashSet<>() ); regexes.add( regex ); } else { boolean all = "*".equals( ext ); _tp.getHost().getSingleModule().getTypeManifolds().stream() .filter( tm -> tm.getContributorKind() != ContributorKind.Supplemental ) .forEach( tm -> { boolean match = !all && tm.handlesFileExtension( ext ); if( all || match ) { String classname = tm.getClass().getTypeName(); Set<String> regexes = typeNames.computeIfAbsent( classname, e -> new HashSet<>() ); regexes.add( regex ); } } ); } }
@Override public boolean handlesFile( IFile file ) Set<String> fqns = getModule().getPathCache().getFqnForFile( file ); if( fqns == null )