本文整理汇总了Java中org.netbeans.api.java.classpath.ClassPath.getClassPath方法的典型用法代码示例。如果您正苦于以下问题:Java ClassPath.getClassPath方法的具体用法?Java ClassPath.getClassPath怎么用?Java ClassPath.getClassPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.classpath.ClassPath
的用法示例。
在下文中一共展示了ClassPath.getClassPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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 = TestUtil.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;
}
示例2: findDeclaringSource
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Locate the declaration of an object declared as a newvalue or methodvalue attribute.
* @param instanceAttribute the result of {@link FileObject#getAttribute} on a {@code literal:*} key
* @return the source file containing the corresponding declaration, or null if not found
*/
private @CheckForNull FileObject findDeclaringSource(@NullAllowed Object instanceAttribute) {
if (!(instanceAttribute instanceof String)) {
return null;
}
// XXX this will not find classes in a sister module; maybe look in ClassPath.EXECUTE, then use SFBQ to find it?
ClassPath src = ClassPath.getClassPath(layer.getLayerFile(), ClassPath.SOURCE); // should work even for Maven src/main/resources/.../layer.xml
if (src == null) {
return null;
}
String attr = (String) instanceAttribute;
if (attr.startsWith("new:")) {
return src.findResource(attr.substring(4).replaceFirst("[$][^.]+$", "").replace('.', '/') + ".java");
} else if (attr.startsWith("method:")) {
return src.findResource(attr.substring(7, attr.lastIndexOf('.')).replaceFirst("[$][^.]+$", "").replace('.', '/') + ".java");
} else {
return null;
}
}
示例3: getTestFileObject
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Grabs and checks a <code>FileObject</code> from the given node.
* If either the file could not be grabbed or the file does not pertain
* to any project, a message is displayed.
*
* @param node node to get a <code>FileObject</code> from.
* @return the grabbed <code>FileObject</code>,
* or <code>null</code> in case of failure
*/
private static FileObject getTestFileObject(final Node node) {
final FileObject fo = UICommonUtils.getFileObjectFromNode(node);
if (fo == null) {
JUnitTestUtil.notifyUser(NbBundle.getMessage(
JUnitTestCreatorProvider.class,
"MSG_file_from_node_failed")); //NOI18N
return null;
}
ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
if (cp == null) {
JUnitTestUtil.notifyUser(NbBundle.getMessage(
JUnitTestCreatorProvider.class,
"MSG_no_project", //NOI18N
fo));
return null;
}
return fo;
}
示例4: findFileObject
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static FileObject findFileObject(DataObject srcDataObject, String path) {
FileObject pfo = srcDataObject.getPrimaryFile();
ClassPath cp = ClassPath.getClassPath(pfo, ClassPath.EXECUTE);
// #167334
if(cp == null) {
LOG.info("Unable to find FileObject due to ClassPath is null");
return null;
}
for(FileObject fo : getRoots(cp)) {
try {
FileSystem fs = fo.getFileSystem();
if (fs != null) {
FileObject retval = fs.findResource(path);
if (retval != null) {
return retval;
}
}
} catch (FileStateInvalidException ex) {
LOG.log(Level.INFO, null, ex);
}
}
return null;
}
示例5: 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;
}
示例6: getProjectClassPath
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Returns the project classpath including project build paths.
* Can be used to set classpath for custom classloader.
*
* @param project the current project.
* @return List of java.net.URL objects representing each entry on the classpath.
*/
public static List<URL> getProjectClassPath(Project project) {
List<URL> projectClassPathEntries = new ArrayList<URL>();
for (SourceGroup sourceGroup : getSourceGroups(project)) {
if (sourceGroup == null) {
continue;
}
ClassPath cp = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE);
for (ClassPath.Entry cpEntry : cp.entries()) {
projectClassPathEntries.add(cpEntry.getURL());
}
}
return projectClassPathEntries;
}
示例7: prepare
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@Override
public Problem prepare(RefactoringElementsBag refactoringElementsBag) {
if (isPackage()){
FileObject pkg = renameRefactoring.getRefactoringSource().lookup(NonRecursiveFolder.class).getFolder();
String oldPackageName = JavaIdentifiers.getQualifiedName(pkg);
return doPrepare(refactoringElementsBag, pkg, oldPackageName, renameRefactoring.getNewName());
} else if (isFolder()){
FileObject folder = renameRefactoring.getRefactoringSource().lookup(FileObject.class);
ClassPath classPath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
if(classPath == null){
return null;//it may happens for folders in php and similar projects, see #181611
}
FileObject root = classPath.findOwnerRoot(folder);
// issue 62320. By JavaDoc, ClassPath.fineOwnerRoot can return null
if(root == null ) {
return null;
}
String prefix = FileUtil.getRelativePath(root, folder.getParent());
// #249491
if (prefix == null) {
return null;
}
prefix = prefix.replace('/','.'); // NOI18N
String oldName = buildName(prefix, folder.getName());
// the new package name
String newName = buildName(prefix, renameRefactoring.getNewName());
return doPrepare(refactoringElementsBag, folder, oldName, newName);
}
return null;
}
示例8: getSourceRoot
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Returns the source root (if any) for given url.
*
* @param url a url of resource file
*
* @return the source root or <code>null</code> when no source root was found.
*/
@Override
public synchronized String getSourceRoot(String url) {
FileObject fo;
try {
fo = URLMapper.findFileObject(new java.net.URL(url));
} catch (java.net.MalformedURLException ex) {
fo = null;
}
FileObject[] roots = null;
if (fo != null && fo.canRead()) {
ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
if (cp != null) {
roots = cp.getRoots();
}
}
if (roots == null) {
roots = originalSourcePath.getRoots();
}
for (FileObject fileObject : roots) {
String rootURL = fileObject.toURL().toString();
if (url.startsWith(rootURL)) {
String root = getRoot(fileObject);
if (root != null) {
return root;
}
}
}
return null; // not found
}
示例9: doFindModuleUsages
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public static Map<URL, Collection<ClassPath>> doFindModuleUsages(FileObject projectArtifact, Collection<URL> locations) {
Project p = FileOwnerQuery.getOwner(projectArtifact);
if (p == null) {
return Collections.emptyMap();
}
Map<String, URL> modLocations = new HashMap<>();
for (URL u : locations) {
String n = SourceUtils.getModuleName(u, true);
if (n != null) {
modLocations.put(n, u);
}
}
Map<URL, Collection<ClassPath>> resultMap = new HashMap<>();
Set seenCP = new HashSet<>();
for (SourceGroup g : ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
FileObject r = g.getRootFolder();
ClassPath src = ClassPath.getClassPath(r, ClassPath.SOURCE);
if (!seenCP.add(Arrays.asList(src.getRoots()))) {
continue;
}
if (src.findResource("module-info.java") == null) {
continue;
}
JavaSource js = JavaSource.forFileObject(r);
if (js != null) {
try {
js.runUserActionTask(new S(src, modLocations, resultMap), true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
return resultMap;
}
示例10: RenameNonRecursiveFolder
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public RenameNonRecursiveFolder(NonRecursiveFolder nrfo, RefactoringElementsBag session) {
this.folder = nrfo.getFolder();
this.session = session;
ClassPath cp = ClassPath.getClassPath(
folder, ClassPath.SOURCE);
this.currentName = cp.getResourceName(folder, '.', false);
this.oldName = this.currentName;
this.root = cp.findOwnerRoot(folder);
}
示例11: bundlesNode
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Prepare node structure for showing available bundles. The
* structure is relative to the file that should access the
* bundle.
* @param prj the <code>Project</code> <code>file</code> is in
* @param file <code>FileObject</code> to show bundles for
* @param includeFiles specifies whether to show jar files or just folders
* @return root <code>Node</code>
*/
static public Node bundlesNode(Project prj, FileObject file, boolean includeFiles) {
List<Node> nodes = new LinkedList<Node>();
if (prj == null) {
prj = FileOwnerQuery.getOwner(file);
}
ClassPath cp = ClassPath.getClassPath(file, ClassPath.EXECUTE);
if (cp != null) {
nodes.addAll(getRootNodes(prj, getRoots(ClassPath.getClassPath(file, ClassPath.SOURCE), cp), BUNDLES_FILTER, includeFiles));
}
return createRootFor(nodes, prj);
}
示例12: getAllClassPaths
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static Set<ClassPath> getAllClassPaths(Set<FileObject> fileObjects, String id) {
Set<ClassPath> classPaths = new HashSet<ClassPath>();
for (FileObject fileObject : fileObjects) {
ClassPath cp = ClassPath.getClassPath(fileObject, id);
if (cp != null) {
classPaths.add(cp);
}
}
return classPaths;
}
示例13: getPkgResourceName
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static String getPkgResourceName(FileObject fo) {
ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
if (cp != null) {
return cp.getResourceName(fo.isFolder() ? fo : fo.getParent());
} else {
return null;
}
}
示例14: testModuleBootPath
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testModuleBootPath() {
final ClassPath mod1aCp = ClassPath.getClassPath(mod1a, JavaClassPathConstants.MODULE_BOOT_PATH);
assertNotNull(mod1aCp);
assertTrue(systemModules == null || urls(systemModules).equals(urls(mod1aCp)));
ClassPath bootCp = ClassPath.getClassPath(mod1b, JavaClassPathConstants.MODULE_BOOT_PATH);
assertSame(mod1aCp, bootCp);
bootCp = ClassPath.getClassPath(mod2c, JavaClassPathConstants.MODULE_BOOT_PATH);
assertSame(mod1aCp, bootCp);
bootCp = ClassPath.getClassPath(mod1d, JavaClassPathConstants.MODULE_BOOT_PATH);
assertSame(mod1aCp, bootCp);
bootCp = ClassPath.getClassPath(mod2d, JavaClassPathConstants.MODULE_BOOT_PATH);
assertSame(mod1aCp, bootCp);
}
示例15: inferBinaryName
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Infers a JavaFileObject
* @param jfm the file manager
* @param jfo the file to be inferred
* @return a inferred name
* @throws IllegalArgumentException when file cannot be inferred.
*/
@NonNull
private static String inferBinaryName(
@NonNull final JavaFileManager jfm,
@NonNull final javax.tools.JavaFileObject jfo) throws IllegalArgumentException {
String result = jfm.inferBinaryName(StandardLocation.SOURCE_PATH, jfo);
if (result != null) {
return result;
}
FileObject fo = null;
ClassPath scp = null;
try {
fo = URLMapper.findFileObject(jfo.toUri().toURL());
if (fo != null) {
scp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
if (scp != null) {
result=scp.getResourceName(fo, '.', false); //NOI18N
if (result != null) {
return result;
}
}
}
} catch (MalformedURLException e) {
//pass - throws IAE
}
throw new IllegalArgumentException(String.format("File: %s Type: %s FileObject: %s Sourcepath: %s", //NOI18N
jfo.toUri().toString(),
jfo.getClass().getName(),
fo == null ? "<null>" : FileUtil.getFileDisplayName(fo), //NOI18N
scp == null? "<null>" : scp.toString())); //NOI18N
}