default IFileSystem getFileSystem() { return getHost().getFileSystem(); }
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(); }
public TypeSystemAwareCache( IManifoldHost host, String name, int size, Loader<K, V> loader ) { super( name, size, loader ); host.addTypeSystemListenerAsWeakRef( null, _cacheClearer ); }
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() ); }
private JCTree.JCClassDecl getClassDecl( Model model ) { JCTree.JCClassDecl classDecl = model.getClassDecl(); if( classDecl != null ) { return classDecl; } List<CompilationUnitTree> trees = new ArrayList<>(); getModule().getHost().getJavaParser().parseText( getSource( model ), trees, null, null, null ); if( trees.isEmpty() ) { return null; } classDecl = (JCTree.JCClassDecl)trees.get( 0 ).getTypeDecls().get( 0 ); model.setClassDecl( classDecl ); return classDecl; }
private boolean isInnerToJavaClass( String topLevel, String relativeInner ) { try { Class<?> cls = Class.forName( topLevel, false, getModule().getHost().getActualClassLoader() ); for( Class<?> inner : cls.getDeclaredClasses() ) { if( isInnerClass( inner, relativeInner ) ) { return true; } } } catch( ClassNotFoundException ignore ) { } return false; }
private void addFilesInDir( String relativePath, IDirectory dir, Map<String, FqnCache<IFile>> filesByExtension ) { if( !_module.getHost().isPathIgnored( relativePath ) ) { for( IFile file : dir.listFiles() ) { String simpleName = file.getName(); int iDot = simpleName.lastIndexOf( '.' ); if( iDot > 0 ) { simpleName = simpleName.substring( 0, iDot ); } String fqn = appendResourceNameToPath( relativePath, simpleName ); addToExtension( fqn, file, filesByExtension ); addToReverseMap( file, fqn ); } for( IDirectory subdir : dir.listDirs() ) { if( isValidPackage( subdir ) ) { String fqn = appendResourceNameToPath( relativePath, subdir.getName() ); addFilesInDir( fqn, subdir, filesByExtension ); } } } }
Set<IFile> changes = changedFiles.stream().map( ( File f ) -> host.getFileSystem().getIFile( f ) ) .collect( Collectors.toSet() ); for( ITypeManifold tm: host.getSingleModule().getTypeManifolds() )
private JCTree.JCClassDecl getClassDecl( Model model ) { JCTree.JCClassDecl classDecl = model.getClassDecl(); if( classDecl != null ) { return classDecl; } List<CompilationUnitTree> trees = new ArrayList<>(); getModule().getHost().getJavaParser().parseText( getSource( model ), trees, null, null, null ); if( trees.isEmpty() ) { return null; } classDecl = (JCTree.JCClassDecl)trees.get( 0 ).getTypeDecls().get( 0 ); model.setClassDecl( classDecl ); return classDecl; }
private boolean isInnerToJavaClass( String topLevel, String relativeInner ) { try { Class<?> cls = Class.forName( topLevel, false, getModule().getHost().getActualClassLoader() ); for( Class<?> inner : cls.getDeclaredClasses() ) { if( isInnerClass( inner, relativeInner ) ) { return true; } } } catch( ClassNotFoundException ignore ) { } return false; }
Set<IFile> changes = changedFiles.stream().map( ( File f ) -> host.getFileSystem().getIFile( f ) ) .collect( Collectors.toSet() ); for( ITypeManifold tm: host.getSingleModule().getTypeManifolds() )
private SrcClass makeStubFromSource() { List<CompilationUnitTree> trees = new ArrayList<>(); _model.getHost().getJavaParser().parseText( _existingSource, trees, null, null, null ); JCTree.JCClassDecl classDecl = (JCTree.JCClassDecl)trees.get( 0 ).getTypeDecls().get( 0 ); SrcClass srcExtended = new SrcClass( _fqn, classDecl.getKind() == Tree.Kind.CLASS ? SrcClass.Kind.Class : SrcClass.Kind.Interface ) .modifiers( classDecl.getModifiers().getFlags() ); if( classDecl.extending != null ) { srcExtended.superClass( classDecl.extending.toString() ); } for( JCTree.JCExpression iface : classDecl.implementing ) { srcExtended.addInterface( iface.toString() ); } return srcExtended; }
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(); }
protected IDirectory getIResourceFromJavaFile( URL location ) { return getHost().getFileSystem().getIDirectory( getFileFromURL( location ) ); }
public PathCache( IModule module, Supplier<Collection<IDirectory>> pathSupplier, Runnable clearHandler ) { _module = module; _pathSupplier = pathSupplier; _clearHandler = clearHandler; _reverseMap = new ConcurrentHashMap<>(); init(); _module.getHost().addTypeSystemListenerAsWeakRef( module, _clearer = new CacheClearer() ); }
private SrcClass makeStubFromSource() { List<CompilationUnitTree> trees = new ArrayList<>(); _model.getHost().getJavaParser().parseText( _existingSource, trees, null, null, null ); JCTree.JCClassDecl classDecl = (JCTree.JCClassDecl)trees.get( 0 ).getTypeDecls().get( 0 ); SrcClass srcExtended = new SrcClass( _fqn, classDecl.getKind() == Tree.Kind.CLASS ? SrcClass.Kind.Class : SrcClass.Kind.Interface ) .modifiers( classDecl.getModifiers().getFlags() ); if( classDecl.extending != null ) { srcExtended.superClass( classDecl.extending.toString() ); } for( JCTree.JCExpression iface : classDecl.implementing ) { srcExtended.addInterface( iface.toString() ); } return srcExtended; }
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 ); } } ); } }
IFile getIResourceFromJavaFile( URL location ) { return getHost().getFileSystem().getIFile( getFileFromURL( location ) ); }
private ClassSymbols( IModule module ) _module.getHost().addTypeSystemListenerAsWeakRef( module, new CacheClearer() ); _altJavacTask_PlainFileMgr = LocklessLazyVar.make( () -> { init();
expr = _tp.getHost().getJavaParser().parseExpr( comp.getExpr(), errorHandler ); if( transferParseErrors( literalOffset, comp, expr, errorHandler ) )