Java Code Examples for javax.tools.StandardLocation#CLASS_OUTPUT

The following examples show how to use javax.tools.StandardLocation#CLASS_OUTPUT . 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: 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 2
Source File: BootClassPathUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    if (location == StandardLocation.CLASS_OUTPUT) {
        List<JavaFileObject> result = new ArrayList<>();
        FileObject pack = output.getFileObject(packageName.replace('.', '/'));

        if (pack != null) {
            Enumeration<? extends FileObject> c = pack.getChildren(recurse);

            while (c.hasMoreElements()) {
                FileObject file = c.nextElement();
                if (!file.hasExt("class"))
                    continue;
                result.add(new InferableJavaFileObject(file, JavaFileObject.Kind.CLASS));
            }
        }

        return result;
    }
    return super.list(location, packageName, kinds, recurse);
}
 
Example 3
Source File: BootClassPathUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    if (location == StandardLocation.CLASS_OUTPUT) {
        List<JavaFileObject> result = new ArrayList<>();
        FileObject pack = output.getFileObject(packageName.replace('.', '/'));

        if (pack != null) {
            Enumeration<? extends FileObject> c = pack.getChildren(recurse);

            while (c.hasMoreElements()) {
                FileObject file = c.nextElement();
                if (!file.hasExt("class"))
                    continue;
                result.add(new InferableJavaFileObject(file, JavaFileObject.Kind.CLASS));
            }
        }

        return result;
    }
    return super.list(location, packageName, kinds, recurse);
}
 
Example 4
Source File: ModuleNamesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException {
    if (location == StandardLocation.CLASS_OUTPUT) {
        return Collections.emptySet();
    } else if (location == StandardLocation.SYSTEM_MODULES) {
        final ClassPath cp = JavaPlatform.getDefault().getBootstrapLibraries();
        Collection<? extends URL> javaBase = findJavaBase(cp);
        if (javaBase.isEmpty()) {
            javaBase = fakeJavaBase(cp);
        }
        return Collections.singleton(Collections.singleton(new ModLoc(
                StandardLocation.SYSTEM_MODULES,
                "java.base",    //NOI18N
                javaBase)));
    } else {
        return Collections.emptySet();
    }
}
 
Example 5
Source File: ModuleFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public ModuleSymbol findSingleModule() {
    try {
        JavaFileObject src_fo = getModuleInfoFromLocation(StandardLocation.SOURCE_PATH, Kind.SOURCE);
        JavaFileObject class_fo = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
        JavaFileObject fo = (src_fo == null) ? class_fo
                : (class_fo == null) ? src_fo
                        : classFinder.preferredFileObject(src_fo, class_fo);

        ModuleSymbol msym;
        if (fo == null) {
            msym = syms.unnamedModule;
        } else {
            msym = readModule(fo);
        }

        if (msym.patchLocation == null) {
            msym.classLocation = StandardLocation.CLASS_OUTPUT;
        } else {
            msym.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
        }
        return msym;

    } catch (IOException e) {
        throw new Error(e); // FIXME
    }
}
 
Example 6
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 7
Source File: SetLocationForModule.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testOutput_nested(Path base) throws IOException {
    try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
        Location locn = StandardLocation.CLASS_OUTPUT;

        Path out1 = Files.createDirectories(base.resolve("out1"));
        fm.setLocationForModule(locn, "m", List.of(out1));

        Location m = fm.getLocationForModule(locn, "m");
        checkEqual("initial setting",
                fm.getLocationAsPaths(m), out1);

        Path out2 = Files.createDirectories(base.resolve("out2"));
        checkException("create nested module",
                UnsupportedOperationException.class, "not supported for CLASS_OUTPUT[m]",
                () -> fm.setLocationForModule(m, "x", List.of(out2)));
    }
}
 
Example 8
Source File: Locations.java    From openjdk-8 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: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine the location for the module on the module source path
 * or source output directory which contains a given CompilationUnit.
 * If the source output directory is unset, the class output directory
 * will be checked instead.
 * {@code null} is returned if no such module can be found.
 * @param tree the compilation unit tree
 * @return the location for the enclosing module
 * @throws IOException if there is a problem while searching for the module.
 */
private Location getModuleLocation(JCCompilationUnit tree) throws IOException {
    JavaFileObject fo = tree.sourcefile;

    Location loc =
            fileManager.getLocationForModule(StandardLocation.MODULE_SOURCE_PATH, fo);
    if (loc == null) {
        Location sourceOutput = fileManager.hasLocation(StandardLocation.SOURCE_OUTPUT) ?
                StandardLocation.SOURCE_OUTPUT : StandardLocation.CLASS_OUTPUT;
        loc =
            fileManager.getLocationForModule(sourceOutput, fo);
    }
    return loc;
}
 
Example 10
Source File: Locations.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void initHandlers() {
    handlersForLocation = new HashMap<>();
    handlersForOption = new EnumMap<>(Option.class);

    BasicLocationHandler[] handlers = {
        new BootClassPathLocationHandler(StandardLocation.PLATFORM_CLASS_PATH),
        new BootClassPathLocationHandler(StandardLocation.SYSTEM_MODULES),
        new ClassFileLocationHandler(),
        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 ModuleSourceFileLocationHandler(),
        new PatchModulesLocationHandler(),
        new ModuleFileLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
        new ModuleFileLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH)
    };

    for (BasicLocationHandler h : handlers) {
        handlersForLocation.put(h.location, h);
        for (Option o : h.options) {
            handlersForOption.put(o, h);
        }
    }
}
 
Example 11
Source File: InMemoryJavaFileManager.java    From toothpick with Apache License 2.0 5 votes vote down vote up
public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind)
    throws IOException {
  if (location == StandardLocation.CLASS_OUTPUT
      && buffers.containsKey(className)
      && kind == Kind.CLASS) {
    final byte[] bytes = buffers.get(className).toByteArray();
    return new SimpleJavaFileObject(URI.create(className), kind) {
      public InputStream openInputStream() {
        return new ByteArrayInputStream(bytes);
      }
    };
  }
  return fileManager.getJavaFileForInput(location, className, kind);
}
 
Example 12
Source File: ModuleNamesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    if (location == StandardLocation.CLASS_OUTPUT) {
        return bootstrap ?
                listModuleContent(
                        (ModLoc) listLocationsForModules(StandardLocation.SYSTEM_MODULES).iterator().next().iterator().next(),
                        packageName,
                        kinds) :
                Collections.emptyList();
    } else if (location instanceof ModLoc) {
        return listModuleContent((ModLoc)location, packageName, kinds);
    } else {
        return Collections.emptyList();
    }
}
 
Example 13
Source File: MemoryOutputJavaFileManager.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@Override
public JavaFileObject getJavaFileForInput(Location location,
        String className, Kind kind) throws IOException {
    JavaFileObject result;
    if (StandardLocation.CLASS_OUTPUT == location && Kind.CLASS == kind) {
        result = outputMap.get(className);
        if (result == null) {
            result = super.getJavaFileForInput(location, className, kind);
        }
    } else {
        result = super.getJavaFileForInput(location, className, kind);
    }
    return result;
}
 
Example 14
Source File: DynamicJavaFileManager.java    From oxygen with Apache License 2.0 5 votes vote down vote up
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind,
    FileObject sibling) throws IOException {
  if (kind == Kind.CLASS && location == StandardLocation.CLASS_OUTPUT) {
    ByteCode byteCode = byteCodes.get(className);
    if (byteCode == null) {
      byteCode = new ByteCode(className, kind);
      byteCodes.put(className, byteCode);
    }
    return byteCode;
  }
  return super.getJavaFileForOutput(location, className, kind, sibling);
}
 
Example 15
Source File: SetLocationForModule.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testOutput_invalid(Path base) throws IOException {
    try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
        Location locn = StandardLocation.CLASS_OUTPUT;
        // set a top default
        Path out1 = Files.createDirectories(base.resolve("out1"));
        fm.setLocationFromPaths(locn, List.of(out1));
        // getLocnForModule
        Location m = fm.getLocationForModule(locn, "m");
        checkEqual("default setting",
                fm.getLocationAsPaths(m), out1.resolve("m"));

        checkException("empty arg list",
                IllegalArgumentException.class, "empty path for directory",
                () -> fm.setLocationFromPaths(m, Collections.emptyList()));

        Path out2 = Files.createDirectories(base.resolve("out2"));
        checkException("empty arg list",
                IllegalArgumentException.class, "path too long for directory",
                () -> fm.setLocationFromPaths(m, List.of(out2, out2)));

        Path notExist = base.resolve("notExist");
        checkException("not exist",
                FileNotFoundException.class, notExist + ": does not exist",
                () -> fm.setLocationFromPaths(m, List.of(notExist)));

        Path file = Files.createFile(base.resolve("file.txt"));
        checkException("not exist",
                IOException.class, file + ": not a directory",
                () -> fm.setLocationFromPaths(m, List.of(file)));
    }
}
 
Example 16
Source File: SetLocationForModule.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testOutput(Path base) throws IOException {
    try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
        Location locn = StandardLocation.CLASS_OUTPUT;

        Path out1 = Files.createDirectories(base.resolve("out1"));
        fm.setLocationFromPaths(locn, List.of(out1));

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

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

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

        Path out2 = Files.createDirectories(base.resolve("out2"));
        fm.setLocationFromPaths(locn, List.of(out2));

        checkEqual("updated setting",
                fm.getLocationAsPaths(m), out2.resolve("m"));
    }
}
 
Example 17
Source File: ModuleLocation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isOutputLocation() {
    return base == StandardLocation.CLASS_OUTPUT;
}
 
Example 18
Source File: TreeLoaderOutputFileManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasLocation(Location location) {
    return location == StandardLocation.CLASS_OUTPUT && outputRoot != null;
}
 
Example 19
Source File: ProxyFileManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@NonNull
private <T extends javax.tools.FileObject> T mark(
        @NonNull final T result,
        @NonNull JavaFileManager.Location l) throws MalformedURLException {
    if (ModuleLocation.isInstance(l)) {
        l = ModuleLocation.cast(l).getBaseLocation();
    }
    boolean valid = true;
    ProcessorGenerated.Type type = null;
    if (l == StandardLocation.CLASS_OUTPUT) {
        type = ProcessorGenerated.Type.RESOURCE;
    } else if (l == StandardLocation.SOURCE_OUTPUT) {
        type = ProcessorGenerated.Type.SOURCE;
    }
    if (cfg.getSiblings().getProvider().hasSibling() &&
        cfg.getSiblings().getProvider().isInSourceRoot()) {
        if (type == ProcessorGenerated.Type.SOURCE) {
            cfg.getProcessorGeneratedFiles().register(
                cfg.getSiblings().getProvider().getSibling(),
                result,
                type);
        } else if (type == ProcessorGenerated.Type.RESOURCE) {
            try {
                result.openInputStream().close();
            } catch (IOException ioe) {
                //Marking only created files
                cfg.getProcessorGeneratedFiles().register(
                    cfg.getSiblings().getProvider().getSibling(),
                    result,
                    type);
            }
        }
        if (!FileObjects.isValidFileName(result)) {
            LOG.log(
                Level.WARNING,
                "Cannot write Annotation Processor generated file: {0} ({1})",   //NOI18N
                new Object[] {
                    result.getName(),
                    result.toUri()
                });
            valid = false;
        }
    }
    return valid && (cfg.getProcessorGeneratedFiles().canWrite() || !cfg.getSiblings().getProvider().hasSibling()) ?
            result :
            (T) FileObjects.nullWriteFileObject((InferableJavaFileObject)result);    //safe - NullFileObject subclass of both JFO and FO.
}
 
Example 20
Source File: JavaSourceUtilImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasLocation(Location location) {
    return location == StandardLocation.CLASS_OUTPUT;
}