Java Code Examples for javax.tools.FileObject#toUri()
The following examples show how to use
javax.tools.FileObject#toUri() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSqlFileQueryMetaFactory.java From doma with Apache License 2.0 | 6 votes |
File getFile(String filePath) { FileObject fileObject = getFileObject(filePath); URI uri = fileObject.toUri(); if (!uri.isAbsolute()) { uri = new File(".").toURI().resolve(uri); } File file = getCanonicalFile(new File(uri)); if (!file.exists()) { throw new AptException( Message.DOMA4019, methodElement, new Object[] {filePath, file.getAbsolutePath()}); } if (file.isDirectory()) { throw new AptException( Message.DOMA4021, methodElement, new Object[] {filePath, file.getAbsolutePath()}); } if (!IOUtil.endsWith(file, filePath)) { throw new AptException( Message.DOMA4309, methodElement, new Object[] {filePath, file.getAbsolutePath()}); } return file; }
Example 2
Source File: BatchFilerImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public FileObject getResource(Location location, CharSequence pkg, CharSequence relativeName) throws IOException { validateName(relativeName); FileObject fo = _fileManager.getFileForInput( location, pkg.toString(), relativeName.toString()); if (fo == null) { throw new FileNotFoundException("Resource does not exist : " + location + '/' + pkg + '/' + relativeName); //$NON-NLS-1$ } URI uri = fo.toUri(); if (_createdFiles.contains(uri)) { throw new FilerException("Resource already created : " + location + '/' + pkg + '/' + relativeName); //$NON-NLS-1$ } _createdFiles.add(uri); return fo; }
Example 3
Source File: BaseFileObject.java From hottub with GNU General Public License v2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 4
Source File: FileObjects.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
public static File toFile(FileObject fileObject) { // java6 returns non-absolute URI that cannot be used with new File(URI) // java7/8 produce messages for .class resources with jar:file:/ URIs URI uri = fileObject.toUri(); if (uri == null) { return null; } String path = uri.getPath(); if (path == null) { return null; } return new File(path); }
Example 5
Source File: DaoMetaFactory.java From doma with Apache License 2.0 | 5 votes |
private File getDir(String dirPath) { FileObject fileObject = getFileObject(dirPath); if (fileObject == null) { return null; } URI uri = fileObject.toUri(); if (!uri.isAbsolute()) { uri = new File(".").toURI().resolve(uri); } File dir = new File(uri); if (dir.exists() && dir.isDirectory()) { return dir; } return null; }
Example 6
Source File: BatchFilerImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public FileObject createResource(Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements) throws IOException { validateName(relativeName); FileObject fo = _fileManager.getFileForOutput( location, pkg.toString(), relativeName.toString(), null); URI uri = fo.toUri(); if (_createdFiles.contains(uri)) { throw new FilerException("Resource already created : " + location + '/' + pkg + '/' + relativeName); //$NON-NLS-1$ } _createdFiles.add(uri); return fo; }
Example 7
Source File: BaseFileObject.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 8
Source File: BaseFileObject.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 9
Source File: BaseFileObject.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 10
Source File: BaseFileObject.java From javaide with GNU General Public License v3.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 11
Source File: BaseFileObject.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 12
Source File: TreeShimsCopier.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annos, RoundEnvironment roundEnv) { for (Element el : roundEnv.getRootElements()) { if (el.getKind() != ElementKind.CLASS) continue; TypeElement type = (TypeElement) el; String qualName = type.getQualifiedName().toString(); String targetPackage = ALLOWED_CLASSES2TARGET_PACKAGE.get(qualName); if (targetPackage != null) { try { Filer filer = processingEnv.getFiler(); FileObject fo = filer.getResource(StandardLocation.SOURCE_PATH, ((PackageElement) type.getEnclosingElement()).getQualifiedName().toString(), type.getSimpleName() + ".java"); URI source = fo.toUri(); StringBuilder path2Shims = new StringBuilder(); int p = qualName.split("\\.").length; for (int i = 0; i < p; i++) { path2Shims.append("../"); } path2Shims.append("../java.source.base/src/org/netbeans/modules/java/source/TreeShims.java"); URI treeShims = source.resolve(path2Shims.toString()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (InputStream in = treeShims.toURL().openStream()) { int r; while ((r = in.read()) != (-1)) { baos.write(r); } } String content = new String(baos.toByteArray(), "UTF-8"); content = content.replace("package org.netbeans.modules.java.source;", "package " + targetPackage + ";"); try (OutputStream out = filer.createSourceFile(targetPackage + ".TreeShims", type).openOutputStream()) { out.write(content.getBytes("UTF-8")); } } catch (IOException ex) { throw new IllegalStateException(ex); } } } return false; }
Example 13
Source File: BaseFileObject.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 14
Source File: BaseFileObject.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 15
Source File: BaseFileObject.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 16
Source File: TestingJavaFileManager.java From doma with Apache License 2.0 | 4 votes |
@Override public FileObject getFileForOutput( final Location location, final String packageName, final String relativeName, final FileObject sibling) throws IOException { if (relativeName.endsWith(".java")) { return getJavaFileForOutput(location, packageName + "." + relativeName, Kind.SOURCE, sibling); } if (relativeName.endsWith(".class")) { return getJavaFileForOutput(location, packageName + "." + relativeName, Kind.CLASS, sibling); } final String key = createKey(packageName, relativeName); if (fileObjects.containsKey(key)) { return fileObjects.get(key); } byte[] content = null; URI uri = null; try { FileObject originalFileObject = null; if (location == StandardLocation.CLASS_OUTPUT) { // Because resources are not copied to the CLASS_OUTPUT in the Aptina Unit environment, we // read // them from SOURCE_PATH first originalFileObject = super.getFileForInput(StandardLocation.SOURCE_PATH, packageName, relativeName); } if (originalFileObject == null) { originalFileObject = super.getFileForOutput(location, packageName, relativeName, sibling); } uri = originalFileObject.toUri(); content = IOUtils.readBytes(originalFileObject.openInputStream()); } catch (final FileNotFoundException ignore) { } final InMemoryJavaFileObject fileObject = new InMemoryJavaFileObject( uri != null ? uri : toURI(location, packageName, relativeName), Kind.OTHER, charset, content); fileObjects.put(key, fileObject); return fileObject; }
Example 17
Source File: PathFileObject.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. * @param fo the file object * @return the simple name of the file object */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }
Example 18
Source File: PathFileObject.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. * @param fo the file object * @return the simple name of the file object */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }