Java 类com.intellij.psi.PsiJavaReference 实例源码

项目:intellij-ce-playground    文件:SliceLeafAnalyzer.java   
@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);
}
项目:tools-idea    文件:SliceLeafAnalyzer.java   
@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);
}
项目:consulo-java    文件:JavadocCompletionConfidence.java   
@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;
}
项目:consulo-java    文件:SuperCalls.java   
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;
}
项目:consulo-java    文件:JavaTypeDeclarationProvider.java   
@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};
}
项目:consulo-java    文件:SliceLeafAnalyzer.java   
@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);
}
项目:intellij-ce-playground    文件:ResolveVariable15Test.java   
public void testDuplicateStaticImport() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:intellij-ce-playground    文件:ResolveVariable15Test.java   
public void testRhombExtending() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:tools-idea    文件:ResolveVariable15Test.java   
public void testDuplicateStaticImport() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:tools-idea    文件:ResolveVariable15Test.java   
public void testRhombExtending() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:consulo-java    文件:ResolveVariable15Test.java   
public void testDuplicateStaticImport() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}
项目:consulo-java    文件:ResolveVariable15Test.java   
public void testRhombExtending() throws Exception {
  PsiReference ref = configure();
  final JavaResolveResult result = ((PsiJavaReference)ref).advancedResolve(true);
  PsiElement target = result.getElement();
  assertNotNull(target);
  assertTrue(result.isValidResult());
}