From 56e2ab354d8254437b6bcb5a9b056a2d2f1dbbcf Mon Sep 17 00:00:00 2001 From: Nikita Eshkeev Date: Fri, 10 Apr 2020 11:47:30 +0300 Subject: [PATCH] [codeInsight][cleanup] IDEA-153125 Create inspection to match the intention "Insert underscores into literal" This patch cleans up the code according to the code review. The changes include: 1. Renamig insert underscores into numeric literals inspection 2. Silently exiting ConvertNumericLiteralQuickFix#applyFix if there is no PsiElement found in ProblemDescriptor 3. Grammar cleanup Signed-off-by: Nikita Eshkeev GitOrigin-RevId: 3f913dd73fb11b8735a3505091a9ea87238eac4f --- .../numeric/ConvertNumericLiteralQuickFix.java | 7 +------ .../inspectionDescriptions/InsertLiteralUnderscores.html | 4 ++-- .../inspectionDescriptions/RemoveLiteralUnderscores.html | 4 ++-- .../underscoresInLiterals/afterInsertUnderscores.java | 2 +- .../underscoresInLiterals/beforeInsertUnderscores.java | 2 +- java/openapi/resources/messages/JavaBundle.properties | 2 +- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/numeric/ConvertNumericLiteralQuickFix.java b/java/java-impl/src/com/intellij/codeInspection/numeric/ConvertNumericLiteralQuickFix.java index b9fabc19557b..cf204d4a78f8 100644 --- a/java/java-impl/src/com/intellij/codeInspection/numeric/ConvertNumericLiteralQuickFix.java +++ b/java/java-impl/src/com/intellij/codeInspection/numeric/ConvertNumericLiteralQuickFix.java @@ -21,8 +21,6 @@ import org.jetbrains.annotations.NotNull; */ final class ConvertNumericLiteralQuickFix implements LocalQuickFix { - private static final Logger LOGGER = Logger.getInstance(ConvertNumericLiteralQuickFix.class); - @NotNull private final String myConvertedValue; @NotNull @Nls(capitalization = Nls.Capitalization.Sentence) private final String myName; @NotNull private @NlsContexts.ListItem final String myFamilyName; @@ -49,10 +47,7 @@ final class ConvertNumericLiteralQuickFix implements LocalQuickFix { public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); - if (element == null) { - LOGGER.error("Problem descriptor cannot be without PsiElement"); - return; - } + if (element == null) return; final PsiExpression replacement = JavaPsiFacade.getElementFactory(project).createExpressionFromText(myConvertedValue, null); element.replace(replacement); diff --git a/java/java-impl/src/inspectionDescriptions/InsertLiteralUnderscores.html b/java/java-impl/src/inspectionDescriptions/InsertLiteralUnderscores.html index 86989db4819c..42afa71f9216 100644 --- a/java/java-impl/src/inspectionDescriptions/InsertLiteralUnderscores.html +++ b/java/java-impl/src/inspectionDescriptions/InsertLiteralUnderscores.html @@ -1,9 +1,9 @@ -Reports numeric literals without underscores which may be hard to read due to their length +Reports numeric literals without underscores that may be hard to read due to their length

This inspection only reports if the language level of the project or module is 7 or higher

Quick fix: adds underscores into numeric literals. E.g. 1000000 will be converted to 1_000_000.

-

New in 2020.2 +

New in 2020.2

diff --git a/java/java-impl/src/inspectionDescriptions/RemoveLiteralUnderscores.html b/java/java-impl/src/inspectionDescriptions/RemoveLiteralUnderscores.html index a76ce136e5b6..7abeb192dbe7 100644 --- a/java/java-impl/src/inspectionDescriptions/RemoveLiteralUnderscores.html +++ b/java/java-impl/src/inspectionDescriptions/RemoveLiteralUnderscores.html @@ -1,9 +1,9 @@ -Reports numeric literals with underscores, so they could be removed using a quick-fix +Reports numeric literals with underscores so they can be removed using a quick-fix

This inspection only reports if the language level of the project or module is 7 or higher

Quick fix: removes underscores from numeric literals. E.g. 1_000_000 will be converted to 1000000.

-

New in 2020.2 +

New in 2020.2

\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/underscoresInLiterals/afterInsertUnderscores.java b/java/java-tests/testData/codeInsight/underscoresInLiterals/afterInsertUnderscores.java index f933f0ba3b09..e66a04121b8e 100644 --- a/java/java-tests/testData/codeInsight/underscoresInLiterals/afterInsertUnderscores.java +++ b/java/java-tests/testData/codeInsight/underscoresInLiterals/afterInsertUnderscores.java @@ -1,4 +1,4 @@ -// "Fix all 'No underscores in numeric literal' problems in file" "true" +// "Fix all 'Unreadable numeric literal' problems in file" "true" class C { int c = 299_792_000; diff --git a/java/java-tests/testData/codeInsight/underscoresInLiterals/beforeInsertUnderscores.java b/java/java-tests/testData/codeInsight/underscoresInLiterals/beforeInsertUnderscores.java index f284f25bc638..66e8e9eee542 100644 --- a/java/java-tests/testData/codeInsight/underscoresInLiterals/beforeInsertUnderscores.java +++ b/java/java-tests/testData/codeInsight/underscoresInLiterals/beforeInsertUnderscores.java @@ -1,4 +1,4 @@ -// "Fix all 'No underscores in numeric literal' problems in file" "true" +// "Fix all 'Unreadable numeric literal' problems in file" "true" class C { int c = 299792000; diff --git a/java/openapi/resources/messages/JavaBundle.properties b/java/openapi/resources/messages/JavaBundle.properties index 7c5fd8002327..1ccaff48d687 100644 --- a/java/openapi/resources/messages/JavaBundle.properties +++ b/java/openapi/resources/messages/JavaBundle.properties @@ -449,7 +449,7 @@ inspection.handle.signature.use.method.fix.family.name=Use one of method overloa inspection.handle.signature.use.method.fix.name=Use method ''{0}'' inspection.idempotent.loop.body=Idempotent loop body inspection.illegal.character=Illegal character -inspection.insert.literal.underscores.display.name=No underscores in numeric literal +inspection.insert.literal.underscores.display.name=Unreadable numeric literal inspection.insert.literal.underscores.family.name=Insert underscores into numeric literal inspection.javadoc.dialog.title=Edit Additional Javadoc Tags inspection.javadoc.display.name=Declaration has Javadoc problems