本文整理汇总了Java中javax.tools.JavaFileManager.Location类的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Location类属于javax.tools.JavaFileManager包,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PathDocFileFactory
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
public PathDocFileFactory(Configuration configuration) {
super(configuration);
fileManager = (PathFileManager) configuration.getFileManager();
if (!configuration.destDirName.isEmpty()
|| !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) {
try {
String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName;
Path dir = fileManager.getDefaultFileSystem().getPath(dirName);
fileManager.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir));
} catch (IOException e) {
throw new DocletAbortException(e);
}
}
destDir = fileManager.getLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next();
}
示例2: getDestDir
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
private File getDestDir() {
if (destDir == null) {
if (!configuration.destDirName.isEmpty()
|| !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) {
try {
String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName;
File dir = new File(dirName);
fileManager.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir));
} catch (IOException e) {
throw new DocletAbortException(e);
}
}
destDir = fileManager.getLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next();
}
return destDir;
}
示例3: test
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
void test(boolean hasLocation, File siblingFile, String relName, String expectedPath)
throws Exception
{
System.err.format("test: hasLocation:%s, siblingFile:%s, relName:%s, expectedPath:%s%n",
hasLocation, siblingFile, relName, expectedPath);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
if (hasLocation) {
for (Location location : StandardLocation.values()) {
System.err.format(" location:%s, moduleLocn:%b%n",
location, location.isModuleOrientedLocation());
if (!location.isOutputLocation()) {
continue;
}
fm.setLocation(location, Arrays.asList(new File(".")));
test(fm, location, siblingFile, relName, expectedPath);
}
} else {
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
}
}
}
示例4: getFileForInput
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
@Override
public javax.tools.FileObject getFileForInput(Location l, String pkgName, String relativeName) {
final String[] names = FileObjects.getFolderAndBaseName(
FileObjects.resolveRelativePath(pkgName, relativeName),
FileObjects.NBFS_SEPARATOR_CHAR);
javax.tools.FileObject fo = tx.readFileObject(l, names[0], names[1]);
if (fo != null) {
return fo;
}
if (!ModuleLocation.isInstance(l)) {
//File in output
return super.getFileForInput(l, pkgName, relativeName);
} else {
//File in module
return getFileForInputImpl(
ModuleLocation.WithExcludes.cast(l).getModuleEntries(),
pkgName,
relativeName);
}
}
示例5: getClassFolderForApt
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
private File getClassFolderForApt(
final Location l,
final String baseName) {
String[] parentName = splitParentName(baseName);
final Collection<? extends URL> roots = getLocationRoots(l);
for (ClassPath.Entry entry : this.apt.entries()) {
FileObject root = entry.getRoot();
if (root != null) {
FileObject parentFile = root.getFileObject(parentName[0]);
if (parentFile != null) {
if (parentFile.getFileObject(parentName[1], FileObjects.JAVA) != null) {
final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL());
if (classFolder != null && roots.contains(classFolder)) {
try {
return BaseUtilities.toFile(classFolder.toURI());
} catch (URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
}
}
return null;
}
示例6: getJavaFileForInput
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
@Override
public JavaFileObject getJavaFileForInput (Location l, final String className, JavaFileObject.Kind kind) {
String[] namePair = FileObjects.getParentRelativePathAndName (className);
String ext = kind == JavaFileObject.Kind.CLASS ? FileObjects.SIG : kind.extension.substring(1); //tzezula: Clearly wrong in compile on save, but "class" is also wrong
for (ClassPath.Entry entry : this.sourceRoots.entries()) {
FileObject root = entry.getRoot();
if (root != null) {
FileObject parent = root.getFileObject(namePair[0]);
if (parent != null) {
FileObject[] children = parent.getChildren();
for (FileObject child : children) {
if (namePair[1].equals(child.getName()) && ext.equalsIgnoreCase(child.getExt()) && (ignoreExcludes || entry.includes(child))) {
return FileObjects.sourceFileObject(child, root);
}
}
}
}
}
return null;
}
示例7: listLocationsForModules
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
@Override
Iterable<Set<Location>> listLocationsForModules() throws IOException {
if (!listed && outputDir != null) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(outputDir)) {
for (Path p : stream) {
getLocationForModule(p.getFileName().toString());
}
}
listed = true;
}
if (moduleTable == null || moduleTable.isEmpty())
return Collections.emptySet();
return Collections.singleton(moduleTable.locations());
}
示例8: getLocation
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
private Location getLocation(String packageName) throws IOException {
if (location == StandardLocation.MODULE_SOURCE_PATH) {
// TODO: handle invalid results
Name pack = names.fromString(packageName);
for (ModuleSymbol msym : modules.allModules()) {
PackageSymbol p = syms.getPackage(msym, pack);
if (p != null && !p.members().isEmpty()) {
return fm.getLocationForModule(location, msym.name.toString());
}
}
return null;
} else {
return location;
}
}
示例9: testBasic
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
@Test
public void testBasic(Path base) throws IOException {
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
Location[] locns = {
StandardLocation.SOURCE_PATH,
StandardLocation.CLASS_PATH,
StandardLocation.PLATFORM_CLASS_PATH,
};
// set a value
Path out = Files.createDirectories(base.resolve("out"));
for (Location locn : locns) {
checkException("unsupported for location",
IllegalArgumentException.class,
"location is not an output location or a module-oriented location: " + locn,
() -> fm.setLocationForModule(locn, "m", List.of(out)));
}
}
}
示例10: testSystemModules
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
@Test
public void testSystemModules(Path base) throws IOException {
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
Location locn = StandardLocation.SYSTEM_MODULES;
Location javaCompiler = fm.getLocationForModule(locn, "java.compiler");
// cannot easily verify default setting: could be jrt: or exploded image
Path override1 = Files.createDirectories(base.resolve("override1"));
fm.setLocationForModule(locn, "java.compiler", List.of(override1));
checkEqual("override setting 1",
fm.getLocationAsPaths(javaCompiler), override1);
Path override2 = Files.createDirectories(base.resolve("override2"));
fm.setLocationFromPaths(javaCompiler, List.of(override2));
checkEqual("override setting 2",
fm.getLocationAsPaths(javaCompiler), override2);
}
}
示例11: fillIn
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
private void fillIn(PackageSymbol p,
Location location,
Iterable<JavaFileObject> files) {
currentLoc = location;
for (JavaFileObject fo : files) {
switch (fo.getKind()) {
case CLASS:
case SOURCE: {
// TODO pass binaryName to includeClassFile
String binaryName = fileManager.inferBinaryName(currentLoc, fo);
String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1);
if (SourceVersion.isIdentifier(simpleName) ||
simpleName.equals("package-info"))
includeClassFile(p, fo);
break;
}
default:
extraFileActions(p, fo);
}
}
}
示例12: computeSubpackages
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void computeSubpackages() throws ToolException {
((List<String>) opts.computeIfAbsent(ToolOption.EXCLUDE, v -> Collections.EMPTY_LIST))
.stream()
.map(ModulePackage::new)
.forEachOrdered((mpkg) -> excludePackages.add(mpkg));
excludePackages.forEach((p) -> {
getEntry(p).excluded = true;
});
for (ModulePackage modpkg : subPackages) {
List<Location> locs = getLocation(modpkg);
for (Location loc : locs) {
addPackagesFromLocations(loc, modpkg);
}
}
}
示例13: setPathForLocation
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
void setPathForLocation(Location location, Iterable<? extends File> path) {
// TODO? if (inited) throw new IllegalStateException
// TODO: otherwise reset sourceSearchPath, classSearchPath as needed
Path p;
if (path == null) {
if (location == CLASS_PATH)
p = computeUserClassPath();
else if (location == PLATFORM_CLASS_PATH)
p = computeBootClassPath();
else if (location == ANNOTATION_PROCESSOR_PATH)
p = computeAnnotationProcessorPath();
else if (location == SOURCE_PATH)
p = computeSourcePath();
else
// no defaults for other paths
p = null;
} else {
p = new Path();
for (File f : path)
p.addFile(f, warn); // TODO: is use of warn appropriate?
}
pathsForLocation.put(location, p);
}
示例14: fillIn
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
private void fillIn(PackageSymbol p,
Location location,
Iterable<JavaFileObject> files)
{
currentLoc = location;
for (JavaFileObject fo : files) {
switch (fo.getKind()) {
case CLASS:
case SOURCE: {
// TODO pass binaryName to includeClassFile
String binaryName = fileManager.inferBinaryName(currentLoc, fo);
String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1);
if (SourceVersion.isIdentifier(simpleName) ||
simpleName.equals("package-info"))
includeClassFile(p, fo);
break;
}
default:
extraFileActions(p, fo);
}
}
}
示例15: initHandlers
import javax.tools.JavaFileManager.Location; //导入依赖的package包/类
void initHandlers() {
handlersForLocation = new HashMap<Location, LocationHandler>();
handlersForOption = new EnumMap<Option, LocationHandler>(Option.class);
LocationHandler[] handlers = {
new BootClassPathLocationHandler(),
new ClassPathLocationHandler(),
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH),
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH),
new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D),
new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S),
new OutputLocationHandler((StandardLocation.NATIVE_HEADER_OUTPUT), Option.H)
};
for (LocationHandler h: handlers) {
handlersForLocation.put(h.location, h);
for (Option o: h.options)
handlersForOption.put(o, h);
}
}