@Override public int computeHashCode(final PsiElement element) { if (element == null) return 0; String text = ApplicationManager.getApplication().runReadAction(new Computable<String>() { @Override public String compute() { PsiElement elementToCompare = element; if (element instanceof PsiJavaReference) { PsiElement resolved = ((PsiJavaReference)element).resolve(); if (resolved != null) { elementToCompare = resolved; } } return elementToCompare instanceof PsiNamedElement ? ((PsiNamedElement)elementToCompare).getName() : AstBufferUtil.getTextSkippingWhitespaceComments(elementToCompare.getNode()); } }); return Comparing.hashcode(text); }
@Nullable private static PsiJavaReference findJavaReference(final PsiFile file, final int offset) { PsiReference reference = file.findReferenceAt(offset); if(reference instanceof PsiMultiReference) { for(final PsiReference psiReference : ((PsiMultiReference) reference).getReferences()) { if(psiReference instanceof PsiJavaReference) { return (PsiJavaReference) psiReference; } } } return reference instanceof PsiJavaReference ? (PsiJavaReference) reference : null; }
static Set<LookupElement> suggestQualifyingSuperCalls(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter, JavaCompletionProcessor.Options options, Condition<String> nameCondition) { Set<LookupElement> set = ContainerUtil.newLinkedHashSet(); for(final String className : getContainingClassNames(element)) { PsiReferenceExpression fakeSuper = JavaCompletionUtil.createReference(className + ".super.rulez", element); PsiElement leaf = ObjectUtils.assertNotNull(fakeSuper.getReferenceNameElement()); JavaCompletionProcessor superProcessor = new JavaCompletionProcessor(leaf, elementFilter, options, nameCondition); fakeSuper.processVariants(superProcessor); for(CompletionElement completionElement : superProcessor.getResults()) { for(LookupElement item : JavaCompletionUtil.createLookupElements(completionElement, javaReference)) { set.add(withQualifiedSuper(className, item)); } } } return set; }
@RequiredReadAction @Nullable @Override public PsiElement[] getSymbolTypeDeclarations(@NotNull PsiElement targetElement, Editor editor, int offset) { PsiType type; if (targetElement instanceof PsiVariable){ type = ((PsiVariable)targetElement).getType(); } else if (targetElement instanceof PsiMethod){ type = ((PsiMethod)targetElement).getReturnType(); } else{ return null; } if (type == null) return null; if (editor != null) { final PsiReference reference = TargetElementUtil.findReference(editor, offset); if (reference instanceof PsiJavaReference) { final JavaResolveResult resolveResult = ((PsiJavaReference)reference).advancedResolve(true); type = resolveResult.getSubstitutor().substitute(type); } } PsiClass psiClass = PsiUtil.resolveClassInType(type); return psiClass == null ? null : new PsiElement[] {psiClass}; }
public void testDuplicateStaticImport() throws Exception { PsiReference ref = configure(); final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true); PsiElement target = result.getElement(); assertNotNull(target); assertTrue(result.isValidResult()); }
public void testRhombExtending() throws Exception { PsiReference ref = configure(); final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true); PsiElement target = result.getElement(); assertNotNull(target); assertTrue(result.isValidResult()); }