Java 类com.intellij.psi.util.proximity.ReferenceListWeigher 实例源码

项目:consulo-java    文件:JavaCompletionUtil.java   
private static boolean shouldMarkRed(@NotNull Object object, @NotNull PsiElement place)
{
    if(!(object instanceof PsiMember))
    {
        return false;
    }
    if(Java15APIUsageInspectionBase.isForbiddenApiUsage((PsiMember) object, PsiUtil.getLanguageLevel(place)))
    {
        return true;
    }

    if(object instanceof PsiEnumConstant)
    {
        return findConstantsUsedInSwitch(place).contains(CompletionUtil.getOriginalOrSelf((PsiEnumConstant) object));
    }
    if(object instanceof PsiClass && ReferenceListWeigher.INSTANCE.getApplicability((PsiClass) object, place) == inapplicable)
    {
        return true;
    }
    return false;
}
项目:consulo-java    文件:JavaSmartCompletionContributor.java   
@Nullable
private static ElementFilter getClassReferenceFilter(final PsiElement element, final boolean inRefList)
{
    //throw new foo
    if(AFTER_THROW_NEW.accepts(element))
    {
        return THROWABLES_FILTER;
    }

    //new xxx.yyy
    if(psiElement().afterLeaf(psiElement().withText(".")).withSuperParent(2, psiElement(PsiNewExpression.class)).accepts(element))
    {
        if(((PsiNewExpression) element.getParent().getParent()).getClassReference() == element.getParent())
        {
            PsiType[] types = ExpectedTypesGetter.getExpectedTypes(element, false);
            return new OrFilter(ContainerUtil.map2Array(types, ElementFilter.class, (Function<PsiType, ElementFilter>) type -> new AssignableFromFilter(type)));
        }
    }

    // extends/implements/throws
    if(inRefList)
    {
        return new ElementExtractorFilter(new ElementFilter()
        {
            @Override
            public boolean isAcceptable(Object aClass, @Nullable PsiElement context)
            {
                return aClass instanceof PsiClass && ReferenceListWeigher.INSTANCE.getApplicability((PsiClass) aClass, element) != ReferenceListWeigher.ReferenceListApplicability.inapplicable;
            }

            @Override
            public boolean isClassAcceptable(Class hintClass)
            {
                return true;
            }
        });
    }

    return null;
}