boolean (PsiTypeElement typeElement) { final PsiElement ancestor = PsiTreeUtil.skipParentsOfType( typeElement, PsiTypeElement.class, PsiJavaCodeReferenceElement.class, PsiReferenceParameterList.class); if (ancestor instanceof PsiDeconstructionPattern deconstructionPattern) { PsiForeachStatementBase parentForEach = PsiTreeUtil.getParentOfType(deconstructionPattern, PsiForeachStatementBase.class, false, PsiStatement.class); if (parentForEach == null) { return false; } if (ancestor.getParent() instanceof PsiForeachStatementBase foreachStatement) { PsiExpression iteratedValue = foreachStatement.getIteratedValue(); if (iteratedValue == null) { return false; } return isWildcardRequired(typeElement, deconstructionPattern.getTypeElement(), JavaGenericsUtil.getCollectionItemType(iteratedValue)); } else if (deconstructionPattern.getParent() instanceof PsiDeconstructionList) { PsiType type = JavaPsiPatternUtil.getDeconstructedImplicitPatternType(deconstructionPattern); if (type == null) { return false; } return isWildcardRequired(typeElement, deconstructionPattern.getTypeElement(), type); } } else if (ancestor instanceof PsiParameter parameter) { final PsiElement scope = parameter.getDeclarationScope(); if (scope instanceof PsiMethod method) { if (MethodUtils.hasSuper(method)) { return true; } } else if (scope instanceof PsiLambdaExpression) { return true; } else if (scope instanceof PsiForeachStatementBase foreachStatement) { final PsiExpression iteratedValue = foreachStatement.getIteratedValue(); if (iteratedValue == null) { return true; // incomplete code } if (scope instanceof PsiForeachStatement normalForeach) { PsiParameter iterationParameter = normalForeach.getIterationParameter(); final PsiTypeElement foreachTypeElement = iterationParameter.getTypeElement(); assert foreachTypeElement != null; return isWildcardRequired(typeElement, foreachTypeElement, JavaGenericsUtil.getCollectionItemType(iteratedValue)); } else if (ancestor instanceof PsiPatternVariable patternVariable) { PsiType type = JavaPsiPatternUtil.getDeconstructedImplicitPatternVariableType(patternVariable); if (type == null) { return true; } return isWildcardRequired(typeElement, patternVariable.getTypeElement(), type); } } } else if (ancestor instanceof PsiLocalVariable localVariable) { final PsiExpression initializer = localVariable.getInitializer(); return initializer != null && isWildcardRequired(typeElement, localVariable.getTypeElement(), initializer.getType()); } return false; }