question: @ NotNull public PsiQuery filter ( @ NotNull final Class < ? extends PsiNamedElement > clazz , @ NotNull final String name ) { final Set < PsiElement > result = new HashSet < PsiElement > ( Arrays . asList ( myPsiElements ) ) ; for ( final PsiElement element : myPsiElements ) { final PsiNamedElement namedElement = PyUtil . as ( element , clazz ) ; if ( ( namedElement == null ) || ( ! name . equals ( namedElement . getName ( ) ) ) ) { result . remove ( element ) ; } } return new PsiQuery ( result . toArray ( new PsiElement [ result . size ( ) ] ) ) ; }
target:  Filter elements by class and name