本文整理汇总了Java中org.netbeans.api.java.source.ElementHandle.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java ElementHandle.getKind方法的具体用法?Java ElementHandle.getKind怎么用?Java ElementHandle.getKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.source.ElementHandle
的用法示例。
在下文中一共展示了ElementHandle.getKind方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeReferenceCount
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
/**
* Returns an estimate of a number of classes on given source path (source root) which are
* using given type.
* @param type the type type to find the usage frequency for.
* @return number of classes using the type.
*/
public int getTypeReferenceCount(@NonNull final ElementHandle<? extends TypeElement> type) {
Parameters.notNull("binaryName", type); //NOI18N
if (!type.getKind().isClass() &&
!type.getKind().isInterface() &&
type.getKind() != ElementKind.OTHER) {
throw new IllegalArgumentException(type.toString());
}
try {
init();
final Integer count = typeFreqs.get(SourceUtils.getJVMSignature(type)[0]);
return count == null ? 0 : count;
} catch (InterruptedException ie) {
return 0;
}
}
示例2: check
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
@Override
public WhiteListQuery.Result check(ElementHandle<?> element, WhiteListQuery.Operation operation) {
if (!operation.equals(WhiteListQuery.Operation.USAGE)) {
return OK;
}
List<WhiteListQuery.RuleDescription> rds = new ArrayList<WhiteListQuery.RuleDescription>();
if (element.getKind() == ElementKind.CLASS || element.getKind() == ElementKind.INTERFACE) {
String qn = element.getQualifiedName();
if (qn.lastIndexOf('.') > 0) {
String pack = qn.substring(0, qn.lastIndexOf("."));
synchronized (IMPL_LOCK) {
if (privatePackages.contains(pack)) {
rds.add(PRIVATE_RD);
}
if (transitivePackages.contains(pack)) {
rds.add(TRANSITIVE_RD);
}
}
if (!rds.isEmpty()) {
return new WhiteListQuery.Result(rds);
}
}
}
return OK;
}
示例3: enable
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
protected boolean enable(Node[] activatedNodes) {
ElementHandle eh = getHandle(activatedNodes);
ElementKind kind = eh == null ? null : eh.getKind();
if (ElementKind.METHOD.equals(kind) || ElementKind.CONSTRUCTOR.equals(kind)) {
name = Bundle.ProfileMethodEditorAction_Name();
return true;
}
if (ElementKind.CLASS.equals(kind)) {
name = Bundle.ProfileClassEditorAction_Name();
return true;
}
name = Bundle.ProfileElementNavigatorAction_Name();
return false;
}
示例4: Description
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
private Description(@NonNull ClassMemberPanelUI ui,
@NonNull final String name,
@NonNull final ElementHandle<? extends Element> elementHandle,
final int posInKind,
@NonNull final ClasspathInfo cpInfo,
@NonNull final Set<Modifier> modifiers,
final long pos,
final boolean inherited,
final boolean topLevel) {
Parameters.notNull("ui", ui); //NOI18N
Parameters.notNull("name", name); //NOI18N
Parameters.notNull("elementHandle", elementHandle); //NOI18N
this.ui = ui;
this.name = name;
this.handle = Union2.<ElementHandle<?>,TreePathHandle>createFirst(elementHandle);
this.kind = elementHandle.getKind();
this.posInKind = posInKind;
this.cpInfo = cpInfo;
this.modifiers = modifiers;
this.pos = pos;
this.isInherited = inherited;
this.isTopLevel = topLevel;
this.icon = () -> ElementIcons.getElementIcon(this.kind, this.modifiers);
this.openable = () -> {OpenAction.openable(elementHandle, getFileObject(), name).open();};
}
示例5: getPackageReferenceCount
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
/**
* Returns an estimate of a number of classes on given source path (source root) which are
* using given package.
* @param pkg the package to find the usage frequency for.
* @return number of classes using types from given package.
*/
public int getPackageReferenceCount(@NonNull final ElementHandle<? extends PackageElement> pkg) {
Parameters.notNull("pkgName", pkg); //NOI18N
if (pkg.getKind() != ElementKind.PACKAGE) {
throw new IllegalArgumentException(pkg.toString());
}
try {
init();
final Integer count = pkgFreqs.get(SourceUtils.getJVMSignature(pkg)[0]);
return count == null ? 0 : count;
} catch (InterruptedException ie) {
return 0;
}
}
示例6: MemberSearchResult
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
public MemberSearchResult(ElementHandle<? extends Element> conflicting) {
this.conflicting = conflicting;
this.shadowed = null;
this.shadowedGate = null;
this.gateSuper = false;
this.requiredModifier = null;
this.conflictingPath = null;
this.kind = conflicting.getKind();
}
示例7: loadDescenantsOfNode2
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
Set<ElementHandle<TypeElement>> loadDescenantsOfNode2() {
// get javafx.scene.Node descendants
TypeElement baseClass = getBaseClass();
if (baseClass == null) {
// something wrong, fxml rt class does not exist
LOG.warning("javafx.scene.Node class not fond");
return Collections.emptySet();
}
ClasspathInfo info = ctx.getClasspathInfo();
ElementHandle<TypeElement> nodeHandle = ElementHandle.create (baseClass);
Set<ElementHandle<TypeElement>> allTypesSeen = new HashSet<ElementHandle<TypeElement>>();
Deque<ElementHandle<TypeElement>> handles = new LinkedList<ElementHandle<TypeElement>>();
handles.add(nodeHandle);
long time = System.currentTimeMillis();
allTypesSeen.add(nodeHandle);
while (!handles.isEmpty()) {
ElementHandle<TypeElement> baseHandle = handles.poll();
LOG.log(Level.FINE, "Loading descendants of {0}", baseHandle);
Set<ElementHandle<TypeElement>> descendants = new HashSet<ElementHandle<TypeElement>>(
info.getClassIndex().getElements(baseHandle,
EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS),
EnumSet.of(ClassIndex.SearchScope.DEPENDENCIES, ClassIndex.SearchScope.SOURCE)
)
);
// eliminate duplicates
descendants.removeAll(allTypesSeen);
allTypesSeen.addAll(descendants);
handles.addAll(descendants);
LOG.log(Level.FINE, "Unique descendants: {0}", descendants);
}
long diff = System.currentTimeMillis();
LOG.log(Level.FINE, "Loading Node descendants took: {0}ms", diff);
Set<ElementHandle<TypeElement>> result = new HashSet<ElementHandle<TypeElement>>();
// add descendants not yet seen to the next processing round
for (ElementHandle<TypeElement> htype : allTypesSeen) {
if (!(
htype.getKind() == ElementKind.CLASS || htype.getKind() == ElementKind.INTERFACE)) {
continue;
}
String n = htype.getQualifiedName();
if (n.length() < namePrefix.length()) {
// shorter name, does not match prefix
continue;
}
int lastDot = n.lastIndexOf('.');
if (lastDot != -1 && packagePrefix != null && (
lastDot < packagePrefix.length() || !n.startsWith(packagePrefix))) {
continue;
}
if (CompletionUtils.startsWith(n.substring(lastDot + 1), namePrefix)) {
result.add(htype);
}
}
return result;
}
示例8: getCompletions
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
@Override
public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
ProcessingEnvironment processingEnv = this.processingEnv.get();
if (processingEnv == null)
return Collections.emptyList();
TypeElement annotationObj = processingEnv.getElementUtils().getTypeElement("java.lang.annotation.Annotation");
if (annotationObj == null)
return Collections.emptyList();
Trees trees = Trees.instance(processingEnv);
TreePath path = trees.getPath(element);
if (path == null)
return Collections.emptyList();
FileObject owner;
try {
owner = URLMapper.findFileObject(path.getCompilationUnit().getSourceFile().toUri().toURL());
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
return Collections.emptyList();
}
ClassIndex ci = ClasspathInfo.create(owner).getClassIndex();
if (ci == null)
return Collections.emptyList();
List<Completion> result = new LinkedList<Completion>();
// for (ElementHandle<TypeElement> eh : ci.getElements(ElementHandle.create(annotationObj), EnumSet.of(SearchKind.IMPLEMENTORS), EnumSet.of(SearchScope.DEPENDENCIES, SearchScope.SOURCE))) {
// result.add(new CompletionImpl(eh.getQualifiedName()));
// }
for (ElementHandle<TypeElement> eh : ci.getDeclaredTypes("", ClassIndex.NameKind.PREFIX, EnumSet.of(SearchScope.DEPENDENCIES, SearchScope.SOURCE))) {
if (eh.getKind() != ElementKind.ANNOTATION_TYPE) continue;
result.add(new CompletionImpl('\"' + eh.getQualifiedName() + '\"'));
}
return result;
}
示例9: isAllowed
import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
boolean isAllowed(
@NonNull final ElementHandle<?> element,
final byte mode) {
final String[] vmSignatures = SourceUtils.getJVMSignature(element);
final String[] pkgNamePair = splitName(vmSignatures[0],'.'); //NOI18N
if (isThere(allowedPackages, pkgNamePair[0])) {
return true;
}
if (isThere(disallowedPackages, pkgNamePair[0])) {
return false;
}
if (!checkedPkgs.second().matcher(pkgNamePair[0]+'.').matches()) { //NOI18N
return true;
}
final Integer pkgId = names.getName(pkgNamePair[0]);
final Integer clsId = names.getName(pkgNamePair[1]);
final IntermediateCacheNode<IntermediateCacheNode<IntermediateCacheNode<CacheNode>>> pkgNode = root.get(pkgId);
if (pkgNode == null) {
return false;
}
final IntermediateCacheNode<IntermediateCacheNode<CacheNode>> clsNode = pkgNode.get(clsId);
if (clsNode == null) {
return false;
}
if ((clsNode.state & mode) == mode) {
return true;
}
if (element.getKind() == ElementKind.METHOD ||
element.getKind() == ElementKind.CONSTRUCTOR) {
final Integer methodNameId = names.getName(vmSignatures[1]);
final Integer methodSigId = names.getName(paramsOnly(vmSignatures[2]));
final IntermediateCacheNode<CacheNode> methodNameNode = clsNode.get(methodNameId);
if (methodNameNode == null) {
return false;
}
final CacheNode methodSigNode = methodNameNode.get(methodSigId);
if (methodSigNode == null) {
return false;
}
return (methodSigNode.state & mode) == mode;
} else if ((element.getKind().isClass() ||
element.getKind().isInterface()) && clsNode.hasChildren()) {
//If the request is for type and it has at least one alowed method
//allow it. It would be strange to black list type usage which method is allowed
return true;
}
return false;
}