本文整理汇总了Java中org.netbeans.api.java.source.ClasspathInfo.getClassIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ClasspathInfo.getClassIndex方法的具体用法?Java ClasspathInfo.getClassIndex怎么用?Java ClasspathInfo.getClassIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.source.ClasspathInfo
的用法示例。
在下文中一共展示了ClasspathInfo.getClassIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileObjectFromClassName
import org.netbeans.api.java.source.ClasspathInfo; //导入方法依赖的package包/类
public static FileObject getFileObjectFromClassName(String qualifiedClassName, Project project) throws IOException {
FileObject root = findSourceRoot(project);
ClasspathInfo cpInfo = ClasspathInfo.create(root);
ClassIndex ci = cpInfo.getClassIndex();
int beginIndex = qualifiedClassName.lastIndexOf('.')+1;
String simple = qualifiedClassName.substring(beginIndex);
Set<ElementHandle<TypeElement>> handles = ci.getDeclaredTypes(
simple, ClassIndex.NameKind.SIMPLE_NAME,
Collections.singleton(ClassIndex.SearchScope.SOURCE));
for (ElementHandle<TypeElement> handle : handles) {
if (qualifiedClassName.equals(handle.getQualifiedName())) {
return SourceUtils.getFile(handle, cpInfo);
}
}
return null;
}
示例2: commonSetup
import org.netbeans.api.java.source.ClasspathInfo; //导入方法依赖的package包/类
void commonSetup() throws Exception {
Logger l = Logger.getLogger(WriteBackTransaction.class.getName());
l.setLevel(Level.FINE);
l.addHandler(logHandler);
TEST_LOGGER.setLevel(Level.ALL);
List ll = new ArrayList<PathResourceImplementation>();
ll.add(ClassPathSupport.createResource(srcRoot.getURL()));
ll.add(ClassPathSupport.createResource(srcRoot2.getURL()));
spiSrc.setImpls(ll);
registerGlobalPath(ClassPath.BOOT, new ClassPath[] {bootPath});
registerGlobalPath(ClassPath.COMPILE, new ClassPath[] {compilePath});
registerGlobalPath(ClassPath.SOURCE, new ClassPath[] {sourcePath});
final ClassPath scp = ClassPathSupport.createClassPath(srcRoot, srcRoot2);
final ClasspathInfo cpInfo = ClasspathInfo.create(
ClassPathSupport.createClassPath(new URL[0]),
ClassPathSupport.createClassPath(new URL[0]),
scp);
ci = cpInfo.getClassIndex();
RepositoryUpdater.getDefault().start(true);
// make the initial scan, with 'src' and 'src2'
logHandler.waitForInitialScan(2);
// ensure the cache will flush after each file:
WriteBackTransaction.disableCache = true;
}
示例3: crawlProject
import org.netbeans.api.java.source.ClasspathInfo; //导入方法依赖的package包/类
final synchronized boolean crawlProject(Project project) {
ClasspathInfo cpi = getClasspathInfo(project);
ClassIndex ci = cpi.getClassIndex();
ElementHandle<TypeElement> ancestor = getTypeOfClass(ci, fqn);
// if ancestor in not on the classpath, don't do anything.
if (ancestor == null) {
return false;
}
// get all implementors
Set<ElementHandle<TypeElement>> list = getAllSubtypes(ci, ancestor);
JavaSource js = JavaSource.create(cpi);
try {
FilterAbstract filter = new FilterAbstract(list);
// Filter will remove some elements from list (inplace)
js.runUserActionTask(filter, true);
// notify listeners about new data
notifyCrawledData(filter.getResult());
return false;
} catch (IOException ex) {
// TODO: What exact error?
list.clear();
return true;
}
}
示例4: crawl
import org.netbeans.api.java.source.ClasspathInfo; //导入方法依赖的package包/类
@Override
public final synchronized void crawl() {
ClasspathInfo cpi = getClasspathInfo(project);
ClassIndex ci = cpi.getClassIndex();
ElementHandle<TypeElement> ancestor = getTypeOfClass(ci, fqn);
// if ancestor in not on the classpath, don't do anything.
if (ancestor == null) {
return;
}
notifyStarted();
// get all implementors
Set<ElementHandle<TypeElement>> list = getAllSubtypes(ci, ancestor);
JavaSource js = JavaSource.create(cpi);
try {
FilterAbstract filter = new FilterAbstract(list);
// Filter will remove some elements from list (inplace)
js.runUserActionTask(filter, true);
// notify listeners about new data
notifyCrawledData(filter.getResult());
notifyFinished(false);
return;
} catch (IOException ex) {
// TODO: What exact error?
list.clear();
notifyFinished(true);
return;
}
}