Java Code Examples for javax.tools.StandardLocation#SOURCE_PATH

The following examples show how to use javax.tools.StandardLocation#SOURCE_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: SetLocationForModule.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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)));
        }
    }
}
 
Example 2
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 3
Source File: PathDocFileFactory.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
Iterable<DocFile> list(Location location, DocPath path) {
    if (location != StandardLocation.SOURCE_PATH)
        throw new IllegalArgumentException();

    Set<DocFile> files = new LinkedHashSet<DocFile>();
    if (fileManager.hasLocation(location)) {
        for (Path f: fileManager.getLocation(location)) {
            if (Files.isDirectory(f)) {
                f = f.resolve(path.getPath());
                if (Files.exists(f))
                    files.add(new StandardDocFile(f));
            }
        }
    }
    return files;
}
 
Example 4
Source File: Locations.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
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: Locations.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 7
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 8
Source File: Locations.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 9
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 10
Source File: MemoryBasedJavaFileManager.java    From spring-init with Apache License 2.0 5 votes vote down vote up
@Override
public String inferBinaryName(Location location, JavaFileObject file) {
	if (location == StandardLocation.SOURCE_PATH) {
		return null;
	}
	// Kind of ignoring location here... assuming we want basically the FQ type name
	// Example value from getName(): javax/validation/bootstrap/GenericBootstrap.class
	String classname = file.getName().replace('/', '.').replace('\\', '.');
	return classname.substring(0, classname.lastIndexOf(".class"));
}
 
Example 11
Source File: NewDependencyCollector.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void collectPubApisOfDependencies(Context context,
                                          Collection<JavaFileObject> explicitJFOs) {
    PubAPIs pubApis = PubAPIs.instance(context);
    for (CompletionNode cDepNode : getDependencyNodes(context, explicitJFOs, false)) {
        ClassSymbol cs = cDepNode.getClassSymbol().outermostClass();
        Location loc = getLocationOf(cs);
        // We're completely ignorant of PLATFORM_CLASS_PATH classes
        if (loc == StandardLocation.CLASS_PATH || loc == StandardLocation.SOURCE_PATH)
            pubApis.visitPubapi(cs);
    }
}
 
Example 12
Source File: InMemoryJavaFileObject.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
public static InMemoryJavaFileObject getSourceJavaFileObject(String className,
		String content) {
	InMemoryJavaFileObject retval = new InMemoryJavaFileObject();
	retval.location = StandardLocation.SOURCE_PATH;
	retval.className = className;
	retval.kind = Kind.SOURCE;
	retval.content = content.getBytes();
	return retval;
}
 
Example 13
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 14
Source File: MemoryBasedJavaFileManager.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Override
public String inferBinaryName(Location location, JavaFileObject file) {
	if (location == StandardLocation.SOURCE_PATH) {
		return null;
	}
	// Kind of ignoring location here... assuming we want basically the FQ type name
	// Example value from getName(): javax/validation/bootstrap/GenericBootstrap.class
	String classname = file.getName().replace('/', '.').replace('\\', '.');
	return classname.substring(0, classname.lastIndexOf(".class"));
}
 
Example 15
Source File: InMemoryJavaFileObject.java    From spring-init with Apache License 2.0 5 votes vote down vote up
public static InMemoryJavaFileObject getSourceJavaFileObject(String className, String content) {
	InMemoryJavaFileObject retval = new InMemoryJavaFileObject();
	retval.location = StandardLocation.SOURCE_PATH;
	retval.className = className;
	retval.kind = Kind.SOURCE;
	retval.content = content.getBytes();
	return retval;
}
 
Example 16
Source File: Locations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void initHandlers() {
    handlersForLocation = new HashMap<>();
    handlersForOption = new EnumMap<>(Option.class);

    BasicLocationHandler[] handlers = {
        new BootClassPathLocationHandler(),
        new ClassPathLocationHandler(),
        new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH),
        new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH),
        new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH),
        new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
        new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
        new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
        new ModuleSourcePathLocationHandler(),
        new PatchModulesLocationHandler(),
        new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
        new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH),
        new SystemModulesLocationHandler(),
    };

    for (BasicLocationHandler h : handlers) {
        handlersForLocation.put(h.location, h);
        for (Option o : h.options) {
            handlersForOption.put(o, h);
        }
    }
}
 
Example 17
Source File: ClassDocImpl.java    From TencentKona-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 18
Source File: ClassDocImpl.java    From jdk8u60 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 19
Source File: FileSystemFileManager.java    From kalang with MIT License 4 votes vote down vote up
@Override
public boolean hasLocation(Location location) {
    return fm.hasLocation(location)
            ||  (location == StandardLocation.SOURCE_PATH && sourcePaths.size() > 0);
}
 
Example 20
Source File: ClassDocImpl.java    From openjdk-8-source 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;
}