本文整理汇总了Java中javax.tools.JavaFileManager.Location方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileManager.Location方法的具体用法?Java JavaFileManager.Location怎么用?Java JavaFileManager.Location使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.JavaFileManager
的用法示例。
在下文中一共展示了JavaFileManager.Location方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUri
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
/**
* Creates a URI for a class file using a location, a package name, and a relative class name.
*
* @param location
* the location of the file relative to {@code BASE_LOCATION}, not null
* @param packageName
* the package name of the class, not null
* @param relativeName
* the name of the class, relative to the package name, not null
*
* @return the URI, not null
*
* @throws IllegalArgumentException
* if {@code location} is null
* @throws IllegalArgumentException
* if {@code packageName} is null
* @throws IllegalArgumentException
* if {@code relativeName} is null
*/
private static URI createUri(
final JavaFileManager.Location location,
final String packageName,
final String relativeName) {
checkNotNull(location, "Argument \'location\' cannot be null.");
checkNotNull(packageName, "Argument \'packageName\' cannot be null.");
checkNotNull(relativeName, "Argument \'relativeName\' cannot be null.");
final StringBuilder uri = new StringBuilder();
uri.append(BASE_LOCATION);
uri.append(location.getName());
uri.append("/");
if (!packageName.isEmpty()) {
uri.append(packageName.replace('.', '/'));
uri.append("/");
}
uri.append(relativeName);
return URI.create(uri.toString());
}
示例2: buildUri
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
/**
* Builds url for a given location, class or internal name
*
* @param location java file manager location
* @param name name
* @return URI
*/
public static URI buildUri(JavaFileManager.Location location, String name) {
String extension = "";
String template = location.getName().toLowerCase().replace("_", "") + ":///%s%s";
if (location == StandardLocation.CLASS_OUTPUT) {
extension = JavaFileObject.Kind.CLASS.extension;
template = CLASS_CODE_URI_TEMPLATE;
} else if (location == StandardLocation.SOURCE_OUTPUT) {
extension = JavaFileObject.Kind.SOURCE.extension;
template = SOURCE_CODE_URI_TEMPLATE;
}
int dotLastPosition = name.lastIndexOf('.');
if (dotLastPosition != -1) {
name = name.replace('.', '/');
}
return buildUri(String.format(template, name, extension));
}
示例3: doWithOriAndPrintWriter
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
public static void doWithOriAndPrintWriter(Filer filer, JavaFileManager.Location location, String relativePath, String filename, BiConsumer<String, PrintWriter> consumer){
try {
FileObject resource = filer.getResource(location, relativePath, filename);
String data;
try{
CharSequence cs = resource.getCharContent(false);
data = cs.toString();
resource.delete();
}catch (FileNotFoundException ignored){
data = "";
}
resource = filer.createResource(location, relativePath, filename);
try(OutputStream outputStream = resource.openOutputStream()){
consumer.accept(data,new PrintWriter(outputStream));
}
} catch (IOException e) {
note("do with resource file failed"+relativePath+filename+" Exception: " + e.toString());
}
}
示例4: listenForNewClassFile
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
private void listenForNewClassFile(OutputMemoryJavaFileObject jfo, JavaFileManager.Location location,
String className, JavaFileObject.Kind kind, FileObject sibling) {
//debug("listenForNewClassFile %s loc=%s kind=%s\n", className, location, kind);
if (location == CLASS_OUTPUT) {
state.debug(DBG_GEN, "Compiler generating class %s\n", className);
OuterWrap w = ((sibling instanceof SourceMemoryJavaFileObject)
&& (((SourceMemoryJavaFileObject) sibling).getOrigin() instanceof OuterWrap))
? (OuterWrap) ((SourceMemoryJavaFileObject) sibling).getOrigin()
: null;
classObjs.compute(w, (k, v) -> (v == null)? new ArrayList<>() : v)
.add(jfo);
}
}
示例5: test_setFiles_getPaths
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
void test_setFiles_getPaths(StandardJavaFileManager fm, List<File> inFiles) throws IOException {
System.err.println("test_setFiles_getPaths");
JavaFileManager.Location l = newLocation();
fm.setLocation(l, inFiles);
Iterable<? extends Path> outPaths = fm.getLocationAsPaths(l);
compare(inFiles, outPaths);
}
示例6: testList
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
public void testList() throws IOException {
//Source level 9, broken jar
ModuleFileManager fm = new ModuleFileManager(
CachingArchiveProvider.getDefault(),
bCp,
(u)->Collections.singleton(u),
Source.JDK1_9,
StandardLocation.MODULE_PATH,
false);
JavaFileManager.Location l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
.flatMap((s)->s.stream())
.findFirst()
.orElse(null);
assertNotNull(l);
Iterable<JavaFileObject> res = fm.list(l, "org.me", EnumSet.of(JavaFileObject.Kind.CLASS), false); //NOI18N
assertEquals(Arrays.asList("A Base","B Base"), toContent(res)); //NOI18N
assertEquals(Arrays.asList("org.me.A","org.me.B"), toInferedName(fm, res)); //NOI18N
//Source level 9, multi release jar
fm = new ModuleFileManager(
CachingArchiveProvider.getDefault(),
mvCp,
(u)->Collections.singleton(u),
Source.JDK1_9,
StandardLocation.MODULE_PATH,
false);
l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
.flatMap((s)->s.stream())
.findFirst()
.orElse(null);
assertNotNull(l);
res = fm.list(l, "org.me", EnumSet.of(JavaFileObject.Kind.CLASS), false); //NOI18N
assertEquals(Arrays.asList("A 9","B Base"), toContent(res)); //NOI18N
assertEquals(Arrays.asList("org.me.A","org.me.B"), toInferedName(fm, res)); //NOI18N
}
示例7: test_setPaths_getPaths
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
void test_setPaths_getPaths(StandardJavaFileManager fm, List<Path> inPaths) throws IOException {
System.err.println("test_setPaths_getPaths");
JavaFileManager.Location l = newLocation();
fm.setLocationFromPaths(l, inPaths);
Iterable<? extends Path> outPaths = fm.getLocationAsPaths(l);
compare(inPaths, outPaths);
}
示例8: test_setPaths_getFiles
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
void test_setPaths_getFiles(StandardJavaFileManager fm, List<Path> inPaths) throws IOException {
System.err.println("test_setPaths_getFiles");
JavaFileManager.Location l = newLocation();
fm.setLocationFromPaths(l, inPaths);
Iterable<? extends File> outFiles = fm.getLocation(l);
compare(inPaths, outFiles);
}
示例9: createResource
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
@Override
public FileObject createResource(
JavaFileManager.Location location,
CharSequence pkg,
CharSequence relativeName,
Element... entryElements)
throws IOException {
Set<InputType> inputTypes = getInputTypes(entryElements);
stateGraph.addGeneratedFile(
new GeneratedResourceFile(location, pkg, relativeName),
inputTypes.toArray(new InputType[0]));
return filer.createResource(location, pkg, relativeName, entryElements);
}
示例10: testCreateResourceFile
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
@Test
public void testCreateResourceFile() throws IOException {
JavaFileManager.Location location = createMock(JavaFileManager.Location.class);
CharSequence pkgName = "org.gradle.incap";
CharSequence relativeName = "resourceFile";
Element element = createMock(Element.class);
InputType inputType = new InputType("className");
JavaFileObject createdSourceFile = createMock(JavaFileObject.class);
// GIVEN
expect(inputTypeFinderMock.findInputTypeForElement(element)).andReturn(inputType).times(1);
stateGraphMock.addGeneratedFile(
eq(new GeneratedResourceFile(location, pkgName, relativeName)), eq(inputType));
expectLastCall().times(1);
expect(filerMock.createResource(location, pkgName, relativeName, element))
.andReturn(createdSourceFile)
.times(1);
incrementalFilerUnderTest =
new IncrementalFiler(filerMock, mappingFileWriterMock, stateGraphMock, inputTypeFinderMock);
replay(inputTypeFinderMock, stateGraphMock, filerMock);
// WHEN
FileObject expectedFile =
incrementalFilerUnderTest.createResource(location, pkgName, relativeName, element);
// THEN
assertEquals(expectedFile, createdSourceFile);
verify(inputTypeFinderMock, stateGraphMock, filerMock);
}
示例11: getJavaFileForOutput
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
@Override
public JavaFileObject getJavaFileForOutput(final JavaFileManager.Location location,
final String className, final JavaFileObject.Kind kind, final FileObject sibling) {
return new OutputStreamSimpleFileObject(new File(className).toURI(), kind, outputStream);
}
示例12: mark
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
@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.
}
示例13: ClasspathInfo
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
/** Creates a new instance of ClasspathInfo (private use the factory methods) */
private ClasspathInfo(final @NonNull ClassPath bootCp,
final @NonNull ClassPath moduleBootP,
final @NonNull ClassPath compileCp,
final @NonNull ClassPath moduleCompileP,
final @NonNull ClassPath moduleClassP,
final @NullAllowed ClassPath srcCp,
final @NullAllowed ClassPath moduleSrcCp,
final @NullAllowed JavaFileFilterImplementation filter,
final boolean backgroundCompilation,
final boolean ignoreExcludes,
final boolean hasMemoryFileManager,
final boolean useModifiedFiles,
final boolean requiresSourceRoots,
@NullAllowed final Function<JavaFileManager.Location, JavaFileManager> jfmProvider) {
assert bootCp != null;
assert compileCp != null;
this.cpListener = new ClassPathListener ();
this.bootClassPath = bootCp;
this.moduleBootPath = moduleBootP;
this.compileClassPath = compileCp;
this.moduleCompilePath = moduleCompileP;
this.moduleClassPath = moduleClassP;
this.listenerList = new ChangeSupport(this);
this.cachedBootClassPath = CacheClassPath.forBootPath(this.bootClassPath,backgroundCompilation);
this.cachedCompileClassPath = CacheClassPath.forClassPath(this.compileClassPath,backgroundCompilation);
this.cachedModuleCompilePath = CacheClassPath.forClassPath(this.moduleCompilePath,backgroundCompilation);
this.cachedModuleClassPath = CacheClassPath.forClassPath(this.moduleClassPath,backgroundCompilation);
if (!backgroundCompilation) {
this.cachedBootClassPath.addPropertyChangeListener(WeakListeners.propertyChange(this.cpListener,this.cachedBootClassPath));
this.cachedCompileClassPath.addPropertyChangeListener(WeakListeners.propertyChange(this.cpListener,this.cachedCompileClassPath));
}
if (srcCp == null || srcCp == ClassPath.EMPTY) {
this.cachedSrcClassPath = this.srcClassPath = this.outputClassPath = this.cachedAptSrcClassPath = ClassPath.EMPTY;
} else {
this.srcClassPath = srcCp;
final ClassPathImplementation noApt = AptSourcePath.sources(srcCp);
this.cachedSrcClassPath = ClassPathFactory.createClassPath(SourcePath.filtered(noApt, backgroundCompilation));
this.cachedAptSrcClassPath = ClassPathFactory.createClassPath(
SourcePath.filtered(AptSourcePath.aptCache(srcCp), backgroundCompilation));
this.outputClassPath = CacheClassPath.forSourcePath (ClassPathFactory.createClassPath(noApt),backgroundCompilation);
if (!backgroundCompilation) {
this.cachedSrcClassPath.addPropertyChangeListener(WeakListeners.propertyChange(this.cpListener,this.cachedSrcClassPath));
}
}
if (requiresSourceRoots && this.cachedSrcClassPath.entries().isEmpty()) {
throw new OutputFileManager.InvalidSourcePath();
}
if (moduleSrcCp == null) {
this.moduleSrcPath = ClassPath.EMPTY;
} else {
this.moduleSrcPath = moduleSrcCp;
}
this.ignoreExcludes = ignoreExcludes;
this.useModifiedFiles = useModifiedFiles;
this.filter = filter;
if (hasMemoryFileManager) {
if (srcCp == null) {
throw new IllegalStateException ();
}
this.memoryFileManager = new MemoryFileManager();
} else {
this.memoryFileManager = null;
}
if (backgroundCompilation) {
final TransactionContext txCtx = TransactionContext.get();
fmTx = txCtx.get(FileManagerTransaction.class);
pgTx = txCtx.get(ProcessorGenerated.class);
} else {
//No real transaction, read-only mode.
fmTx = FileManagerTransaction.treeLoaderOnly();
pgTx = ProcessorGenerated.nullWrite();
}
this.peerProviders = new IdentityHashMap<>();
this.peerProviders.put(cachedModuleCompilePath, new Peers(this.moduleCompilePath));
assert fmTx != null : "No file manager transaction."; //NOI18N
assert pgTx != null : "No processor generated transaction."; //NOI18N
this.jfmProvider = jfmProvider;
}
示例14: newClassFile
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
void newClassFile(OutputMemoryJavaFileObject jfo, JavaFileManager.Location location,
String className, Kind kind, FileObject sibling);
示例15: getClassLoader
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
@Override
public ClassLoader getClassLoader(JavaFileManager.Location location) {
return classLoader;
}