PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { if (expression.getAnonymousClass() != null || expression.isArrayCreation() || expression.getArgumentList() == null || !expression.getArgumentList().isEmpty()) { return; } PsiJavaCodeReferenceElement reference = expression.getClassReference(); if (reference == null) return; String qualifiedName = reference.getQualifiedName(); if (!COLLECTIONS.contains(qualifiedName)) return; PsiClassType type = ObjectUtils.tryCast(expression.getType(), PsiClassType.class); if (type == null || type.isRaw()) return; PsiType elementType = ArrayUtil.getFirstElement(type.getParameters()); if (elementType == null || TypeUtils.isJavaLangObject(elementType)) return; ModCommandAction fix = null; if (elementType instanceof PsiClassType && ((PsiClassType)elementType).resolve() instanceof PsiTypeParameter) { if (IGNORE_TYPE_PARAMETERS) return; String message = JavaBundle.message("inspection.sorted.collection.with.non.comparable.keys.option.type.parameters"); fix = new UpdateInspectionOptionFix(SortedCollectionWithNonComparableKeysInspection.this, "IGNORE_TYPE_PARAMETERS", message, true); } if (InheritanceUtil.isInheritor(elementType, CommonClassNames.JAVA_LANG_COMPARABLE)) return; holder.problem(expression, JavaBundle.message("inspection.sorted.collection.with.non.comparable.keys.message")) .maybeFix(fix).register(); } }; }