public static FileKey newName(String packageName, String rawName, String ext) { return new FileKey(packageName, rawName, ext); }
public static FileKey newName(String packageName, String name) { int pos = name.indexOf('.'); String rawName; String ext; if (pos == -1) { rawName = name; ext = ""; } else { rawName = name.substring(0, pos); ext = name.substring(pos + 1); } return newName(packageName, rawName, ext); }
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); FileManager files = getFiles(location); if (files != null) { return files.getReadable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } }
@Override public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); // Address a bug if (location == StandardLocation.SOURCE_PATH) { FileObject file = sourcePath.getReadable(key); if (file == null) { throw new FileNotFoundException("Not found:" + key.toString()); } return file; } else { FileManager files = getFiles(location); if (files != null) { return files.getWritable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } } }
@Override public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { FileManager files = getFiles(location); if (files != null) { FileKey key = FileKey.newJavaName(className, kind); return files.getWritable(key); } else { throw new UnsupportedOperationException("Location " + location + " not supported"); } } }
@Override public boolean isSameFile(FileObject a, FileObject b) { FileKey ka = ((JavaFileObjectImpl)a).getKey(); FileKey kb = ((JavaFileObjectImpl)b).getKey(); return ka.equals(kb); }
public Kind getKind() { return key.getKind(); }
public static FileKey newName(String packageName, String name) { int pos = name.indexOf('.'); String rawName; String ext; if (pos == -1) { rawName = name; ext = ""; } else { rawName = name.substring(0, pos); ext = name.substring(pos + 1); } return newName(packageName, rawName, ext); }
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); FileManager files = getFiles(location); if (files != null) { return files.getReadable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } }
@Override public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); // Address a bug if (location == StandardLocation.SOURCE_PATH) { FileObject file = sourcePath.getReadable(key); if (file == null) { throw new FileNotFoundException("Not found:" + key.toString()); } return file; } else { FileManager files = getFiles(location); if (files != null) { return files.getWritable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } } }
@Override public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { FileManager files = getFiles(location); if (files != null) { FileKey key = FileKey.newJavaName(className, kind); return files.getWritable(key); } else { throw new UnsupportedOperationException("Location " + location + " not supported"); } } }
@Override public boolean isSameFile(FileObject a, FileObject b) { FileKey ka = ((JavaFileObjectImpl)a).getKey(); FileKey kb = ((JavaFileObjectImpl)b).getKey(); return ka.equals(kb); }
public Kind getKind() { return key.getKind(); }
/** * Resolve a resource from the provided context and path. * * @param context the context of the application that will help to resolve the path source code * @param path the path of the resource to resolve * @return the resolved resource or null if it cannot be determined * @throws NullPointerException if any argument is null * @throws IllegalArgumentException if the context package is not valid */ public FileObject resolveResourceFromSourcePath(ElementHandle.Package context, Path.Absolute path) throws NullPointerException, IllegalArgumentException { return resolveResourceFromSourcePath(context, FileKey.newName(path)); }
if (f.exists() && f.isFile()) { log.info("Resolved " + coordinates + " to " + f.getAbsolutePath()); return new JavaFileObjectImpl<File>(StandardLocation.SOURCE_PATH, FileKey.newResourceName(pkg.toString(), relativeName.toString()), sourcePath, f); } else { log.info("Resolving " + coordinates + " from source path does not exists " + f.getAbsolutePath());
public static FileKey newName(String packageName, String rawName, String ext) { return new FileKey(packageName, rawName, ext); }
private <P> Collection<JavaFileObject> getFromSourcePath(ReadFileSystem<P> fs, String... compilationUnits) throws IOException { SimpleFileManager<P> manager = new SimpleFileManager<P>(StandardLocation.SOURCE_PATH, fs); ArrayList<String> tmp = new ArrayList<String>(); final ArrayList<JavaFileObject> javaFiles = new ArrayList<JavaFileObject>(); for (String compilationUnit : compilationUnits) { tmp.clear(); ArrayList<String> names = Spliterator.split(compilationUnit.substring(1), '/', tmp); String name = tmp.get(tmp.size() - 1); if (!name.endsWith(".java")) { throw new IllegalArgumentException("Illegal compilation unit: " + compilationUnit); } P file = manager.getFileSystem().getPath(names); if (file == null) { throw new IllegalArgumentException("Could not find compilation unit: " + compilationUnit); } names.remove(names.size() - 1); String pkg = Tools.join('.', names); FileKey key = FileKey.newJavaName(pkg, name); javaFiles.add(manager.getReadable(key)); } return javaFiles; }