boolean (PsiElement element) { if (!(element instanceof PsiJavaToken token)) { return false; } final IElementType tokenType = token.getTokenType(); if (!JavaTokenType.FOR_KEYWORD.equals(tokenType)) { return false; } final PsiElement parent = element.getParent(); if (!(parent instanceof PsiForeachStatement foreachStatement)) { return false; } final PsiExpression iteratedValue = foreachStatement.getIteratedValue(); if (iteratedValue == null) { return false; } final PsiType type = iteratedValue.getType(); if (!(type instanceof PsiArrayType)) { final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(type); if (aClass == null) { return false; } final Project project = element.getProject(); final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); final PsiClass listInterface = psiFacade.findClass(CommonClassNames.JAVA_UTIL_LIST, GlobalSearchScope.allScope(project)); if (listInterface == null || !InheritanceUtil.isInheritorOrSelf(aClass, listInterface, true)) { return false; } } return !ErrorUtil.containsError(parent); }