PsiElement (PsiElement element, Class<?> aClass, boolean strict) { PsiElement scope = strict ? element.getContext() : element; while(scope != null && !aClass.isInstance(scope)){ scope = scope.getContext(); } return scope; }