@Nullable private static ElementFilter getReferenceFilter(PsiElement element) { //throw new foo if (AFTER_THROW_NEW.accepts(element)) { return new ElementExtractorFilter(THROWABLE_TYPE_FILTER); } //new xxx.yyy if (psiElement().afterLeaf(psiElement().withText(".")).withSuperParent(2, psiElement(PsiNewExpression.class)).accepts(element)) { if (((PsiNewExpression)element.getParent().getParent()).getClassReference() == element.getParent()) { return new GeneratorFilter(AssignableGroupFilter.class, new ExpectedTypesGetter()); } } return null; }
@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; }