PsiExpression (@NotNull PsiElement element, final boolean ignoreEqualsMethod, boolean forceIgnoreTypeCast) { if (!(element instanceof PsiNewExpression newExpression)) { return null; } final PsiAnonymousClass anonymousClass = newExpression.getAnonymousClass(); if (anonymousClass == null) return null; final PsiMethod method; if (ignoreEqualsMethod) { final List<PsiMethod> methods = ContainerUtil.filter(anonymousClass.getMethods(), method1 -> !"equals".equals(method1.getName())); method = methods.get(0); } else { method = anonymousClass.getMethods()[0]; } if (method == null || method.getBody() == null) return null; return generateLambdaByMethod(anonymousClass, method, lambda -> (PsiLambdaExpression)newExpression.replace(lambda), forceIgnoreTypeCast); }