Java 类javax.tools.JavaFileManager 实例源码
项目:Avatar
文件:InMemoryJavaFileManager.java
/**
* Creates a URI for a class file using a location, a class name, and a kind.
*
* @param location
* the location of the file relative to {@code BASE_LOCATION}, not null
* @param className
* the name of the class, not null
* @param kind
* the kind of the class, not null
*
* @return the URI, not null
*
* @throws IllegalArgumentException
* if {@code location} is null
* @throws IllegalArgumentException
* if {@code className} is null
* @throws IllegalArgumentException
* if {@code kind} is null
*/
private static URI createUri(
final JavaFileManager.Location location,
final String className,
final JavaFileObject.Kind kind) {
checkNotNull(location, "Argument \'location\' cannot be null.");
checkNotNull(className, "Argument \'className\' cannot be null.");
checkNotNull(kind, "Argument \'kind\' cannot be null.");
final StringBuilder uri = new StringBuilder();
uri.append(BASE_LOCATION);
uri.append(location.getName());
uri.append("/");
uri.append(className.replace(".", "/"));
uri.append(kind.extension);
return URI.create(uri.toString());
}
项目:manifold
文件:JavacPlugin.java
private String deriveClassOutputPath()
{
try
{
String ping = "__dummy__";
//JavaFileObject classFile = _jpe.getFiler().createClassFile( ping );
JavaFileObject classFile = _javacTask.getContext().get( JavaFileManager.class ).getJavaFileForOutput( StandardLocation.CLASS_OUTPUT, ping, JavaFileObject.Kind.CLASS, null );
if( !isPhysicalFile( classFile ) )
{
return "";
}
File dummyFile = new File( classFile.toUri() );
String path = dummyFile.getAbsolutePath();
path = path.substring( 0, path.length() - (File.separatorChar + ping + ".class").length() );
return path;
}
catch( IOException e )
{
throw new RuntimeException( e );
}
}
项目:incubator-netbeans
文件:SourceAnalyzerFactory.java
protected UsagesVisitor (
JavacTaskImpl jt,
CompilationUnitTree cu,
JavaFileManager manager,
javax.tools.JavaFileObject sibling,
Set<? super Pair<String,String>> topLevels) throws MalformedURLException, IllegalArgumentException {
this(
jt,
cu,
inferBinaryName(manager, sibling),
sibling.toUri().toURL(),
false,
false,
null,
null,
topLevels);
}
项目:openjdk-jdk10
文件:JavapTaskCtorFailWithNPE.java
private void run() {
File classToCheck = new File(System.getProperty("test.classes"),
getClass().getSimpleName() + ".class");
DiagnosticCollector<JavaFileObject> dc =
new DiagnosticCollector<JavaFileObject>();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavaFileManager fm = JavapFileManager.create(dc, pw);
JavapTask t = new JavapTask(pw, fm, dc, null,
Arrays.asList(classToCheck.getPath()));
if (t.run() != 0)
throw new Error("javap failed unexpectedly");
List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
for (Diagnostic<? extends JavaFileObject> d: diags) {
if (d.getKind() == Diagnostic.Kind.ERROR)
throw new AssertionError(d.getMessage(Locale.ENGLISH));
}
String lineSep = System.getProperty("line.separator");
String out = sw.toString().replace(lineSep, "\n");
if (!out.equals(expOutput)) {
throw new AssertionError("The output is not equal to the one expected");
}
}
项目:openjdk-jdk10
文件:ToolEnvironment.java
/**
* Constructor
*
* @param context Context for this javadoc instance.
*/
protected ToolEnvironment(Context context) {
context.put(ToolEnvKey, this);
this.context = context;
messager = Messager.instance0(context);
syms = Symtab.instance(context);
finder = JavadocClassFinder.instance(context);
enter = JavadocEnter.instance(context);
names = Names.instance(context);
externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
chk = Check.instance(context);
types = com.sun.tools.javac.code.Types.instance(context);
fileManager = context.get(JavaFileManager.class);
if (fileManager instanceof JavacFileManager) {
((JavacFileManager)fileManager).setSymbolFileEnabled(false);
}
docTrees = JavacTrees.instance(context);
source = Source.instance(context);
elements = JavacElements.instance(context);
typeutils = JavacTypes.instance(context);
elementToTreePath = new HashMap<>();
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@Override
@CheckForNull
public FileObject getFileForInput(
@NonNull final Location l,
@NonNull final String packageName,
@NonNull final String relativeName) throws IOException {
checkSingleOwnerThread();
try {
JavaFileManager[] fms = cfg.getFileManagers(l, null);
for (JavaFileManager fm : fms) {
FileObject result = fm.getFileForInput(l, packageName, relativeName);
if (result != null) {
return result;
}
}
return null;
} finally {
clearOwnerThread();
}
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@Override
@CheckForNull
public String inferModuleName(@NonNull final Location location) throws IOException {
checkSingleOwnerThread();
try {
for (JavaFileManager jfm : cfg.getFileManagers(location, null)) {
final String modName = jfm.inferModuleName(location);
if (modName != null) {
return modName;
}
}
return null;
} finally {
clearOwnerThread();
}
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@Override
@CheckForNull
public JavaFileObject getJavaFileForOutput(
@NonNull final Location l,
@NonNull final String className,
@NonNull final JavaFileObject.Kind kind,
@NonNull final FileObject sibling)
throws IOException, UnsupportedOperationException, IllegalArgumentException {
checkSingleOwnerThread();
try {
final JavaFileManager[] fms = cfg.getFileManagers (l, null);
if (fms.length == 0) {
throw new UnsupportedOperationException("No JavaFileManager for location: " + l); //NOI18N
} else {
return mark (
fms[0].getJavaFileForOutput (l, className, kind, sibling),
l);
}
} finally {
clearOwnerThread();
}
}
项目:openjdk-jdk10
文件:JavadocHelper.java
private Pair<JavacTask, CompilationUnitTree> findSource(String moduleName,
String binaryName) throws IOException {
JavaFileObject jfo = fm.getJavaFileForInput(StandardLocation.SOURCE_PATH,
binaryName,
JavaFileObject.Kind.SOURCE);
if (jfo == null)
return null;
List<JavaFileObject> jfos = Arrays.asList(jfo);
JavaFileManager patchFM = moduleName != null
? new PatchModuleFileManager(baseFileManager, jfo, moduleName)
: baseFileManager;
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, patchFM, d -> {}, null, null, jfos);
Iterable<? extends CompilationUnitTree> cuts = task.parse();
task.enter();
return Pair.of(task, cuts.iterator().next());
}
项目:openjdk-jdk10
文件:DetectMutableStaticFields.java
void analyzeModule(StandardJavaFileManager fm, String moduleName)
throws
IOException,
ConstantPoolException,
InvalidDescriptor {
JavaFileManager.Location location =
fm.getLocationForModule(StandardLocation.SYSTEM_MODULES, moduleName);
if (location == null)
throw new AssertionError("can't find module " + moduleName);
for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
String className = fm.inferBinaryName(location, file);
int index = className.lastIndexOf('.');
String pckName = index == -1 ? "" : className.substring(0, index);
if (shouldAnalyzePackage(pckName)) {
analyzeClassFile(ClassFile.read(file.openInputStream()));
}
}
}
项目:openjdk-jdk10
文件:T8068517.java
void runTest(String aJava, String bJava) throws Exception {
try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
ToolBox tb = new ToolBox();
ToolBox.MemoryFileManager memoryFM1 = new ToolBox.MemoryFileManager(fm);
new JavacTask(tb).fileManager(memoryFM1)
.sources(aJava, bJava)
.run();
ToolBox.MemoryFileManager memoryFM2 = new ToolBox.MemoryFileManager(fm);
new JavacTask(tb).fileManager(memoryFM2)
.sources(bJava, aJava)
.run();
Assert.check(Arrays.equals(memoryFM1.getFileBytes(StandardLocation.CLASS_OUTPUT, "B"),
memoryFM2.getFileBytes(StandardLocation.CLASS_OUTPUT, "B")));
}
}
项目:manifold
文件:JavacPlugin.java
private void hijackJavacFileManager()
{
if( !(_fileManager instanceof ManifoldJavaFileManager) && _manFileManager == null )
{
_ctx = _javacTask.getContext();
_fileManager = _ctx.get( JavaFileManager.class );
_javaInputFiles = new HashSet<>();
_gosuInputFiles = fetchGosuInputFiles();
_treeMaker = TreeMaker.instance( _ctx );
_javacElements = JavacElements.instance( _ctx );
_typeProcessor = new TypeProcessor( _javacTask );
_issueReporter = new IssueReporter( Log.instance( getContext() ) );
_seenModules = new LinkedHashSet<>();
injectManFileManager();
}
}
项目:OpenJSharp
文件:JavahTask.java
JavahTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes) {
this();
this.log = getPrintWriterForWriter(out);
this.fileManager = fileManager;
this.diagnosticListener = diagnosticListener;
try {
handleOptions(options, false);
} catch (BadArgs e) {
throw new IllegalArgumentException(e.getMessage());
}
this.classes = new ArrayList<String>();
if (classes != null) {
for (String classname: classes) {
classname.getClass(); // null-check
this.classes.add(classname);
}
}
}
项目:openjdk-jdk10
文件:DocEnv.java
/**
* Constructor
*
* @param context Context for this javadoc instance.
*/
protected DocEnv(Context context) {
context.put(docEnvKey, this);
this.context = context;
messager = Messager.instance0(context);
syms = Symtab.instance(context);
finder = JavadocClassFinder.instance(context);
enter = JavadocEnter.instance(context);
names = Names.instance(context);
externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
chk = Check.instance(context);
types = Types.instance(context);
fileManager = context.get(JavaFileManager.class);
if (fileManager instanceof JavacFileManager) {
((JavacFileManager)fileManager).setSymbolFileEnabled(false);
}
// Default. Should normally be reset with setLocale.
this.doclocale = new DocLocale(this, "", breakiterator);
source = Source.instance(context);
}
项目:incubator-netbeans
文件:ClasspathInfoTest.java
public void testGetPackageDeclaration() throws Exception {
ClasspathInfo ci = ClasspathInfo.create( bootPath, classPath, null);
JavaFileManager fm = ClasspathInfoAccessor.getINSTANCE().createFileManager(ci, null);
JarFile jf = new JarFile( rtJar );
for( Enumeration entries = jf.entries(); entries.hasMoreElements(); ) {
JarEntry je = (JarEntry)entries.nextElement();
String jeName = je.getName();
if ( je.isDirectory() ) {
String packageName = jeName.replace( "/", "." );
if ( !fm.list( StandardLocation.PLATFORM_CLASS_PATH,packageName, EnumSet.of( JavaFileObject.Kind.CLASS ), false).iterator().hasNext() ) {
// empty package
continue;
}
PackageElement pd = JavacParser.createJavacTask(ci, (DiagnosticListener) null, (String) null, null, null, null, null, null, Collections.emptyList()).getElements().getPackageElement( packageName );
assertNotNull( "Declaration for " + packageName + " should not be null.", pd );
}
}
}
项目:incubator-netbeans
文件:MultiPassCompileWorker.java
private void dumpSymFile(
@NonNull final JavaFileManager jfm,
@NonNull final JavacTaskImpl jti,
@NullAllowed final ClassSymbol cs,
@NonNull final Set<File> alreadyCreated,
@NonNull final File classes,
@NonNull final HashMap<ClassSymbol, JCClassDecl> syms2trees) throws IOException {
if (cs == null) {
//ClassDecl has no symbol because compilation was cancelled
//by low memory before ENTER done.
return;
}
JavaFileObject file = jfm.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT,
cs.flatname.toString(), JavaFileObject.Kind.CLASS, cs.sourcefile);
if (file instanceof FileObjects.FileBase && !alreadyCreated.contains(((FileObjects.FileBase)file).getFile())) {
TreeLoader.dumpSymFile(jfm, jti, cs, classes, syms2trees);
}
}
项目:incubator-netbeans
文件:SwitchingJavaFileManger.java
protected JavaFileManager delegate() {
JavaFileManager d = localDelegate.get();
if (d != null) {
return d;
}
d = this.delegate;
if (d != null) {
return d;
}
synchronized (this) {
if (delegate == null) {
this.delegate = ClasspathInfoAccessor.getINSTANCE().createFileManager(cpInfo, "9");
}
return delegate;
}
}
项目:javaide
文件:Enter.java
protected Enter(Context context) {
context.put(enterKey, this);
log = Log.instance(context);
reader = ClassReader.instance(context);
make = TreeMaker.instance(context);
syms = Symtab.instance(context);
chk = Check.instance(context);
memberEnter = MemberEnter.instance(context);
types = Types.instance(context);
annotate = Annotate.instance(context);
lint = Lint.instance(context);
names = Names.instance(context);
predefClassDef = make.ClassDef(
make.Modifiers(PUBLIC),
syms.predefClass.name, null, null, null, null);
predefClassDef.sym = syms.predefClass;
todo = Todo.instance(context);
fileManager = context.get(JavaFileManager.class);
Options options = Options.instance(context);
pkginfoOpt = PkgInfo.get(options);
}
项目:openjdk-jdk10
文件:JavacTrees.java
private void init(Context context) {
modules = Modules.instance(context);
attr = Attr.instance(context);
enter = Enter.instance(context);
elements = JavacElements.instance(context);
log = Log.instance(context);
resolve = Resolve.instance(context);
treeMaker = TreeMaker.instance(context);
memberEnter = MemberEnter.instance(context);
names = Names.instance(context);
types = Types.instance(context);
docTreeMaker = DocTreeMaker.instance(context);
parser = ParserFactory.instance(context);
syms = Symtab.instance(context);
fileManager = context.get(JavaFileManager.class);
JavacTask t = context.get(JavacTask.class);
if (t instanceof JavacTaskImpl)
javacTaskImpl = (JavacTaskImpl) t;
}
项目:GitHub
文件:FileSystemRegistry.java
@Nullable
public JavaFileManager getFileSystem(URL url) {
String prefix = url.getProtocol() + "://" + url.getHost() + "/";
if(prefix2jfm.containsKey(prefix)) {
return prefix2jfm.get(prefix).get();
} else {
return null;
}
}
项目:GitHub
文件:FileSystemRegistry.java
public String getUrlPrefix(JavaFileManager jfm) {
if(jfm2prefix.containsKey(jfm)) {
return jfm2prefix.get(jfm);
} else {
String result = protocolName + "://jfm" + (sequence++) + "/";
jfm2prefix.put(jfm,result);
prefix2jfm.put(result, new WeakReference<JavaFileManager>(jfm));
return result;
}
}
项目:jsf-sdk
文件:TemplatePrecompiler.java
@SuppressWarnings("serial")
private static void matchClassNames(List<String> ret, final String className)
throws IOException {
String packageName = className.substring(0, className.lastIndexOf('.'));
String relativedName = className.substring(
className.lastIndexOf('.') + 1, className.length());
String patName = relativedName.replace("*", "(\\w+)");
Pattern pat = Pattern.compile(patName);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
JavaFileManager fm = compiler.getStandardFileManager(
new DiagnosticCollector<JavaFileObject>(), null, null);
HashSet<JavaFileObject.Kind> kind = new HashSet<JavaFileObject.Kind>() {
{
add(JavaFileObject.Kind.CLASS);
}
};
for (JavaFileObject f : fm.list(StandardLocation.PLATFORM_CLASS_PATH, packageName, kind, false)) {
String relatived0 = f.getName();
String name0 = relatived0.substring(0, relatived0.length() - ".class".length());
Matcher m = pat.matcher(name0);
if (m.matches()) {
String name = packageName + '.' + name0;
if (!ret.contains(name)) {
ret.add(name);
}
}
}
}
项目:OpenJSharp
文件:JavacPathFileManager.java
/**
* Create a JavacPathFileManager using a given context, optionally registering
* it as the JavaFileManager for that context.
*/
public JavacPathFileManager(Context context, boolean register, Charset charset) {
super(charset);
if (register)
context.put(JavaFileManager.class, this);
pathsForLocation = new HashMap<Location, PathsForLocation>();
fileSystems = new HashMap<Path,FileSystem>();
setContext(context);
}
项目:openjdk-jdk10
文件:DocFileFactory.java
/**
* Get the appropriate factory, based on the file manager given in the
* configuration.
*
* @param configuration the configuration for this doclet
* @return the factory associated with this configuration
*/
public static synchronized DocFileFactory getFactory(BaseConfiguration configuration) {
DocFileFactory f = configuration.docFileFactory;
if (f == null) {
JavaFileManager fm = configuration.getFileManager();
if (fm instanceof StandardJavaFileManager) {
f = new StandardDocFileFactory(configuration);
} else {
throw new IllegalStateException();
}
configuration.docFileFactory = f;
}
return f;
}
项目:openjdk-jdk10
文件:ClassWriter.java
/** Construct a class writer, given an options table.
*/
protected ClassWriter(Context context) {
context.put(classWriterKey, this);
log = Log.instance(context);
names = Names.instance(context);
options = Options.instance(context);
target = Target.instance(context);
source = Source.instance(context);
types = Types.instance(context);
fileManager = context.get(JavaFileManager.class);
signatureGen = new CWSignatureGenerator(types);
verbose = options.isSet(VERBOSE);
genCrt = options.isSet(XJCOV);
debugstackmap = options.isSet("debug.stackmap");
emitSourceFile = options.isUnset(G_CUSTOM) ||
options.isSet(G_CUSTOM, "source");
String modifierFlags = options.get("debug.dumpmodifiers");
if (modifierFlags != null) {
dumpClassModifiers = modifierFlags.indexOf('c') != -1;
dumpFieldModifiers = modifierFlags.indexOf('f') != -1;
dumpInnerClassModifiers = modifierFlags.indexOf('i') != -1;
dumpMethodModifiers = modifierFlags.indexOf('m') != -1;
}
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@Override
public void close() throws IOException {
checkSingleOwnerThread();
try {
for (JavaFileManager fm : cfg.getFileManagers(ALL, null)) {
fm.close();
}
} finally {
clearOwnerThread();
}
}
项目:openjdk-jdk10
文件:Enter.java
protected Enter(Context context) {
context.put(enterKey, this);
log = Log.instance(context);
make = TreeMaker.instance(context);
syms = Symtab.instance(context);
chk = Check.instance(context);
typeEnter = TypeEnter.instance(context);
types = Types.instance(context);
annotate = Annotate.instance(context);
lint = Lint.instance(context);
names = Names.instance(context);
modules = Modules.instance(context);
diags = JCDiagnostic.Factory.instance(context);
predefClassDef = make.ClassDef(
make.Modifiers(PUBLIC),
syms.predefClass.name,
List.nil(),
null,
List.nil(),
List.nil());
predefClassDef.sym = syms.predefClass;
todo = Todo.instance(context);
fileManager = context.get(JavaFileManager.class);
Options options = Options.instance(context);
pkginfoOpt = PkgInfo.get(options);
typeEnvs = TypeEnvs.instance(context);
}
项目:openjdk-jdk10
文件:SJFM_Locations.java
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);
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@Override
public boolean isSameFile(FileObject fileObject, FileObject fileObject0) {
checkSingleOwnerThread();
try {
final JavaFileManager[] fms = cfg.getFileManagers(ALL, null);
for (JavaFileManager fm : fms) {
if (fm.isSameFile(fileObject, fileObject0)) {
return true;
}
}
return fileObject.toUri().equals (fileObject0.toUri());
} finally {
clearOwnerThread();
}
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@NonNull
JavaFileManager[] getFileManagers(@NonNull Location location, @NullAllowed String hint) {
if (ModuleLocation.isInstance(location)) {
location = ModuleLocation.cast(location).getBaseLocation();
}
if (location == ALL) {
//Todo: create factories with options when there are more than one option.
if (TreeLoaderOutputFileManager.OUTPUT_ROOT.equals(hint)) {
createTreeLoaderFileManager();
}
if (JavacParser.OPTION_PATCH_MODULE.equals(hint)) {
createPatchFileManager();
createModuleSrcFileManager();
}
final List<JavaFileManager> res = new ArrayList<>(emitted.length);
for (JavaFileManager jfm : emitted) {
if (jfm != null) {
res.add(jfm);
}
}
return res.toArray(new JavaFileManager[res.size()]);
} else {
final Entry result = fileManagers.get(location);
return result == null ?
EMPTY :
result.get();
}
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@NonNull
private JavaFileManager createCompileFileManager() {
if (emitted[COMPILE] == null) {
emitted[COMPILE] = new CachingFileManager (cap, compiledCached, sourceLevel, false, true);
}
return emitted[COMPILE];
}
项目:openjdk-jdk10
文件:PathsTest.java
File createJar() throws IOException {
File f = new File("test.jar");
try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler()
.getStandardFileManager(null, null, null)) {
ToolBox tb = new ToolBox();
new JarTask(tb, f.getPath())
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*")
.run();
}
return f;
}
项目:openjdk-jdk10
文件:ClassReader.java
/** Construct a new class reader. */
protected ClassReader(Context context) {
context.put(classReaderKey, this);
annotate = Annotate.instance(context);
names = Names.instance(context);
syms = Symtab.instance(context);
types = Types.instance(context);
fileManager = context.get(JavaFileManager.class);
if (fileManager == null)
throw new AssertionError("FileManager initialization error");
diagFactory = JCDiagnostic.Factory.instance(context);
log = Log.instance(context);
Options options = Options.instance(context);
verbose = options.isSet(Option.VERBOSE);
Source source = Source.instance(context);
allowSimplifiedVarargs = source.allowSimplifiedVarargs();
allowModules = source.allowModules();
saveParameterNames = options.isSet(PARAMETERS);
profile = Profile.instance(context);
typevars = WriteableScope.create(syms.noSymbol);
lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);
initAttributeReaders();
}
项目:incubator-netbeans
文件:ProxyFileManager.java
@NonNull
private JavaFileManager createModuleFileManager() {
if (emitted[USER_MODULES] == null) {
emitted[USER_MODULES] = new ModuleFileManager(
cap,
moduleCompile,
peersMap.getOrDefault(moduleCompile, ROOT_TO_COLLECTION),
sourceLevel,
StandardLocation.MODULE_PATH,
false);
}
return emitted[USER_MODULES];
}
项目:incubator-netbeans
文件:ProxyFileManager.java
private Entry(
@NonNull final Supplier<JavaFileManager[]> factory,
@NullAllowed final Function<JavaFileManager[],JavaFileManager[]> filter) {
assert factory != null;
this.factory = factory;
this.filter = filter;
}
项目:OpenJSharp
文件:JavadocTool.java
@Override
public DocumentationTask getTask(
Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Class<?> docletClass,
Iterable<String> options,
Iterable<? extends JavaFileObject> compilationUnits) {
Context context = new Context();
return getTask(out, fileManager, diagnosticListener,
docletClass, options, compilationUnits, context);
}
项目:incubator-netbeans
文件:ClasspathInfo.java
@NonNull
private static ClasspathInfo create(
@NonNull final ClassPath bootPath,
@NonNull final ClassPath moduleBootPath,
@NonNull final ClassPath classPath,
@NonNull final ClassPath moduleCompilePath,
@NonNull final ClassPath moduleClassPath,
@NullAllowed final ClassPath sourcePath,
@NullAllowed final ClassPath moduleSourcePath,
@NullAllowed final JavaFileFilterImplementation filter,
final boolean backgroundCompilation,
final boolean ignoreExcludes,
final boolean hasMemoryFileManager,
final boolean useModifiedFiles,
final boolean requiresSourceRoots,
@NullAllowed final Function<JavaFileManager.Location, JavaFileManager> jfmProvider) {
return new ClasspathInfo(
bootPath,
moduleBootPath,
classPath,
moduleCompilePath,
moduleClassPath,
sourcePath,
moduleSourcePath,
filter,
backgroundCompilation,
ignoreExcludes,
hasMemoryFileManager,
useModifiedFiles,
requiresSourceRoots,
jfmProvider);
}
项目:incubator-netbeans
文件:ClasspathInfo.java
@Override
public ClasspathInfo create (
@NonNull final ClassPath bootPath,
@NonNull final ClassPath moduleBootPath,
@NonNull final ClassPath classPath,
@NonNull final ClassPath moduleCompilePath,
@NonNull final ClassPath moduleClassPath,
@NullAllowed final ClassPath sourcePath,
@NullAllowed final ClassPath moduleSourcePath,
@NullAllowed final JavaFileFilterImplementation filter,
final boolean backgroundCompilation,
final boolean ignoreExcludes,
final boolean hasMemoryFileManager,
final boolean useModifiedFiles,
final boolean requiresSourceRoots,
@NullAllowed final Function<JavaFileManager.Location, JavaFileManager> jfmProvider) {
return ClasspathInfo.create(
bootPath,
moduleBootPath,
classPath,
moduleCompilePath,
moduleClassPath,
sourcePath,
moduleSourcePath,
filter,
backgroundCompilation,
ignoreExcludes,
hasMemoryFileManager,
useModifiedFiles,
requiresSourceRoots,
jfmProvider);
}
项目:incubator-netbeans
文件:SourceUtils.java
/**
* Returns names of all modules within given scope.
* @param info the CompilationInfo used to resolve modules
* @param scope to search in {@see SearchScope}
* @return set of module names
* @since 2.23
*/
public static Set<String> getModuleNames(CompilationInfo info, final @NonNull Set<? extends ClassIndex.SearchScopeType> scope) {
Set<String> ret = new HashSet<>();
JavaFileManager jfm = info.impl.getJavacTask().getContext().get(JavaFileManager.class);
if (jfm != null) {
List<JavaFileManager.Location> toSearch = new ArrayList<>();
for (ClassIndex.SearchScopeType s : scope) {
if (s.isSources()) {
toSearch.add(StandardLocation.MODULE_SOURCE_PATH);
}
if (s.isDependencies()) {
toSearch.add(StandardLocation.MODULE_PATH);
toSearch.add(StandardLocation.UPGRADE_MODULE_PATH);
toSearch.add(StandardLocation.SYSTEM_MODULES);
}
}
try {
for (JavaFileManager.Location searchLocation : toSearch) {
for (Set<JavaFileManager.Location> locations : jfm.listLocationsForModules(searchLocation)) {
for (JavaFileManager.Location location : locations) {
ret.add(jfm.inferModuleName(location));
}
}
}
} catch (IOException ioe) {}
}
return ret;
}
项目:incubator-netbeans
文件:ModuleNamesTest.java
@NonNull
private static Supplier<byte[]> moduleInfoClz(
@NonNull final Supplier<Pair<Boolean,String>> moduleInfoJava) {
return () -> {
try {
final JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
final List<String> opts = new ArrayList<>();
opts.add("-source"); //NOI18N
opts.add("9"); //NOI18N
opts.add("-target"); //NOI18N
opts.add("9"); //NOI18N
final Pair<Boolean,String> p = moduleInfoJava.get();
final JavaFileObject moduleInfo = FileObjects.memoryFileObject(
"", //NOI18N
"module-info.java", //NOI18N
p.second());
final JavaFileManager fm = new MemFM(p.first());
final JavacTask task = (JavacTask) jc.getTask(null, fm, null, opts, null, Collections.singleton(moduleInfo));
final Iterator<? extends JavaFileObject> res = task.generate().iterator();
final JavaFileObject fo = res.hasNext() ?
res.next() :
null;
if (fo != null) {
try (InputStream in = fo.openInputStream()) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
FileUtil.copy(in, out);
out.close();
return out.toByteArray();
}
} else {
return null;
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
};
}