PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { if (PsiDiamondTypeUtil.canCollapseToDiamond(expression, expression, null)) { final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference(); LOG.assertTrue(classReference != null); final PsiReferenceParameterList parameterList = classReference.getParameterList(); LOG.assertTrue(parameterList != null); for (PsiTypeElement typeElement : parameterList.getTypeParameterElements()) { if (typeElement.getAnnotations().length > 0) { return; } } final PsiElement firstChild = parameterList.getFirstChild(); final PsiElement lastChild = parameterList.getLastChild(); final TextRange range = new TextRange(firstChild != null && firstChild.getNode().getElementType() == JavaTokenType.LT ? 1 : 0, parameterList.getTextLength() - (lastChild != null && lastChild.getNode().getElementType() == JavaTokenType.GT ? 1 : 0)); holder.registerProblem(parameterList, range, JavaAnalysisBundle.message("explicit.type.argument.ref.loc.can.be.replaced.with"), new ReplaceWithDiamondFix()); } } }; }