本文整理汇总了Java中org.netbeans.api.java.classpath.ClassPath.findOwnerRoot方法的典型用法代码示例。如果您正苦于以下问题:Java ClassPath.findOwnerRoot方法的具体用法?Java ClassPath.findOwnerRoot怎么用?Java ClassPath.findOwnerRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.classpath.ClassPath
的用法示例。
在下文中一共展示了ClassPath.findOwnerRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSource
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@CheckForNull
private static FileObject findSource(
@NonNull final FileObject file,
@NonNull final ElementHandle<?> elementHandle) {
FileObject owner = null;
for (String id : new String[] {
ClassPath.EXECUTE,
ClassPath.COMPILE,
ClassPath.BOOT}) {
final ClassPath cp = ClassPath.getClassPath(file, id);
if (cp != null) {
owner = cp.findOwnerRoot(file);
if (owner != null) {
break;
}
}
}
return owner == null ?
owner :
SourceUtils.getFile(
elementHandle,
ClasspathInfo.create(
ClassPathSupport.createClassPath(owner),
ClassPath.EMPTY,
ClassPath.EMPTY));
}
示例2: groupByRoot
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private Iterable<? extends List<FileObject>> groupByRoot (Iterable<? extends FileObject> data) {
Map<FileObject,List<FileObject>> result = new HashMap<FileObject,List<FileObject>> ();
for (FileObject file : data) {
if (isCanceled()) {
return Collections.emptyList();
}
ClassPath cp = ClassPath.getClassPath(file, ClassPath.SOURCE);
if (cp != null) {
FileObject root = cp.findOwnerRoot(file);
if (root != null) {
if (!includeTest && UnitTestForSourceQuery.findSources(root).length > 0) {
continue;
}
List<FileObject> subr = result.get (root);
if (subr == null) {
subr = new LinkedList<FileObject>();
result.put (root,subr);
}
subr.add(file);
}
}
}
return result.values();
}
示例3: binaryOpen
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static boolean binaryOpen(
@NonNull final FileObject toSearch,
@NonNull final ElementHandle<? extends Element> toOpen,
@NonNull final AtomicBoolean cancel) {
boolean res = false;
final BinaryElementOpen beo = Lookup.getDefault().lookup(BinaryElementOpen.class);
if (beo != null) {
ClassPath bootCp = ClassPath.getClassPath(toSearch, ClassPath.BOOT);
if (bootCp == null) {
bootCp = JavaPlatform.getDefault().getBootstrapLibraries();
}
ClassPath cp = ClassPath.getClassPath(toSearch, ClassPath.COMPILE);
if (cp == null || cp.findOwnerRoot(toSearch) == null) {
cp = ClassPath.getClassPath(toSearch, ClassPath.EXECUTE);
if (cp == null) {
cp = ClassPath.EMPTY;
}
}
final ClassPath src = ClassPath.getClassPath(toSearch, ClassPath.SOURCE);
res = beo.open(ClasspathInfo.create(bootCp, cp, src), toOpen, cancel);
}
return res;
}
示例4: checkDirection
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Checks whether this action should be enabled for "Go To Test"
* or for "Go To Tested Class" or whether it should be disabled.
*
* @return {@code Boolean.TRUE} if this action should be enabled for
* "Go To Test",<br />
* {@code Boolean.FALSE} if this action should be enabled for
* "Go To Tested Class",<br />
* {@code null} if this action should be disabled
*/
private Boolean checkDirection(FileObject fileObj) {
ClassPath srcCP;
FileObject fileObjRoot;
boolean isJavaFile = false;
boolean sourceToTest = true;
boolean enabled = (fileObj != null)
&& (fileObj.isFolder() || (isJavaFile = JUnitTestUtil.isJavaFile(fileObj)))
&& ((srcCP = ClassPath.getClassPath(fileObj, ClassPath.SOURCE)) != null)
&& ((fileObjRoot = srcCP.findOwnerRoot(fileObj)) != null)
&& ((UnitTestForSourceQuery.findUnitTests(fileObjRoot).length != 0)
|| (sourceToTest = false) //side effect - assignment
|| isJavaFile && (UnitTestForSourceQuery.findSources(fileObjRoot).length != 0));
return enabled ? Boolean.valueOf(sourceToTest)
: null;
}
示例5: classToSourceURL
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private String classToSourceURL (FileObject fo, OutputWriter logger) {
ClassPath cp = ClassPath.getClassPath (fo, ClassPath.EXECUTE);
if (cp == null) {
return null;
}
FileObject root = cp.findOwnerRoot (fo);
String resourceName = cp.getResourceName (fo, '/', false);
if (resourceName == null) {
logger.println("Can not find classpath resource for "+fo+", skipping...");
return null;
}
int i = resourceName.indexOf ('$');
if (i > 0) {
resourceName = resourceName.substring (0, i);
}
FileObject[] sRoots = SourceForBinaryQuery.findSourceRoots
(root.toURL ()).getRoots ();
ClassPath sourcePath = ClassPathSupport.createClassPath (sRoots);
FileObject rfo = sourcePath.findResource (resourceName + ".java");
if (rfo == null) {
return null;
}
return rfo.toURL ().toExternalForm ();
}
示例6: computePersistentFile
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private File computePersistentFile(FileObject file, String extension) throws IOException {
ClassPath cp = Utilities.getSourceClassPathFor(file);
if (cp == null)
return null;
FileObject root = cp.findOwnerRoot(file);
if (root == null) {
LOG.log(Level.FINE, "file={0} does not have a root on its own source classpath", file); //NOI18N
return null;
}
String resourceName = cp.getResourceName(file, File.separatorChar, true);
File cacheRoot = getCacheRoot(root.toURL());
File cacheFile = computePersistentFile(cacheRoot, resourceName, extension);
return cacheFile;
}
示例7: findAllResources
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@NonNull
private static List<Pair<FileObject, ClassPath>> findAllResources(
@NonNull final String resourceName,
@NonNull final Predicate<? super FileObject> rootsFilter,
@NonNull final ClassPath... cps) {
final List<Pair<FileObject,ClassPath>> result = new ArrayList<>();
for (ClassPath cp : cps) {
for (FileObject fo : cp.findAllResources(resourceName)) {
final FileObject root = cp.findOwnerRoot(fo);
if (root != null && rootsFilter.test(root)) {
result.add(Pair.<FileObject,ClassPath>of(fo, cp));
}
}
}
return result;
}
示例8: getSourceClassPathFor
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public static ClassPath getSourceClassPathFor(FileObject file) {
Pair<FileObject,Reference<ClassPath>> ce = rootCache;
ClassPath cp;
if (ce != null &&
(cp = ce.second().get()) != null &&
ce.first().equals(cp.findOwnerRoot(file))) {
return cp;
}
for (String sourceCP : PathRecognizerRegistry.getDefault().getSourceIds()) {
cp = ClassPath.getClassPath(file, sourceCP);
if (cp != null) {
final FileObject root = cp.findOwnerRoot(file);
if (root != null) {
rootCache = Pair.<FileObject,Reference<ClassPath>>of(
root,
new WeakReference<ClassPath>(cp));
}
return cp;
}
}
return null;
}
示例9: findModuleNames
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private void findModuleNames(String fqn, ClassPath searchPath, Set<String> moduleNames) {
fqn = fqn.replace(".", "/"); // NOI18N
String resourceName = fqn + CLASS_EXTENSION;
FileObject classResource = searchPath.findResource(resourceName);
if (classResource == null || classResource.isFolder()) {
int last = fqn.length();
for (int i = fqn.lastIndexOf('.'); i >= 0; i = fqn.lastIndexOf('/', last)) { // NOI18N
resourceName = fqn.substring(0, i);
classResource = searchPath.findResource(resourceName + CLASS_EXTENSION);
if (classResource != null && classResource.isData()) {
resourceName += fqn.substring(i).replace("/", "$") + CLASS_EXTENSION; // NOI18N
classResource = searchPath.findResource(resourceName);
break;
}
classResource = searchPath.findResource(resourceName);
if (classResource != null && classResource.isFolder()) {
return;
}
}
}
if (classResource != null) {
final FileObject r = searchPath.findOwnerRoot(classResource);
for (ClassPath.Entry e : searchPath.entries()) {
final FileObject er = e.getRoot();
if (er != null && er.equals(r)) {
String name = SourceUtils.getModuleName(e.getURL(), true);
moduleNames.add(name);
}
}
}
}
示例10: findOwnerRoot
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@CheckForNull
private static URL findOwnerRoot(
@NonNull final FileObject file,
@NonNull final Collection<? extends String> ids) {
for (String id : ids) {
final ClassPath cp = ClassPath.getClassPath(file, id);
if (cp != null) {
final FileObject owner = cp.findOwnerRoot(file);
if (owner != null) {
return owner.toURL();
}
}
}
return null;
}
示例11: run
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@Override
public void run() {
LOG.log(Level.FINE, "dequeued work for: {0}", fileOrRoot);
final ClassPath cp = ClassPath.getClassPath(fileOrRoot, ClassPath.SOURCE);
if (cp == null) {
LOG.log(Level.FINE, "cp == null");
return;
}
FileObject root = cp.findOwnerRoot(fileOrRoot);
if (root == null) {
Project p = FileOwnerQuery.getOwner(fileOrRoot);
LOG.log(Level.WARNING,
"file: {0} is not on its own source classpath: {1}, project: {2}",
new Object[] {
FileUtil.getFileDisplayName(fileOrRoot),
cp.toString(ClassPath.PathConversionMode.PRINT),
p != null ? p.getClass() : "null"
});
return ;
}
if (fileOrRoot.isData()) {
updateErrorsInFile(callback, root, fileOrRoot);
} else {
updateErrorsInRoot(callback, root, canceled);
}
}
示例12: getSourceLevel
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Determines source level of the given file.
*
* @param file file whose source level is to be determined
* @return string denoting source level of the given file
* (e.g. <code>"1.5"</code>)
* or {@literal null} if the source level could not be determined
*/
public static String getSourceLevel(FileObject file) {
ClassPath srcCP = ClassPath.getClassPath(file, ClassPath.SOURCE);
if (srcCP == null) {
return null;
}
FileObject srcRoot = srcCP.findOwnerRoot(file);
if (srcRoot == null) {
return null;
}
return SourceLevelQuery.getSourceLevel(srcRoot);
}
示例13: findOwnerRoot
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@CheckForNull
private static FileObject findOwnerRoot(@NonNull final FileObject file) {
final ClassPath sourcePath = ClassPath.getClassPath(file, ClassPath.SOURCE);
return sourcePath == null ? null : sourcePath.findOwnerRoot(file);
}
示例14: findClassPath
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public ClassPath findClassPath(FileObject fo, String type) {
if (!SUPPORTED_CLASS_PATH_TYPES.contains(type)) {
return null;
}
if (fo == null || type == null) {
throw new IllegalArgumentException();
}
JavaPlatform lp = this.getLastUsedPlatform(fo);
JavaPlatform[] platforms;
if (lp != null) {
platforms = new JavaPlatform[] {lp};
}
else {
JavaPlatformManager manager = JavaPlatformManager.getDefault();
platforms = manager.getInstalledPlatforms();
}
for (JavaPlatform jp : platforms) {
ClassPath bootClassPath = jp.getBootstrapLibraries();
ClassPath libraryPath = jp.getStandardLibraries();
ClassPath sourcePath = jp.getSourceFolders();
FileObject root = null;
if (ClassPath.SOURCE.equals(type) && sourcePath != null &&
(root = sourcePath.findOwnerRoot(fo))!=null) {
this.setLastUsedPlatform (root,jp);
return sourcePath;
} else if (ClassPath.BOOT.equals(type) &&
(root = getArtefactOwner(fo, bootClassPath, libraryPath, sourcePath)) != null ) {
this.setLastUsedPlatform (root,jp);
return bootClassPath;
} else if (ClassPath.COMPILE.equals(type)) {
if (libraryPath != null && (root = libraryPath.findOwnerRoot(fo))!=null) {
this.setLastUsedPlatform (root,jp);
return libraryPath;
}
else if ((bootClassPath != null && (root = bootClassPath.findOwnerRoot (fo))!=null) ||
(sourcePath != null && (root = sourcePath.findOwnerRoot(fo)) != null)) {
return this.getEmptyClassPath ();
}
} else if (JavaClassPathConstants.MODULE_BOOT_PATH.equals(type) &&
JAVA_9.compareTo(jp.getSpecification().getVersion()) <= 0 &&
(root = getArtefactOwner(fo, bootClassPath, libraryPath, sourcePath)) != null) {
this.setLastUsedPlatform (root,jp);
return bootClassPath;
}
}
return null;
}
示例15: performAction
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
protected void performAction (Node[] nodes) {
FileObject selectedFO;
for (int i = 0; i < nodes.length; i++) {
// get test class or suite class file, if it was not such one pointed by the node
selectedFO = org.netbeans.modules.gsf.testrunner.ui.api.UICommonUtils.getFileObjectFromNode(nodes[i]);
if (selectedFO == null) {
JUnitTestUtil.notifyUser(NbBundle.getMessage(OpenTestAction.class, "MSG_file_from_node_failed"));
continue;
}
ClassPath cp = ClassPath.getClassPath(selectedFO, ClassPath.SOURCE);
if (cp == null) {
JUnitTestUtil.notifyUser(NbBundle.getMessage(OpenTestAction.class,
"MSG_no_project", selectedFO));
continue;
}
FileObject packageRoot = cp.findOwnerRoot(selectedFO);
URL[] testRoots = UnitTestForSourceQuery.findUnitTests(packageRoot);
FileObject fileToOpen = null;
for (int j = 0 ; j < testRoots.length; j++) {
fileToOpen = findUnitTestInTestRoot(cp, selectedFO, testRoots[j]);
if (fileToOpen != null) break;
}
if (fileToOpen != null) {
openFile(fileToOpen);
} else {
String testClsName = getTestName(cp, selectedFO).replace('/','.');
String pkgName = cp.getResourceName(selectedFO, '.', false);
boolean isPackage = selectedFO.isFolder();
boolean isDefPkg = isPackage && (pkgName.length() == 0);
String msgPattern = !isPackage
? "MSG_test_class_not_found" //NOI18N
: isDefPkg
? "MSG_testsuite_class_not_found_def_pkg" //NOI18N
: "MSG_testsuite_class_not_found"; //NOI18N
String[] params = isDefPkg ? new String[] { testClsName }
: new String[] { testClsName,
pkgName };
JUnitTestUtil.notifyUser(NbBundle.getMessage(OpenTestAction.class,
msgPattern, params),
ErrorManager.INFORMATIONAL);
continue;
}
}
}