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 (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_ITERABLE)) { return false; } return !ErrorUtil.containsError(foreachStatement); }