boolean (@NotNull final PsiCall callExpression, @NotNull final PsiExpression @NotNull [] arrayElements) { @NotNull final PsiMethod oldRefMethod = Objects.requireNonNull(callExpression.resolveMethod()); if (arrayElements.length == 1) { PsiType type = arrayElements[0].getType(); // change foo(new Object[]{array}) to foo(array) is not safe if (PsiTypes.nullType().equals(type) || type instanceof PsiArrayType) return false; } PsiCall copy = (PsiCall)callExpression.copy(); PsiExpressionList copyArgumentList = copy.getArgumentList(); LOG.assertTrue(copyArgumentList != null); PsiExpression[] args = copyArgumentList.getExpressions(); try { args[args.length - 1].delete(); if (arrayElements.length > 0) { copyArgumentList.addRange(arrayElements[0], arrayElements[arrayElements.length - 1]); } final Project project = callExpression.getProject(); final JavaResolveResult resolveResult; if (callExpression instanceof PsiEnumConstant enumConstant) { final PsiClass containingClass = enumConstant.getContainingClass(); if (containingClass == null) return false; final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final PsiClassType classType = facade.getElementFactory().createType(containingClass); resolveResult = facade.getResolveHelper().resolveConstructor(classType, copyArgumentList, enumConstant); return resolveResult.isValidResult() && resolveResult.getElement() == oldRefMethod; } else { resolveResult = copy.resolveMethodGenerics(); if (!resolveResult.isValidResult() || resolveResult.getElement() != oldRefMethod) { return false; } if (callExpression.getParent() instanceof PsiExpressionStatement) return true; final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes((PsiCallExpression)callExpression, false); if (expectedTypes.length == 0) return false; final PsiType expressionType = ((PsiCallExpression)copy).getType(); if (expressionType == null) return false; for (ExpectedTypeInfo expectedType : expectedTypes) { if (expectedType.getType().isAssignableFrom(expressionType)) { return true; } } return false; } } catch (IncorrectOperationException e) { return false; } }