From c97b9104a248b29dc4c0a02fb740800f88e83f51 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 20 Jun 2025 15:36:31 +0200 Subject: [PATCH] Java: no highlight, only fix on numeric literals of length 4 (IDEA-261998) GitOrigin-RevId: aea6ef78149c1a2cf6d9bc3e98713c6bb9eb2035 --- .../InsertLiteralUnderscoresInspection.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/numeric/InsertLiteralUnderscoresInspection.java b/java/java-impl-inspections/src/com/intellij/codeInspection/numeric/InsertLiteralUnderscoresInspection.java index e4bdceec6e56..c3ea23881c6f 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/numeric/InsertLiteralUnderscoresInspection.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/numeric/InsertLiteralUnderscoresInspection.java @@ -1,8 +1,9 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInspection.numeric; import com.intellij.codeInspection.CommonQuickFixBundle; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.java.JavaBundle; import com.intellij.pom.java.JavaFeature; @@ -20,13 +21,13 @@ import org.jetbrains.annotations.NotNull; public final class InsertLiteralUnderscoresInspection extends LocalInspectionTool { @Override - public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { + public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!PsiUtil.isAvailable(JavaFeature.UNDERSCORES, holder.getFile())) { return PsiElementVisitor.EMPTY_VISITOR; } return new JavaElementVisitor() { @Override - public void visitLiteralExpression(final @NotNull PsiLiteralExpression literalExpression) { + public void visitLiteralExpression(@NotNull PsiLiteralExpression literalExpression) { final PsiType type = literalExpression.getType(); if (!PsiTypes.intType().equals(type) && !PsiTypes.longType().equals(type) && !PsiTypes.floatType().equals(type) && !PsiTypes.doubleType().equals(type)) return; @@ -35,15 +36,16 @@ public final class InsertLiteralUnderscoresInspection extends LocalInspectionToo if (text == null || text.contains("_")) return; final String converted = LiteralFormatUtil.format(text, type); - if (converted.length() == text.length()) return; + int length = text.length(); + if (converted.length() == length) return; - final String displayMessage = JavaBundle.message("inspection.insert.literal.underscores.display.name"); final String actionText = CommonQuickFixBundle.message("fix.replace.x.with.y", text, converted); final String familyName = JavaBundle.message("inspection.insert.literal.underscores.family.name"); final ConvertNumericLiteralQuickFix quickFix = new ConvertNumericLiteralQuickFix(converted, actionText, familyName); - holder.registerProblem(literalExpression, displayMessage, quickFix); + holder.registerProblem(literalExpression, JavaBundle.message("inspection.insert.literal.underscores.display.name"), + length <= 4 ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickFix); } }; }