PsiNewExpression (Project project, PsiNewExpression expression, PsiType targetType) { if (targetType instanceof PsiEllipsisType) { PsiArrayInitializerExpression initializer = expression.getArrayInitializer(); if (initializer != null) { PsiExpression[] initializers = initializer.getInitializers(); if (initializers.length != 0) { expression.getParent().addRangeBefore(initializers[0], initializers[initializers.length - 1], expression); } expression.delete(); return null; } } if (targetType != null) { try { final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference(); final PsiType componentType = targetType.getDeepComponentType(); if (classReference != null) { final PsiElement psiElement = targetType.equals(RefactoringChangeUtil.getTypeByExpression(expression)) ? classReference : replaceTypeWithClassReferenceOrKeyword(project, componentType, classReference); final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(psiElement, PsiNewExpression.class); if (!tryToReplaceWithDiamond(newExpression, targetType)) { return newExpression; } } else { final PsiElement typeKeyword = getTypeKeyword(expression); if (typeKeyword != null) { replaceTypeWithClassReferenceOrKeyword(project, componentType, typeKeyword); } } } catch (IncorrectOperationException e) { LOG.error(e); } } return null; }