Java Code Examples for javax.tools.StandardLocation#MODULE_SOURCE_PATH

The following examples show how to use javax.tools.StandardLocation#MODULE_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: ModuleSourceFileManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
@CheckForNull
public Location getLocationForModule(Location location, JavaFileObject jfo) throws IOException {
    if (location != StandardLocation.MODULE_SOURCE_PATH) {
        throw new IllegalStateException(String.format("Unsupported location: %s", location));
    }
    final FileObject fo = URLMapper.findFileObject(jfo.toUri().toURL());
    if (fo != null) {
        for (ModuleLocation.WithExcludes moduleLocation : sourceModuleLocationsRemovedPatches()) {
            for (ClassPath.Entry moduleEntry : moduleLocation.getModuleEntries()) {
                final FileObject root = moduleEntry.getRoot();
                if (root != null && FileUtil.isParentOf(root, fo)) {
                    return moduleLocation;
                }
            }
        }
    }
    return null;
}
 
Example 2
Source File: JavadocTool.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example 3
Source File: ModuleSourceFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@NonNull
public Iterable<Set<Location>> listLocationsForModules(@NonNull final Location location) throws IOException {
    if (location != StandardLocation.MODULE_SOURCE_PATH) {
        throw new IllegalStateException(String.format("Unsupported location: %s", location));
    }
    return sourceModuleLocationsRemovedPatches().stream().map(
            loc -> Collections.singleton((Location)loc)
    ).collect(Collectors.toSet());
}
 
Example 4
Source File: ModuleSourceFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@CheckForNull
public Location getLocationForModule(Location location, String moduleName) throws IOException {
    if (location != StandardLocation.MODULE_SOURCE_PATH) {
        throw new IllegalStateException(String.format("Unsupported location: %s", location));
    }
    for (ModuleLocation.WithExcludes moduleLocation : sourceModuleLocationsRemovedPatches()) {
        if (Objects.equals(moduleName, moduleLocation.getModuleName())) {
            return moduleLocation;
        }
    }
    return null;
}
 
Example 5
Source File: SetLocationForModule.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public void testModuleSourcePath(Path base) throws IOException {
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {

            Location locn = StandardLocation.MODULE_SOURCE_PATH;

            Path src1 = Files.createDirectories(base.resolve("src1"));
            Path src1_m = src1.resolve("m");
            tb.writeJavaFiles(src1_m, "module m { }");
//            fm.setLocationFromPaths(locn, List.of(src1));
            fm.handleOption("--module-source-path", List.of(src1.toString()).iterator());

            Location m = fm.getLocationForModule(locn, "m");
            checkEqual("default setting",
                    fm.getLocationAsPaths(m), src1.resolve("m"));

            Path override1 = Files.createDirectories(base.resolve("override1"));
            tb.writeJavaFiles(override1, "module m { }");
            fm.setLocationForModule(locn, "m", List.of(override1));
            checkEqual("override setting 1",
                    fm.getLocationAsPaths(m), override1);

            Path override2 = Files.createDirectories(base.resolve("override2"));
            tb.writeJavaFiles(override2, "module m { }");
            fm.setLocationFromPaths(m, List.of(override2));
            checkEqual("override setting 2",
                    fm.getLocationAsPaths(m), override2);

            Path src2 = Files.createDirectories(base.resolve("src2"));
            Path src2_m = src2.resolve("m");
            tb.writeJavaFiles(src2_m, "module m { }");
//            fm.setLocationFromPaths(locn, List.of(src2));
            fm.handleOption("--module-source-path", List.of(src2.toString()).iterator());

            checkEqual("updated setting",
                    fm.getLocationAsPaths(m), src2.resolve("m"));
        }
    }
 
Example 6
Source File: ModuleFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) {
    ListBuffer<ModuleSymbol> results = new ListBuffer<>();
    Map<Name, Location> namesInSet = new HashMap<>();
    boolean multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
    while (moduleLocationIterator.hasNext()) {
        Set<Location> locns = (moduleLocationIterator.next());
        namesInSet.clear();
        for (Location l: locns) {
            try {
                Name n = names.fromString(fileManager.inferModuleName(l));
                if (namesInSet.put(n, l) == null) {
                    ModuleSymbol msym = syms.enterModule(n);
                    if (msym.sourceLocation != null || msym.classLocation != null) {
                        // module has already been found, so ignore this instance
                        continue;
                    }
                    if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) &&
                        msym.patchLocation == null) {
                        msym.patchLocation =
                                fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH,
                                                                 msym.name.toString());
                        if (msym.patchLocation != null &&
                            multiModuleMode &&
                            fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.patchOutputLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    }
                    if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
                        msym.sourceLocation = l;
                        if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.classLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    } else {
                        msym.classLocation = l;
                    }
                    if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES ||
                        moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) {
                        msym.flags_field |= Flags.SYSTEM_MODULE;
                    }
                    if (toFind == null ||
                        (toFind == msym && (msym.sourceLocation != null || msym.classLocation != null))) {
                        // Note: cannot return msym directly, because we must finish
                        // processing this set first
                        results.add(msym);
                    }
                } else {
                    log.error(Errors.DuplicateModuleOnPath(
                            getDescription(moduleLocationIterator.outer), n));
                }
            } catch (IOException e) {
                // skip location for now?  log error?
            }
        }
        if (toFind != null && results.nonEmpty())
            return results.toList();
    }

    return results.toList();
}
 
Example 7
Source File: Locations.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
ModuleSourceFileLocationHandler() {
    super(StandardLocation.MODULE_SOURCE_PATH,
            Option.MODULE_SOURCE_PATH);
}
 
Example 8
Source File: ModuleSourceFileManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasLocation(Location location) {
    return location == StandardLocation.MODULE_SOURCE_PATH;
}
 
Example 9
Source File: ModuleFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) {
    ListBuffer<ModuleSymbol> results = new ListBuffer<>();
    Map<Name, Location> namesInSet = new HashMap<>();
    boolean multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
    while (moduleLocationIterator.hasNext()) {
        Set<Location> locns = (moduleLocationIterator.next());
        namesInSet.clear();
        for (Location l: locns) {
            try {
                Name n = names.fromString(fileManager.inferModuleName(l));
                if (namesInSet.put(n, l) == null) {
                    ModuleSymbol msym = syms.enterModule(n);
                    if (msym.sourceLocation != null || msym.classLocation != null) {
                        // module has already been found, so ignore this instance
                        continue;
                    }
                    if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) &&
                        msym.patchLocation == null) {
                        msym.patchLocation =
                                fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH,
                                                                 msym.name.toString());
                        if (msym.patchLocation != null &&
                            multiModuleMode &&
                            fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.patchOutputLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    }
                    if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
                        msym.sourceLocation = l;
                        if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.classLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    } else {
                        msym.classLocation = l;
                    }
                    if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES ||
                        moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) {
                        msym.flags_field |= Flags.SYSTEM_MODULE;
                    }
                    if (toFind == null ||
                        (toFind == msym && (msym.sourceLocation != null || msym.classLocation != null))) {
                        // Note: cannot return msym directly, because we must finish
                        // processing this set first
                        results.add(msym);
                    }
                } else {
                    log.error(Errors.DuplicateModuleOnPath(
                            getDescription(moduleLocationIterator.outer), n));
                }
            } catch (IOException e) {
                // skip location for now?  log error?
            }
        }
        if (toFind != null && results.nonEmpty())
            return results.toList();
    }

    return results.toList();
}
 
Example 10
Source File: Locations.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
ModuleSourcePathLocationHandler() {
    super(StandardLocation.MODULE_SOURCE_PATH,
            Option.MODULE_SOURCE_PATH);
}