/** * 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 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 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; } }
/** * 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 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 protected Map<String, LocklessLazyVar<Model>> getPeripheralTypes() { // Include types extended by dynamically provided extension classes from IExtensionClassProducers Map<String, LocklessLazyVar<Model>> map = new HashMap<>(); for( ITypeManifold tm : getModule().getTypeManifolds() ) { if( tm instanceof IExtensionClassProducer ) { for( String extended : ((IExtensionClassProducer)tm).getExtendedTypes() ) { map.put( extended, LocklessLazyVar.make( () -> new Model( extended, Collections.emptySet(), this ) ) ); } } } return map; }
@Override protected Map<String, LocklessLazyVar<Model>> getPeripheralTypes() { // Include types extended by dynamically provided extension classes from IExtensionClassProducers Map<String, LocklessLazyVar<Model>> map = new HashMap<>(); for( ITypeManifold tm : getModule().getTypeManifolds() ) { if( tm instanceof IExtensionClassProducer ) { for( String extended : ((IExtensionClassProducer)tm).getExtendedTypes() ) { map.put( extended, LocklessLazyVar.make( () -> new Model( extended, Collections.emptySet(), this ) ) ); } } } return map; }
private void findExtensionsFromExtensionClassProviders( Set<String> fqns ) { ExtensionManifold extensionManifold = _model.getTypeManifold(); for( ITypeManifold tm: extensionManifold.getModule().getTypeManifolds() ) { if( tm != extensionManifold && tm instanceof IExtensionClassProducer ) { Set<String> extensionClasses = ((IExtensionClassProducer)tm).getExtensionClasses( _model.getFqn() ); fqns.addAll( extensionClasses ); } } }
private void findExtensionsFromExtensionClassProviders( Set<String> fqns ) { ExtensionManifold extensionManifold = _model.getTypeManifold(); for( ITypeManifold tm: extensionManifold.getModule().getTypeManifolds() ) { if( tm != extensionManifold && tm instanceof IExtensionClassProducer ) { Set<String> extensionClasses = ((IExtensionClassProducer)tm).getExtensionClasses( _model.getFqn() ); fqns.addAll( extensionClasses ); } } }
private void precompile( Map<String, Set<String>> typeNames ) { for( ITypeManifold tm: _tp.getHost().getSingleModule().getTypeManifolds() ) { for( Map.Entry<String, Set<String>> entry: typeNames.entrySet() ) { String typeManifoldClassName = entry.getKey(); if( tm.getClass().getName().equals( typeManifoldClassName ) ) { Collection<String> namesToPrecompile = computeNamesToPrecompile( tm.getAllTypeNames(), entry.getValue() ); for( String fqn: namesToPrecompile ) { // This call surfaces the type in the compiler. If compiling in "static" mode, this means // the type will be compiled to disk. IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), fqn ); } } } } }
@Override public void process( TypeElement element, IssueReporter<JavaFileObject> issueReporter ) { if( IDynamicJdk.isInitializing() ) { // avoid re-entry of dynamic jdk construction return; } for( ITypeManifold sp: getHost().getSingleModule().getTypeManifolds() ) { if( sp instanceof ITypeProcessor ) { //JavacProcessingEnvironment.instance( getContext() ).getMessager().printMessage( Diagnostic.Kind.NOTE, "Processing: " + element.getQualifiedName() ); try { ((ITypeProcessor)sp).process( element, this, issueReporter ); } catch( Throwable e ) { StringWriter stackTrace = new StringWriter(); e.printStackTrace( new PrintWriter( stackTrace ) ); issueReporter.reportError( "Fatal error processing with Manifold type processor: " + sp.getClass().getName() + "\non type: " + element.getQualifiedName() + "\nPlease report the error with the accompanying stack trace.\n" + stackTrace ); throw e; } } } }
private void precompile( Map<String, Set<String>> typeNames ) { for( ITypeManifold tm: _tp.getHost().getSingleModule().getTypeManifolds() ) { for( Map.Entry<String, Set<String>> entry: typeNames.entrySet() ) { String typeManifoldClassName = entry.getKey(); if( tm.getClass().getName().equals( typeManifoldClassName ) ) { Collection<String> namesToPrecompile = computeNamesToPrecompile( tm.getAllTypeNames(), entry.getValue() ); for( String fqn: namesToPrecompile ) { // This call surfaces the type in the compiler. If compiling in "static" mode, this means // the type will be compiled to disk. IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), fqn ); } } } } }
Set<IFile> changes = changedFiles.stream().map( ( File f ) -> host.getFileSystem().getIFile( f ) ) .collect( Collectors.toSet() ); for( ITypeManifold tm: host.getSingleModule().getTypeManifolds() )
Set<IFile> changes = changedFiles.stream().map( ( File f ) -> host.getFileSystem().getIFile( f ) ) .collect( Collectors.toSet() ); for( ITypeManifold tm: host.getSingleModule().getTypeManifolds() )