本文整理汇总了Java中org.netbeans.api.java.source.ClassIndex类的典型用法代码示例。如果您正苦于以下问题:Java ClassIndex类的具体用法?Java ClassIndex怎么用?Java ClassIndex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassIndex类属于org.netbeans.api.java.source包,在下文中一共展示了ClassIndex类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: fillSubTypes
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
private List<DeclaredType> fillSubTypes(CompilationController cc, DeclaredType dType) {
List<DeclaredType> subtypes = new ArrayList<>();
//Set<? extends SearchScopeType> scope = Collections.singleton(new ClassSearchScopeType(prefix));
Types types = cc.getTypes();
if (prefix != null && prefix.length() > 2 && lastPrefixDot < 0) {
//Trees trees = cc.getTrees();
ClassIndex.NameKind kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
for (ElementHandle<TypeElement> handle : cpi.getClassIndex().getDeclaredTypes(prefix, kind, EnumSet.allOf(ClassIndex.SearchScope.class))) {
TypeElement te = handle.resolve(cc);
if (te != null && /*trees.isAccessible(scope, te) &&*/ types.isSubtype(types.getDeclaredType(te), dType)) {
subtypes.add(types.getDeclaredType(te));
}
}
} else {
HashSet<TypeElement> elems = new HashSet<>();
LinkedList<DeclaredType> bases = new LinkedList<>();
bases.add(dType);
ClassIndex index = cpi.getClassIndex();
while (!bases.isEmpty()) {
DeclaredType head = bases.remove();
TypeElement elem = (TypeElement) head.asElement();
if (!elems.add(elem)) {
continue;
}
if (accept(elem)) {
subtypes.add(head);
}
//List<? extends TypeMirror> tas = head.getTypeArguments();
//boolean isRaw = !tas.iterator().hasNext();
for (ElementHandle<TypeElement> eh : index.getElements(ElementHandle.create(elem), EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS), EnumSet.allOf(ClassIndex.SearchScope.class))) {
TypeElement e = eh.resolve(cc);
if (e != null) {
DeclaredType dt = types.getDeclaredType(e);
bases.add(dt);
}
}
}
}
return subtypes;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:ExceptionCompletionProvider.java
示例2: createNameFactory
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
@NonNull
private static Convertor<String,String> createNameFactory(@NonNull final ClassIndex.ResourceType type) {
switch (type) {
case SOURCE:
return new Convertor<String,String>() {
@Override
public String convert(String p) {
final int index = p.indexOf('$'); //NOI18N
if (index > 0) {
p = p.substring(0, index);
}
return p;
}
};
case BINARY:
return Convertors.<String>identity();
default:
throw new IllegalArgumentException(String.valueOf(type));
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DocumentUtil.java
示例3: doPackageCompletion
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
private void doPackageCompletion(JavaSource js, final String typedPrefix, final int substitutionOffset) throws IOException {
js.runUserActionTask(new Task<CompilationController>() {
@Override
public void run(CompilationController cc) throws Exception {
if (isCancelled()) {
return;
}
cc.toPhase(Phase.ELEMENTS_RESOLVED);
ClassIndex ci = cc.getClasspathInfo().getClassIndex();
int index = substitutionOffset;
int dotIndex = typedPrefix.lastIndexOf('.'); // NOI18N
if (dotIndex != -1) {
index += (dotIndex + 1); // NOI18N
}
addPackages(ci, typedPrefix, index, CompletionProvider.COMPLETION_ALL_QUERY_TYPE);
}
}, true);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavaPackageCompletor.java
示例4: toSearchScope
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
private Set<ClassIndex.SearchScope> toSearchScope(Set<Scope> scope) {
Set<ClassIndex.SearchScope> sScope = EnumSet.noneOf(ClassIndex.SearchScope.class);
for(Scope s : scope) {
switch (s) {
case DEPENDENCIES: {
sScope.add(ClassIndex.SearchScope.DEPENDENCIES);
break;
}
case SOURCE: {
sScope.add(ClassIndex.SearchScope.SOURCE);
break;
}
}
}
return sScope;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:BaseProfilerTypeUtilsImpl.java
示例5: findImplementors
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
public static Set<ElementHandle<TypeElement>> findImplementors(final ClasspathInfo cpInfo, final ElementHandle<TypeElement> baseType) {
final Set<ClassIndex.SearchKind> kind = EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS);
final Set<ClassIndex.SearchScope> scope = EnumSet.allOf(ClassIndex.SearchScope.class);
final Set<ElementHandle<TypeElement>> allImplementors = new HashSet<ElementHandle<TypeElement>>();
ParsingUtils.invokeScanSensitiveTask(cpInfo, new ScanSensitiveTask<CompilationController>(true) {
@Override
public void run(CompilationController cc) {
Set<ElementHandle<TypeElement>> implementors = cpInfo.getClassIndex().getElements(baseType, kind, scope);
do {
Set<ElementHandle<TypeElement>> tmpImplementors = new HashSet<ElementHandle<TypeElement>>();
allImplementors.addAll(implementors);
for (ElementHandle<TypeElement> element : implementors) {
tmpImplementors.addAll(cpInfo.getClassIndex().getElements(element, kind, scope));
}
implementors = tmpImplementors;
} while (!implementors.isEmpty());
}
});
return allImplementors;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ElementUtilitiesEx.java
示例6: JavacPackageInfo
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
public JavacPackageInfo(ClasspathInfo cpInfo, ClasspathInfo indexInfo, String simpleName, String fqn, Scope scope) {
super(simpleName, fqn, scope);
this.cpInfo = cpInfo;
this.indexInfo = indexInfo;
switch (scope) {
case SOURCE: {
sScope= EnumSet.of(ClassIndex.SearchScope.SOURCE);
break;
}
case DEPENDENCIES: {
sScope = EnumSet.of(ClassIndex.SearchScope.DEPENDENCIES);
break;
}
default: {
sScope = Collections.EMPTY_SET;
}
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavacPackageInfo.java
示例7: getSubpackages
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
@Override
public Collection<SourcePackageInfo> getSubpackages() {
final ClassIndex index = cpInfo.getClassIndex();
final List<SourcePackageInfo> pkgs = new ArrayList<SourcePackageInfo>();
ParsingUtils.invokeScanSensitiveTask(cpInfo, new ScanSensitiveTask<CompilationController>(true) {
@Override
public void run(CompilationController cc) {
for (String pkgName : index.getPackageNames(getBinaryName() + ".", true, sScope)) { // NOI18N
pkgs.add(new JavacPackageInfo(cpInfo, indexInfo, pkgName, pkgName, getScope()));
}
}
});
return pkgs;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavacPackageInfo.java
示例8: getImplementorsAsHandles
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
private Set<ElementHandle<TypeElement>> getImplementorsAsHandles(ClassIndex idx, TypeElement el) {
LinkedList<ElementHandle<TypeElement>> elements = new LinkedList<ElementHandle<TypeElement>>(
implementorsQuery(idx, ElementHandle.create(el)));
Set<ElementHandle<TypeElement>> result = new HashSet<ElementHandle<TypeElement>>();
while (!elements.isEmpty()) {
if (canceled) {
return Collections.emptySet();
}
ElementHandle<TypeElement> next = elements.removeFirst();
if (!result.add(next)) {
// it is a duplicate; do not query again
continue;
}
Set<ElementHandle<TypeElement>> foundElements = implementorsQuery(idx, next);
elements.addAll(foundElements);
}
return result;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:AddPropertyPanel.java
示例9: btnBrowseClassActionPerformed
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
private void btnBrowseClassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseClassActionPerformed
final ClasspathInfo cpi = getClasspathInfo();
String current = this.source.getText();
ElementHandle<TypeElement> handle = TypeElementFinder.find(cpi, current, new TypeElementFinder.Customizer() {
@Override
public Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, ClassIndex.NameKind nameKind, Set<ClassIndex.SearchScope> searchScopes) {
searchScopes.retainAll(Arrays.asList(ClassIndex.SearchScope.SOURCE));
return cpi.getClassIndex().getDeclaredTypes(textForQuery, nameKind, searchScopes);
}
@Override
public boolean accept(ElementHandle<TypeElement> typeHandle) {
return true;
}
});
if (handle == null) {
return;
}
targetClass = handle;
source.setText(handle.getQualifiedName());
classNameChanged(null);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JShellOptions2.java
示例10: addAllTypes
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
private void addAllTypes(JavadocContext env, EnumSet<ElementKind> kinds, Set<? extends Element> toExclude, String prefix, int substitutionOffset) {
// String prefix = env.getPrefix();
CompilationInfo controller = env.javac;
boolean isCaseSensitive = false;
ClassIndex.NameKind kind =
isCaseSensitive? ClassIndex.NameKind.PREFIX : ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
// ClassIndex.NameKind kind = env.isCamelCasePrefix() ?
// Utilities.isCaseSensitive() ? ClassIndex.NameKind.CAMEL_CASE : ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE :
// Utilities.isCaseSensitive() ? ClassIndex.NameKind.PREFIX : ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
Set<ElementHandle<Element>> excludeHandles = null;
if (toExclude != null) {
excludeHandles = new HashSet<ElementHandle<Element>>(toExclude.size());
for (Element el : toExclude) {
excludeHandles.add(ElementHandle.create(el));
}
}
for(ElementHandle<TypeElement> name : controller.getClasspathInfo().getClassIndex().getDeclaredTypes(prefix, kind, EnumSet.allOf(ClassIndex.SearchScope.class))) {
if ((excludeHandles == null || !excludeHandles.contains(name)) && !isAnnonInner(name)) {
items.add(LazyJavaCompletionItem.createTypeItem(name, kinds, substitutionOffset, env.getReferencesCount(), controller.getSnapshot().getSource(), false, false, false, null));
}
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JavadocCompletionQuery.java
示例11: getFileObjectFromClassName
import org.netbeans.api.java.source.ClassIndex; //导入依赖的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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SourceGroupSupport.java
示例12: getTypeOfClass
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
/**
* Find the ElementHandle of TypeElement of clazz in the passed ClassIndex.
* Look in boot, compile and sources.
* @param ci ClassIndex in which we are looking.
* @param clazz class for which TypeElement we are looking
* @return null if no such EH found in ci otherwise first found class with same fqn.
*/
protected final ElementHandle<TypeElement> getTypeOfClass(ClassIndex ci, String classfqn) {
String searchedString = getSimpleNameFromFQN(classfqn);
NameKind kind = NameKind.SIMPLE_NAME;
Set<SearchScope> searchScope = EnumSet.of(SearchScope.DEPENDENCIES, SearchScope.SOURCE);
Set<ElementHandle<TypeElement>> res = ci.getDeclaredTypes(searchedString, kind, searchScope);
// Find if there is a ElementHandle<TypeElement> with same FQN as the ancestor.
for (ElementHandle<TypeElement> eh : res) {
String qn = eh.getQualifiedName();
if (classfqn.equals(qn)) {
return eh;
}
}
return null;
}
开发者ID:kefik,项目名称:Pogamut3,代码行数:23,代码来源:AbstractCrawler.java
示例13: getAllSubtypes
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
/**
* Get all subtypes (either implemetors or subtypes) of certain TypeElement in the ClassIndex.
* I.e. find all {@link TypeElement types} that either (transitively) extend or implement the ancestor.
* @param ci ClassIndex in which we are loooking
* @param ancestorTE type element that is the ancestor.
* @return set of all types that extend / implement ancestor
*/
protected final Set<ElementHandle<TypeElement>> getAllSubtypes(ClassIndex ci, ElementHandle<TypeElement> ancestorTE) {
Set<ElementHandle<TypeElement>> result = new HashSet<ElementHandle<TypeElement>>();
LinkedList<ElementHandle<TypeElement>> todo = new LinkedList<ElementHandle<TypeElement>>();
todo.add(ancestorTE);
while (!todo.isEmpty()) {
// the element we will process in this loop
ElementHandle<TypeElement> curr = todo.removeFirst();
// All extending of the curr
Set<ElementHandle<TypeElement>> subtypesOfCurr = getDirectSubtypes(ci, curr);
if (subtypesOfCurr != null) {// can be null for ancellable tasks
result.addAll(subtypesOfCurr);
todo.addAll(subtypesOfCurr);
}
}
return result;
}
开发者ID:kefik,项目名称:Pogamut3,代码行数:26,代码来源:AbstractCrawler.java
示例14: getHandleClassName
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
public static ElementHandle<TypeElement> getHandleClassName(String qualifiedClassName,
Project project) throws IOException {
FileObject root = MiscUtilities.findSourceRoot(project);
ClassPathProvider provider = project.getLookup().lookup(
ClassPathProvider.class);
ClassPath sourceCp = provider.findClassPath(root, ClassPath.SOURCE);
ClassPath compileCp = provider.findClassPath(root, ClassPath.COMPILE);
ClassPath bootCp = provider.findClassPath(root, ClassPath.BOOT);
ClasspathInfo cpInfo = ClasspathInfo.create(bootCp, compileCp, sourceCp);
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,
EnumSet.of(ClassIndex.SearchScope.SOURCE,
ClassIndex.SearchScope.DEPENDENCIES));
for (final ElementHandle<TypeElement> handle : handles) {
if (qualifiedClassName.equals(handle.getQualifiedName())) {
return handle;
}
}
return null;
}
开发者ID:jeddict,项目名称:jCode,代码行数:24,代码来源:SourceGroupSupport.java
示例15: collectDeclaredTypes
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
public boolean collectDeclaredTypes(
@NullAllowed final Pattern packageName,
@NonNull final String typeName,
@NonNull NameKind kind,
@NonNull Collection<? super JavaTypeDescription> collector) throws IOException, InterruptedException {
if (!initIndex()) {
return false;
}
final SearchScope baseSearchScope = isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE;
SearchScopeType searchScope;
if (packageName != null) {
//FQN
final Set<String> allPackages = new HashSet<>();
index.getPackageNames("", false, allPackages); //NOI18N
final Set<? extends String> packages = filterPackages(packageName, allPackages);
searchScope = ClassIndex.createPackageSearchScope(baseSearchScope, packages.toArray(new String[packages.size()]));
kind = translateSearchType(typeName, kind);
} else {
//simple name
searchScope = baseSearchScope;
}
try {
index.getDeclaredElements(
typeName,
kind,
Collections.unmodifiableSet(Collections.<SearchScopeType>singleton(searchScope)),
DocumentUtil.declaredTypesFieldSelector(true, true),
new JavaTypeDescriptionConvertor(this),
collector);
} catch (Index.IndexClosedException ice) {
//Closed after put into rootCache, ignore
}
return true;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:JavaTypeProvider.java
示例16: fileObjectConvertor
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
@NonNull
public static Convertor<Document,FileObject> fileObjectConvertor (
@NonNull final ClassIndex.ResourceType resourceType,
@NonNull final FileObject... roots) {
assert resourceType != null;
assert roots != null;
return new FileObjectConvertor (resourceType, roots);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:DocumentUtil.java
示例17: translateQueryKind
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
static Queries.QueryKind translateQueryKind(final ClassIndex.NameKind kind) {
switch (kind) {
case SIMPLE_NAME: return Queries.QueryKind.EXACT;
case PREFIX: return Queries.QueryKind.PREFIX;
case CASE_INSENSITIVE_PREFIX: return Queries.QueryKind.CASE_INSENSITIVE_PREFIX;
case CAMEL_CASE: return Queries.QueryKind.CAMEL_CASE;
case CAMEL_CASE_INSENSITIVE: return Queries.QueryKind.CASE_INSENSITIVE_CAMEL_CASE;
case REGEXP: return Queries.QueryKind.REGEXP;
case CASE_INSENSITIVE_REGEXP: return Queries.QueryKind.CASE_INSENSITIVE_REGEXP;
default: throw new IllegalArgumentException();
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:DocumentUtil.java
示例18: FileObjectConvertor
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
private FileObjectConvertor (
@NonNull final ClassIndex.ResourceType type,
@NonNull final FileObject... roots) {
this.nameFactory = createNameFactory(type);
this.filter = createFilter(type);
this.roots = roots;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:DocumentUtil.java
示例19: getDeclaredElements
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
public abstract <T> void getDeclaredElements (
@NonNull String name,
@NonNull ClassIndex.NameKind kind,
@NonNull Set<? extends ClassIndex.SearchScopeType> scope,
@NonNull FieldSelector selector,
@NonNull Convertor<? super Document, T> convertor,
@NonNull Collection<? super T> result) throws IOException, InterruptedException;
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ClassIndexImpl.java
示例20: testOverruningClassIndexScopes
import org.netbeans.api.java.source.ClassIndex; //导入依赖的package包/类
public void testOverruningClassIndexScopes() throws IOException, InterruptedException {
final ClassIndexImpl index = ClassIndexManager.getDefault().getUsagesQuery(src.toURL(), true);
assertNotNull(index);
final List<Document> res = new ArrayList<>(PKG_COUNT*CLZ_IN_PKG_COUNT);
Set<ClassIndex.SearchScopeType> scopes = new HashSet<>();
scopes.add(ClassIndex.SearchScope.SOURCE);
index.getDeclaredElements(
"", //NOI18N
ClassIndex.NameKind.PREFIX,
scopes,
null,
Identity.<Document>getInstance(),
res);
assertEquals(PKG_COUNT*CLZ_IN_PKG_COUNT, res.size());
res.clear();
scopes.clear();
final Set<String> pkgs = new HashSet<>();
index.getPackageNames("", true, pkgs);
assertEquals(PKG_COUNT, pkgs.size());
scopes.add(ClassIndex.createPackageSearchScope(
ClassIndex.SearchScope.SOURCE,
pkgs.toArray(new String[pkgs.size()])));
index.getDeclaredElements(
"", //NOI18N
ClassIndex.NameKind.PREFIX,
scopes,
null,
Identity.<Document>getInstance(),
res);
assertEquals(PKG_COUNT*CLZ_IN_PKG_COUNT, res.size());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:PersistentClassIndexScopesTest.java
注:本文中的org.netbeans.api.java.source.ClassIndex类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论