@Override public String getRelativePath() { String relativePath = super.getRelativePath(); if (relativePath == null) { try { relativePath = FileObjects.getRelativePath(root.toURL(), path); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } return relativePath; }
/** * Returns binary name of given file within a root * @param file to get binary name for * @param root the root owning the file * @return the binary name */ public static @NonNull String getBinaryName (final @NonNull File file, final @NonNull File root) { assert file != null && root != null; String fileName = FileObjects.getRelativePath (root, file); int index = fileName.lastIndexOf('.'); //NOI18N if (index > 0) { fileName = fileName.substring(0,index); } return fileName.replace(File.separatorChar,'.'); //NOI18N }
/** * Returns a relative path of given file in given root * @param root owning the file * @param fo a file to get the relative path for * @return the relative path */ public static @NonNull String getRelativePath (@NonNull final URL root, @NonNull final URL fo) throws URISyntaxException { final String path = getRelativePath(BaseUtilities.toFile(root.toURI()), BaseUtilities.toFile(fo.toURI())); return path.replace(File.separatorChar, NBFS_SEPARATOR_CHAR); }
@Override @NonNull JavaFileObject createFileObject( @NonNull final Location location, @NonNull final File file, @NonNull final File root, @NullAllowed final JavaFileFilterImplementation filter, @NullAllowed final Charset encoding) { final String[] pkgNamePair = FileObjects.getFolderAndBaseName(FileObjects.getRelativePath(root, file), File.separatorChar); String pname = FileObjects.convertFolder2Package(pkgNamePair[0], File.separatorChar); CachedFileObject cfo = getFileObject(location, pname, pkgNamePair[1], false); if (cfo != null) { return cfo; } String relPath = FileObjects.getRelativePath(root, file); File shadowRoot = new File(root.getParent(), root.getName() + WORK_SUFFIX); File shadowFile = new File(shadowRoot, relPath); workDirs.add(shadowRoot); cfo = new CachedFileObject(this, file, pname, pkgNamePair[1], filter, encoding); cfo.setShadowFile(shadowFile); addFile(location, pname, cfo); if (!shadowRoot.mkdirs() && !shadowRoot.exists() && !shadowRoot.isDirectory()) { throw new IllegalStateException(); } return cfo; }
public static Collection<? extends ElementHandle<TypeElement>> getRelatedTypes (final File source, final File root) throws IOException { final List<ElementHandle<TypeElement>> result = new LinkedList<ElementHandle<TypeElement>>(); final File classFolder = JavaIndex.getClassFolder(root); final String path = FileObjects.getRelativePath(root, source); final String ext = FileObjects.getExtension(path); final String pathNoExt = FileObjects.stripExtension(path);
if (!genSources.isEmpty()) { final File sourceFile = BaseUtilities.toFile(forSource.toURI()); final String relativePath = FileObjects.stripExtension(FileObjects.getRelativePath(sourceRoot, sourceFile)); final File cacheFile = new File (classCache, relativePath+'.'+FileObjects.RAPT); if (!cacheFile.getParentFile().exists()) { final StringBuilder sb = new StringBuilder(); for (javax.tools.FileObject file : genSources) { sb.append(FileObjects.getRelativePath(aptRootURL, file.toUri().toURL())); sb.append('\n'); //NOI18N boolean changed = false; for (javax.tools.FileObject file : genResources) { String resPath = FileObjects.getRelativePath(BaseUtilities.toURI(classCache).toURL(), file.toUri().toURL()); if (currentResources.add(resPath)) { sb.append(resPath);
@Override @CheckForNull protected URL map(@NonNull final FileObject fo) { final String relative = FileObjects.convertFolder2Package( FileObjects.stripExtension(FileObjects.getRelativePath(cacheRoot, FileUtil.toFile(fo))), File.separatorChar); final FileObject sourceFile = SourceUtils.getFile( ElementHandleAccessor.getInstance().create(ElementKind.CLASS, relative), resolveCps); return sourceFile == null ? null : sourceFile.toURL(); } }
/** * Creates {@link JavaFileObject} for a regular {@link File} * @param file for which the {@link JavaFileObject} should be created * @param root - the classpath root owning the file * @param encoding - the file's encoding * @return {@link JavaFileObject}, never returns null */ public static @NonNull PrefetchableJavaFileObject fileFileObject( final @NonNull File file, final @NonNull File root, final @NullAllowed JavaFileFilterImplementation filter, final @NullAllowed Charset encoding) { assert file != null; assert root != null; final String[] pkgNamePair = getFolderAndBaseName(getRelativePath(root,file),File.separatorChar); return new FileBase( file, convertFolder2Package(pkgNamePair[0], File.separatorChar), pkgNamePair[1], filter, encoding); }
@NonNull public static PrefetchableJavaFileObject asyncWriteFileObject( @NonNull final File file, @NonNull final File root, @NullAllowed JavaFileFilterImplementation filter, @NullAllowed Charset encoding, @NonNull final Executor pool, @NonNull final CompletionHandler<Void,Void> done) { final String[] pkgNamePair = getFolderAndBaseName(getRelativePath(root,file),File.separatorChar); return new AsyncWriteFileObject( file, convertFolder2Package(pkgNamePair[0], File.separatorChar), pkgNamePair[1], filter, encoding, pool, done); }