本文整理汇总了Java中org.netbeans.api.java.source.ElementHandle类的典型用法代码示例。如果您正苦于以下问题:Java ElementHandle类的具体用法?Java ElementHandle怎么用?Java ElementHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ElementHandle类属于org.netbeans.api.java.source包,在下文中一共展示了ElementHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Property
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
Property( PropertyPattern pp, CompilationInfo javac, BiAnalyser bia ) throws GenerateBeanException {
super( pp, bia );
mode = pp.getMode();
pattern = pp;
TypeElement declaringClass = pattern.getDeclaringClass().resolve(javac);
declaringClassName = declaringClass.getQualifiedName().toString();
ElementHandle<ExecutableElement> getterHandle = pattern.getGetterMethod();
getterName = getterHandle == null? null: getterHandle.resolve(javac).getSimpleName().toString();
ElementHandle<ExecutableElement> setterHandle = pattern.getSetterMethod();
setterName = setterHandle == null? null: setterHandle.resolve(javac).getSimpleName().toString();
if (LOG.isLoggable(Level.FINE) && getClass() == Property.class) {
debugTooltip = String.format("<html><body><b>Field:</b> %s<br><b>Getter:</b> %s<br><b>Setter:</b> %s</body></html>", // NOI18N
pp.getEstimatedField() == null
? null
: ElementHeaders.getHeader(pp.getEstimatedField().resolve(javac), javac, ElementHeaders.NAME +
" : " + ElementHeaders.TYPE) + " :: " + // NOI18N
((TypeElement) pp.getEstimatedField().resolve(javac).getEnclosingElement()).getQualifiedName(),
printMethodHandleTip(getterHandle, javac),
printMethodHandleTip(setterHandle, javac)
);
}
}
示例2: CreateEnumConstant
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
public CreateEnumConstant(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, TypeMirror proposedType, FileObject targetFile) {
this.name = name;
this.inFQN = target.getQualifiedName().toString();
this.cpInfo = info.getClasspathInfo();
this.targetFile = targetFile;
this.target = ElementHandle.create(target);
if (proposedType.getKind() == TypeKind.NULL) {
TypeElement tel = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
if (tel != null) {
proposedType = tel.asType();
this.proposedType = TypeMirrorHandle.create(proposedType);
} else {
this.proposedType = null;
}
} else {
this.proposedType = TypeMirrorHandle.create(proposedType);
}
}
示例3: AbstractCreateRelationshipHint
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
public AbstractCreateRelationshipHint(FileObject fileObject,
ElementHandle<TypeElement> classHandle,
AccessType accessType,
String localAttrName,
String targetEntityClassName,
String annotationClass,
String complimentaryAnnotationClassName) {
this.classHandle = classHandle;
this.fileObject = fileObject;
this.accessType = accessType;
this.targetEntityClassName = targetEntityClassName;
this.annotationClass = annotationClass;
this.complimentaryAnnotationClassName = complimentaryAnnotationClassName;
this.localAttrName = localAttrName;
int dotPos = annotationClass.lastIndexOf('.');
relationName = dotPos > -1 ? annotationClass.substring(dotPos+1) : annotationClass;
}
示例4: getFileObjectFromClassName
import org.netbeans.api.java.source.ElementHandle; //导入依赖的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;
}
示例5: getFile
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
@Override
public FileObject getFile() {
ElementHandle<TypeElement> eh = handle;
ClasspathInfo ci = cpInfo;
synchronized(this) {
if (src == null) {
src = SourceUtils.getFile(eh, ci);
if (src == null) {
String resName = eh.getBinaryName().replace('.', '/').concat(".class"); // NOI18N
src = ci.getClassPath(ClasspathInfo.PathKind.BOOT).findResource(resName);
if (src == null) {
src = ci.getClassPath(ClasspathInfo.PathKind.COMPILE).findResource(resName);
if (src == null) {
src = ci.getClassPath(ClasspathInfo.PathKind.SOURCE).findResource(resName);
}
}
}
}
return src;
}
}
示例6: FixImport
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
public FixImport(FileObject file, String fqn, ElementHandle<Element> toImport, String sortText, boolean isValid, CompilationInfo info, @NullAllowed TreePath replacePath, @NullAllowed String replaceSuffix,
boolean doOrganize) {
super(file, fqn, toImport, sortText, isValid);
if (replacePath != null) {
this.replacePathHandle = TreePathHandle.create(replacePath, info);
this.suffix = replaceSuffix;
while (replacePath != null && replacePath.getLeaf().getKind() != Kind.IMPORT) {
replacePath = replacePath.getParentPath();
}
this.statik = replacePath != null ? ((ImportTree) replacePath.getLeaf()).isStatic() : false;
} else {
this.replacePathHandle = null;
this.suffix = null;
this.statik = false;
}
this.doOrganize = doOrganize;
}
示例7: createItem
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
private CompletionItem createItem(ElementHandle<TypeElement> handle, int priority) {
TypeElement el = handle.resolve(ctx.getCompilationInfo());
if (el == null) {
// element does not exist etc
return null;
}
if (el.getKind() != ElementKind.CLASS && el.getKind() != ElementKind.ENUM) {
// do not honour interfaces
return null;
}
if (!el.getModifiers().contains(Modifier.PUBLIC)) {
return null;
}
CompletionItem item = null;
Collection<? extends ClassItemFactory> converters = MimeLookup.getLookup(JavaFXEditorUtils.FXML_MIME_TYPE).lookupAll(ClassItemFactory.class);
for (ClassItemFactory converter : converters) {
item = converter.convert(el, ctx, priority);
if (item != null) {
break;
}
}
return item;
}
示例8: deleteSigFiles
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
private static void deleteSigFiles(final URL root, final List<? extends ElementHandle<TypeElement>> toRemove) throws IOException {
File cacheFolder = JavaIndex.getClassFolder(root);
if (cacheFolder.exists()) {
if (toRemove.size() > CLEAN_ALL_LIMIT) {
//Todo: do as SlowIOTask
FileObjects.deleteRecursively(cacheFolder);
} else {
for (ElementHandle<TypeElement> eh : toRemove) {
final StringBuilder sb = new StringBuilder(FileObjects.convertPackage2Folder(eh.getBinaryName(),File.separatorChar));
sb.append('.'); //NOI18N
sb.append(FileObjects.SIG);
final File f = new File (cacheFolder, sb.toString());
f.delete();
}
}
}
}
示例9: analyze
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
public void analyze(
@NonNull final Iterable<? extends CompilationUnitTree> trees,
@NonNull final JavacTaskImpl jt,
@NonNull final CompileTuple active,
@NonNull final Set<? super ElementHandle<TypeElement>> newTypes,
@NonNull final Set<? super ElementHandle<ModuleElement>> newModules,
@NonNull /*@Out*/ final boolean[] mainMethod) throws IOException {
final SourceAnalyzerFactory.StorableAnalyzer analyzer = getSourceAnalyzer();
assert analyzer != null;
analyzer.analyse(trees, jt, active, newTypes, newModules, mainMethod);
final Lookup pluginServices = getPluginServices(jt);
for (CompilationUnitTree cu : trees) {
for (JavaIndexerPlugin plugin : getPlugins()) {
plugin.process(cu, active.indexable, pluginServices);
}
}
}
示例10: findDependent
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
private static Map<URL, Set<URL>> findDependent(final URL root, final Collection<ElementHandle<TypeElement>> classes, boolean includeFilesInError) throws IOException {
//get dependencies
Map<URL, List<URL>> deps = IndexingController.getDefault().getRootDependencies();
Map<URL, List<URL>> peers = IndexingController.getDefault().getRootPeers();
//create inverse dependencies
final Map<URL, List<URL>> inverseDeps = new HashMap<URL, List<URL>> ();
for (Map.Entry<URL,List<URL>> entry : deps.entrySet()) {
final URL u1 = entry.getKey();
final List<URL> l1 = entry.getValue();
for (URL u2 : l1) {
List<URL> l2 = inverseDeps.get(u2);
if (l2 == null) {
l2 = new ArrayList<URL>();
inverseDeps.put (u2,l2);
}
l2.add (u1);
}
}
return findDependent(root, deps, inverseDeps, peers, classes, includeFilesInError, true);
}
示例11: 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;
}
}
示例12: addOccurrences
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
public void addOccurrences(List<Occurrence> result) throws BadLocationException {
Collection<ElementHandle<ExecutableElement>> methodHandles = renamedProperty.getMethodHandles();
Collection<ExecutableElement> methods = JavaUtils.getMethodsFromHandles(cc, methodHandles);
List<SpringBean> beans = docAccess.getSpringBeans().getFileBeans(docAccess.getFileObject()).getBeans();
for (SpringBean bean : beans) {
Set<SpringBeanProperty> properties = bean.getProperties();
if (properties.isEmpty()) {
continue;
}
// resolve bean's class
String className = new BeanClassFinder(bean, docAccess.getFileObject()).findImplementationClass(false);
if (className == null) {
continue;
}
TypeElement beanTypeElement = JavaUtils.findClassElementByBinaryName(className, cc);
if (beanTypeElement == null) {
continue;
}
for (SpringBeanProperty property : properties) {
processPropertyOccurrence(property, bean, beanTypeElement, methods, result);
}
}
}
示例13: 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;
}
示例14: findMethod
import org.netbeans.api.java.source.ElementHandle; //导入依赖的package包/类
@NbBundle.Messages("JavaUtils.title.method.searching=Searching Method")
public static ElementHandle<ExecutableElement> findMethod(FileObject fileObject, final String classBinName,
final String methodName, int argCount, Public publicFlag, Static staticFlag) {
JavaSource js = JavaUtils.getJavaSource(fileObject);
if (js != null) {
MethodFinder methodFinder = new MethodFinder(js, classBinName, methodName, argCount, publicFlag, staticFlag);
methodFinder.runAsUserTask();
if (methodFinder.getMethodHandle() == null && SourceUtils.isScanInProgress()) {
if (!ScanDialog.runWhenScanFinished(methodFinder, Bundle.JavaUtils_title_method_searching())) {
return methodFinder.getMethodHandle();
} else {
return null;
}
} else {
return methodFinder.getMethodHandle();
}
}
return null;
}
示例15: findSource
import org.netbeans.api.java.source.ElementHandle; //导入依赖的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));
}