private static URI getUriFrom( IManifoldHost host, String fqn ) { final String outRelativePath = fqn.replace( '.', File.separatorChar ) + ".class"; IDirectory outputPath = host.getSingleModule().getOutputPath().stream().findFirst().orElse( null ); File file = new File( outputPath.getPath().getFileSystemPathString(), outRelativePath ); return file.toURI(); }
private static URI getUriFrom( IManifoldHost host, String fqn, String filename ) { final String outRelativePath = fqn.replace( '.', File.separatorChar ) + File.separatorChar + filename; IDirectory outputPath = host.getSingleModule().getOutputPath().stream().findFirst().orElse( null ); File file = new File( outputPath.getPath().getFileSystemPathString(), outRelativePath ); return file.toURI(); }
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 ); } } ); } }
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; }
public JavaFileObject getSourceFileForInput( Location location, String fqn, JavaFileObject.Kind kind, DiagnosticListener<JavaFileObject> errorHandler ) { try { JavaFileObject file = super.getJavaFileForInput( location, fqn, kind ); if( file != null ) { return file; } } catch( IOException ignore ) { } return findGeneratedFile( fqn.replace( '$', '.' ), location, getHost().getSingleModule(), errorHandler ); }
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 ); } } } } }
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; }
IModule globalModule = getHost().getSingleModule(); if( globalModule != null )
Set<IFile> changes = changedFiles.stream().map( ( File f ) -> host.getFileSystem().getIFile( f ) ) .collect( Collectors.toSet() ); for( ITypeManifold tm: host.getSingleModule().getTypeManifolds() )
private String getTypeForFile( JavaFileObject file ) { URI uri = file.toUri(); if( !uri.getScheme().equalsIgnoreCase( "file" ) ) { return makeTypeName( file.getName() ); } IFile iFile = getHost().getFileSystem().getIFile( new File( file.getName() ) ); List<IDirectory> sourcePath = getHost().getSingleModule().getSourcePath(); for( IDirectory dir : sourcePath ) { if( iFile.isDescendantOf( dir ) ) { return makeTypeName( iFile.getName().substring( dir.getName().length() ) ); } } throw new IllegalStateException( "Could not infer type name from: " + file.getName() ); }
Set<IFile> changes = changedFiles.stream().map( ( File f ) -> host.getFileSystem().getIFile( f ) ) .collect( Collectors.toSet() ); for( ITypeManifold tm: host.getSingleModule().getTypeManifolds() )
if( kinds.contains( JavaFileObject.Kind.SOURCE ) && (location == StandardLocation.SOURCE_PATH || location == StandardLocation.CLASS_PATH || location instanceof ManPatchModuleLocation) ) Set<TypeName> children =((SimpleModule)getHost().getSingleModule()).getChildrenOfNamespace( packageName ); if( children == null || children.isEmpty() )