[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 <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 3f913dd73fb11b8735a3505091a9ea87238eac4f
This commit is contained in:
Nikita Eshkeev
2020-04-10 10:04:03 +00:00
committed by intellij-monorepo-bot
parent 05ecffb3cf
commit 56e2ab354d
6 changed files with 8 additions and 13 deletions
@@ -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);
@@ -1,9 +1,9 @@
<html>
<body>
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
<p>This inspection only reports if the language level of the project or module is 7 or higher</p>
<!-- tooltip end -->
<p>Quick fix: adds underscores into numeric literals. E.g. 1000000 will be converted to 1_000_000.</p>
<p><small>New in 2020.2</small>
<p><small>New in 2020.2</small></p>
</body>
</html>
@@ -1,9 +1,9 @@
<html>
<body>
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
<p>This inspection only reports if the language level of the project or module is 7 or higher</p>
<!-- tooltip end -->
<p>Quick fix: removes underscores from numeric literals. E.g. 1_000_000 will be converted to 1000000.</p>
<p><small>New in 2020.2</small>
<p><small>New in 2020.2</small></p>
</body>
</html>
@@ -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;
@@ -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 = <caret>299792000;
@@ -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