當前位置: 首頁>>代碼示例>>Java>>正文


Java JavaFileManager.Location方法代碼示例

本文整理匯總了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());
}
 
開發者ID:MatthewTamlin,項目名稱:Avatar,代碼行數:44,代碼來源:InMemoryJavaFileManager.java

示例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));
}
 
開發者ID:twosigma,項目名稱:beaker-notebook-archive,代碼行數:24,代碼來源:URIUtil.java

示例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());
    }
}
 
開發者ID:frankelau,項目名稱:pndao,代碼行數:21,代碼來源:ResourceHelper.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:TaskFactory.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:SJFM_Locations.java

示例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
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:MRJARModuleFileManagerTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:SJFM_Locations.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:SJFM_Locations.java

示例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);
}
 
開發者ID:gradle,項目名稱:incap,代碼行數:16,代碼來源:IncrementalFiler.java

示例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);
}
 
開發者ID:gradle,項目名稱:incap,代碼行數:34,代碼來源:IncrementalFilerTest.java

示例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);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:6,代碼來源:ClassBuilder.java

示例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.
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:49,代碼來源:ProxyFileManager.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:80,代碼來源:ClasspathInfo.java

示例14: newClassFile

import javax.tools.JavaFileManager; //導入方法依賴的package包/類
void newClassFile(OutputMemoryJavaFileObject jfo, JavaFileManager.Location location,
String className, Kind kind, FileObject sibling);
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:3,代碼來源:MemoryFileManager.java

示例15: getClassLoader

import javax.tools.JavaFileManager; //導入方法依賴的package包/類
@Override
public ClassLoader getClassLoader(JavaFileManager.Location location) {
    return classLoader;
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:5,代碼來源:JdkCompiler.java


注:本文中的javax.tools.JavaFileManager.Location方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。