Java Code Examples for javax.tools.StandardLocation#CLASS_PATH

The following examples show how to use javax.tools.StandardLocation#CLASS_PATH . 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: JavadocTool.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Recursively search all directories in path for subdirectory name.
 * Add all packages found in such a directory to packages list.
 */
private Map<String,List<JavaFileObject>> searchSubPackages(
        List<String> subPackages,
        ListBuffer<String> packages,
        List<String> excludedPackages)
        throws IOException {
    Map<String,List<JavaFileObject>> packageFiles =
            new HashMap<String,List<JavaFileObject>>();

    Map<String,Boolean> includedPackages = new HashMap<String,Boolean>();
    includedPackages.put("", true);
    for (String p: excludedPackages)
        includedPackages.put(p, false);

    StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
            ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

    searchSubPackages(subPackages,
            includedPackages,
            packages, packageFiles,
            path,
            EnumSet.of(JavaFileObject.Kind.SOURCE));

    return packageFiles;
}
 
Example 2
Source File: StandardDocFileFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
Iterable<DocFile> list(Location location, DocPath path) {
    Location l = ((location == StandardLocation.SOURCE_PATH)
            && !fileManager.hasLocation(StandardLocation.SOURCE_PATH))
            ? StandardLocation.CLASS_PATH
            : location;

    Set<DocFile> files = new LinkedHashSet<>();
    for (Path f: fileManager.getLocationAsPaths(l)) {
        if (Files.isDirectory(f)) {
            f = f.resolve(path.getPath());
            if (Files.exists(f))
                files.add(new StandardDocFile(f));
        }
    }
    return files;
}
 
Example 3
Source File: JavadocTool.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Recursively search all directories in path for subdirectory name.
 * Add all packages found in such a directory to packages list.
 */
private Map<String,List<JavaFileObject>> searchSubPackages(
        List<String> subPackages,
        ListBuffer<String> packages,
        List<String> excludedPackages)
        throws IOException {
    Map<String,List<JavaFileObject>> packageFiles =
            new HashMap<String,List<JavaFileObject>>();

    Map<String,Boolean> includedPackages = new HashMap<String,Boolean>();
    includedPackages.put("", true);
    for (String p: excludedPackages)
        includedPackages.put(p, false);

    StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
            ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

    searchSubPackages(subPackages,
            includedPackages,
            packages, packageFiles,
            path,
            EnumSet.of(JavaFileObject.Kind.SOURCE));

    return packageFiles;
}
 
Example 4
Source File: JavadocTool.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Recursively search all directories in path for subdirectory name.
 * Add all packages found in such a directory to packages list.
 */
private Map<String,List<JavaFileObject>> searchSubPackages(
        List<String> subPackages,
        ListBuffer<String> packages,
        List<String> excludedPackages)
        throws IOException {
    Map<String,List<JavaFileObject>> packageFiles =
            new HashMap<String,List<JavaFileObject>>();

    Map<String,Boolean> includedPackages = new HashMap<String,Boolean>();
    includedPackages.put("", true);
    for (String p: excludedPackages)
        includedPackages.put(p, false);

    StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
            ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

    searchSubPackages(subPackages,
            includedPackages,
            packages, packageFiles,
            path,
            EnumSet.of(JavaFileObject.Kind.SOURCE));

    return packageFiles;
}
 
Example 5
Source File: JavadocTool.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Recursively search all directories in path for subdirectory name.
 * Add all packages found in such a directory to packages list.
 */
private Map<String,List<JavaFileObject>> searchSubPackages(
        List<String> subPackages,
        ListBuffer<String> packages,
        List<String> excludedPackages)
        throws IOException {
    Map<String,List<JavaFileObject>> packageFiles =
            new HashMap<String,List<JavaFileObject>>();

    Map<String,Boolean> includedPackages = new HashMap<String,Boolean>();
    includedPackages.put("", true);
    for (String p: excludedPackages)
        includedPackages.put(p, false);

    StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
            ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

    searchSubPackages(subPackages,
            includedPackages,
            packages, packageFiles,
            path,
            EnumSet.of(JavaFileObject.Kind.SOURCE));

    return packageFiles;
}
 
Example 6
Source File: StandardDocFileFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
Iterable<DocFile> list(Location location, DocPath path) {
    Location l = ((location == StandardLocation.SOURCE_PATH)
            && !fileManager.hasLocation(StandardLocation.SOURCE_PATH))
            ? StandardLocation.CLASS_PATH
            : location;

    Set<DocFile> files = new LinkedHashSet<>();
    for (Path f: fileManager.getLocationAsPaths(l)) {
        if (Files.isDirectory(f)) {
            f = f.resolve(path.getPath());
            if (Files.exists(f))
                files.add(new StandardDocFile(f));
        }
    }
    return files;
}
 
Example 7
Source File: JavadocTool.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Recursively search all directories in path for subdirectory name.
 * Add all packages found in such a directory to packages list.
 */
private Map<String,List<JavaFileObject>> searchSubPackages(
        List<String> subPackages,
        ListBuffer<String> packages,
        List<String> excludedPackages)
        throws IOException {
    Map<String,List<JavaFileObject>> packageFiles =
            new HashMap<String,List<JavaFileObject>>();

    Map<String,Boolean> includedPackages = new HashMap<String,Boolean>();
    includedPackages.put("", true);
    for (String p: excludedPackages)
        includedPackages.put(p, false);

    StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
            ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

    searchSubPackages(subPackages,
            includedPackages,
            packages, packageFiles,
            path,
            EnumSet.of(JavaFileObject.Kind.SOURCE));

    return packageFiles;
}
 
Example 8
Source File: JavaCodeScriptEngine.java    From chaosblade-exec-jvm with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse)
    throws IOException {
    if (location == StandardLocation.PLATFORM_CLASS_PATH) {
        return super.list(location, packageName, kinds, recurse);
    } else if (location == StandardLocation.CLASS_PATH && kinds.contains(JavaFileObject.Kind.CLASS)) {
        if (packageName.startsWith("java")) {
            return super.list(location, packageName, kinds, recurse);
        } else {
            return find(packageName);
        }
    }
    return Collections.emptyList();
}
 
Example 9
Source File: MemoryBasedJavaFileManager.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasLocation(Location location) {
	logger.debug("hasLocation({})", location);
	return (location == StandardLocation.SOURCE_PATH
			|| location == StandardLocation.CLASS_PATH
			|| location == StandardLocation.PLATFORM_CLASS_PATH);
}
 
Example 10
Source File: ClassFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Load directory of package into members scope.
 */
private void fillIn(PackageSymbol p) throws IOException {
    if (p.members_field == null)
        p.members_field = WriteableScope.create(p);

    ModuleSymbol msym = p.modle;

    Assert.checkNonNull(msym, p::toString);

    msym.complete();

    if (msym == syms.noModule) {
        preferCurrent = false;
        if (userPathsFirst) {
            scanUserPaths(p, true);
            preferCurrent = true;
            scanPlatformPath(p);
        } else {
            scanPlatformPath(p);
            scanUserPaths(p, true);
        }
    } else if (msym.classLocation == StandardLocation.CLASS_PATH) {
        scanUserPaths(p, msym.sourceLocation == StandardLocation.SOURCE_PATH);
    } else {
        scanModulePaths(p, msym);
    }
}
 
Example 11
Source File: ClassFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Load directory of package into members scope.
 */
private void fillIn(PackageSymbol p) throws IOException {
    if (p.members_field == null)
        p.members_field = WriteableScope.create(p);

    ModuleSymbol msym = p.modle;

    Assert.checkNonNull(msym, p::toString);

    msym.complete();

    if (msym == syms.noModule) {
        preferCurrent = false;
        if (userPathsFirst) {
            scanUserPaths(p, true);
            preferCurrent = true;
            scanPlatformPath(p);
        } else {
            scanPlatformPath(p);
            scanUserPaths(p, true);
        }
    } else if (msym.classLocation == StandardLocation.CLASS_PATH) {
        scanUserPaths(p, msym.sourceLocation == StandardLocation.SOURCE_PATH);
    } else {
        scanModulePaths(p, msym);
    }
}
 
Example 12
Source File: Locations.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
ClassPathLocationHandler() {
    super(StandardLocation.CLASS_PATH,
            Option.CLASSPATH, Option.CP);
}
 
Example 13
Source File: AsyncJavaSymbolDescriptor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasLocation(Location location) {
    return location == StandardLocation.CLASS_PATH || location == StandardLocation.PLATFORM_CLASS_PATH;
}
 
Example 14
Source File: Locations.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
ClassPathLocationHandler() {
    super(StandardLocation.CLASS_PATH,
            Option.CLASSPATH, Option.CP);
}
 
Example 15
Source File: Utils.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Location defaultLocation() {
    JavaFileManager fm = configuration.docEnv.getJavaFileManager();
    return fm.hasLocation(StandardLocation.SOURCE_PATH)
            ? StandardLocation.SOURCE_PATH
            : StandardLocation.CLASS_PATH;
}
 
Example 16
Source File: ClassDocImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the package that this class is contained in.
 */
@Override
public PackageDoc containingPackage() {
    PackageDocImpl p = env.getPackageDoc(tsym.packge());
    if (p.setDocPath == false) {
        FileObject docPath;
        try {
            Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
                ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

            docPath = env.fileManager.getFileForInput(
                    location, p.qualifiedName(), "package.html");
        } catch (IOException e) {
            docPath = null;
        }

        if (docPath == null) {
            // fall back on older semantics of looking in same directory as
            // source file for this class
            SourcePosition po = position();
            if (env.fileManager instanceof StandardJavaFileManager &&
                    po instanceof SourcePositionImpl) {
                URI uri = ((SourcePositionImpl) po).filename.toUri();
                if ("file".equals(uri.getScheme())) {
                    File f = new File(uri);
                    File dir = f.getParentFile();
                    if (dir != null) {
                        File pf = new File(dir, "package.html");
                        if (pf.exists()) {
                            StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager;
                            docPath = sfm.getJavaFileObjects(pf).iterator().next();
                        }
                    }

                }
            }
        }

        p.setDocPath(docPath);
    }
    return p;
}
 
Example 17
Source File: MemoryBasedJavaFileManager.java    From spring-init with Apache License 2.0 4 votes vote down vote up
@Override
	public Iterable<JavaFileObject> list(Location location, String packageName,
			Set<Kind> kinds, boolean recurse) throws IOException {
		logger.debug("list({},{},{},{})", location, packageName, kinds, recurse);
		String classpath = "";
		Path moduleRootPath = null;
		if (location instanceof JDKModuleLocation && (kinds == null || kinds.contains(Kind.CLASS))) {
			// list(org.springframework.cloud.function.compiler.java.MemoryBasedJavaFileManager$JDKModuleLocation@550a1967,
			//      java.lang,[SOURCE, CLASS, HTML, OTHER],false)
			moduleRootPath = ((JDKModuleLocation)location).getModuleRootPath();
			logger.info("For JDKModuleLocation "+location.toString()+" root path is "+moduleRootPath);
		} else if (location == StandardLocation.PLATFORM_CLASS_PATH
				&& (kinds == null || kinds.contains(Kind.CLASS))) {
			classpath = getPlatformClassPath();
//			if (classpath.length() == 0) {
//			if (hasJrtFsPath()) {
//				classpath = getJrtFsPath();
//			}
//		}
			logger.debug("Creating iterable for boot class path: {}", classpath);
		}
		else if (location == StandardLocation.CLASS_PATH
				&& (kinds == null || kinds.contains(Kind.CLASS))) {
			String javaClassPath = getClassPath();
			if (!resolvedAdditionalDependencies.isEmpty()) {
				for (File resolvedAdditionalDependency : resolvedAdditionalDependencies
						.values()) {
					javaClassPath += File.pathSeparatorChar + resolvedAdditionalDependency
							.toURI().toString().substring("file:".length());
				}
			}
			classpath = javaClassPath;
			logger.debug("Creating iterable for class path: {}", classpath);
		}
		Key k = new Key(location, classpath, packageName, kinds, recurse);
		CloseableFilterableJavaFileObjectIterable resultIterable = iterables.get(k);
		if (resultIterable == null) {
			if (moduleRootPath != null) {
				resultIterable = new IterableJrtModule(compilationInfoCache, moduleRootPath, packageName, recurse);
			} else {
				resultIterable = new IterableClasspath(compilationInfoCache, classpath, packageName, recurse);
			}
			iterables.put(k, resultIterable);
		}
		resultIterable.reset();
		return resultIterable;
	}
 
Example 18
Source File: Locations.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
ClassPathLocationHandler() {
    super(StandardLocation.CLASS_PATH,
            Option.CLASSPATH, Option.CP);
}
 
Example 19
Source File: ClassDocImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the package that this class is contained in.
 */
@Override
public PackageDoc containingPackage() {
    PackageDocImpl p = env.getPackageDoc(tsym.packge());
    if (p.setDocPath == false) {
        FileObject docPath;
        try {
            Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
                ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

            docPath = env.fileManager.getFileForInput(
                    location, p.qualifiedName(), "package.html");
        } catch (IOException e) {
            docPath = null;
        }

        if (docPath == null) {
            // fall back on older semantics of looking in same directory as
            // source file for this class
            SourcePosition po = position();
            if (env.fileManager instanceof StandardJavaFileManager &&
                    po instanceof SourcePositionImpl) {
                URI uri = ((SourcePositionImpl) po).filename.toUri();
                if ("file".equals(uri.getScheme())) {
                    File f = new File(uri);
                    File dir = f.getParentFile();
                    if (dir != null) {
                        File pf = new File(dir, "package.html");
                        if (pf.exists()) {
                            StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager;
                            docPath = sfm.getJavaFileObjects(pf).iterator().next();
                        }
                    }

                }
            }
        }

        p.setDocPath(docPath);
    }
    return p;
}
 
Example 20
Source File: ClassDocImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the package that this class is contained in.
 */
@Override
public PackageDoc containingPackage() {
    PackageDocImpl p = env.getPackageDoc(tsym.packge());
    if (p.setDocPath == false) {
        FileObject docPath;
        try {
            Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
                ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;

            docPath = env.fileManager.getFileForInput(
                    location, p.qualifiedName(), "package.html");
        } catch (IOException e) {
            docPath = null;
        }

        if (docPath == null) {
            // fall back on older semantics of looking in same directory as
            // source file for this class
            SourcePosition po = position();
            if (env.fileManager instanceof StandardJavaFileManager &&
                    po instanceof SourcePositionImpl) {
                URI uri = ((SourcePositionImpl) po).filename.toUri();
                if ("file".equals(uri.getScheme())) {
                    File f = new File(uri);
                    File dir = f.getParentFile();
                    if (dir != null) {
                        File pf = new File(dir, "package.html");
                        if (pf.exists()) {
                            StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager;
                            docPath = sfm.getJavaFileObjects(pf).iterator().next();
                        }
                    }

                }
            }
        }

        p.setDocPath(docPath);
    }
    return p;
}