-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #11: Support transformation to BigDecimal constants
- Loading branch information
Showing
8 changed files
with
526 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...main/java/de/markiewb/netbeans/plugins/hints/bigdecimal/UseBigDecimalConstantsFixONE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.markiewb.netbeans.plugins.hints.bigdecimal; | ||
|
||
import org.netbeans.spi.editor.hints.ErrorDescription; | ||
import org.netbeans.spi.editor.hints.Fix; | ||
import org.netbeans.spi.editor.hints.Severity; | ||
import org.netbeans.spi.java.hints.ErrorDescriptionFactory; | ||
import org.netbeans.spi.java.hints.Hint; | ||
import org.netbeans.spi.java.hints.HintContext; | ||
import org.netbeans.spi.java.hints.TriggerPattern; | ||
import org.netbeans.spi.java.hints.TriggerPatterns; | ||
import org.openide.util.NbBundle.Messages; | ||
|
||
@Messages({ | ||
"ERR_UseBigDecimalConstantsFixONE=Convert to <tt>BigDecimal.ONE</tt>", | ||
"DN_UseBigDecimalConstantsONE=Convert to <tt>BigDecimal.ONE</tt>", | ||
"DESC_UseBigDecimalConstantsONE=Converts expressions like <tt>new java.math.BigDecimal(1)</tt> to <tt>BigDecimal.ONE</tt> ",}) | ||
public class UseBigDecimalConstantsFixONE { | ||
|
||
@Hint(displayName = "#DN_UseBigDecimalConstantsONE", description = "#DESC_UseBigDecimalConstantsONE", category = "Suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT) | ||
@TriggerPatterns( | ||
{ | ||
@TriggerPattern("new java.math.BigDecimal(\"1\")"), | ||
@TriggerPattern("new java.math.BigDecimal(\"1.0\")"), | ||
@TriggerPattern("new java.math.BigDecimal(\"1.00\")"), | ||
@TriggerPattern("new java.math.BigDecimal(1)"), | ||
@TriggerPattern("new java.math.BigDecimal(1L)"), | ||
@TriggerPattern("new java.math.BigDecimal(1f)"), | ||
@TriggerPattern("new java.math.BigDecimal(1.0f)"), | ||
@TriggerPattern("new java.math.BigDecimal(1.00f)"), | ||
@TriggerPattern("new java.math.BigDecimal(1d)"), | ||
@TriggerPattern("new java.math.BigDecimal(1.0d)"), | ||
@TriggerPattern("new java.math.BigDecimal(1.00d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1L)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1.0f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1.00f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1.0d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(1.00d)"),} | ||
) | ||
public static ErrorDescription convertToZero(HintContext ctx) { | ||
|
||
Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBigDecimalConstantsFixONE(), ctx.getPath(), "java.math.BigDecimal.ONE"); | ||
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBigDecimalConstantsFixONE(), fix); | ||
} | ||
|
||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...main/java/de/markiewb/netbeans/plugins/hints/bigdecimal/UseBigDecimalConstantsFixTEN.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.markiewb.netbeans.plugins.hints.bigdecimal; | ||
|
||
import org.netbeans.spi.editor.hints.ErrorDescription; | ||
import org.netbeans.spi.editor.hints.Fix; | ||
import org.netbeans.spi.editor.hints.Severity; | ||
import org.netbeans.spi.java.hints.ErrorDescriptionFactory; | ||
import org.netbeans.spi.java.hints.Hint; | ||
import org.netbeans.spi.java.hints.HintContext; | ||
import org.netbeans.spi.java.hints.TriggerPattern; | ||
import org.netbeans.spi.java.hints.TriggerPatterns; | ||
import org.openide.util.NbBundle.Messages; | ||
|
||
@Messages({ | ||
"ERR_UseBigDecimalConstantsFixTEN=Convert to <tt>BigDecimal.TEN</tt>", | ||
"DN_UseBigDecimalConstantsTEN=Convert to <tt>BigDecimal.TEN</tt>", | ||
"DESC_UseBigDecimalConstantsTEN=Converts expressions like <tt>new java.math.BigDecimal(10)</tt> to <tt>BigDecimal.TEN</tt> ",}) | ||
public class UseBigDecimalConstantsFixTEN { | ||
|
||
@Hint(displayName = "#DN_UseBigDecimalConstantsTEN", description = "#DESC_UseBigDecimalConstantsTEN", category = "Suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT) | ||
@TriggerPatterns( | ||
{ | ||
@TriggerPattern("new java.math.BigDecimal(\"10\")"), | ||
@TriggerPattern("new java.math.BigDecimal(\"10.0\")"), | ||
@TriggerPattern("new java.math.BigDecimal(\"10.00\")"), | ||
@TriggerPattern("new java.math.BigDecimal(10)"), | ||
@TriggerPattern("new java.math.BigDecimal(10L)"), | ||
@TriggerPattern("new java.math.BigDecimal(10f)"), | ||
@TriggerPattern("new java.math.BigDecimal(10.0f)"), | ||
@TriggerPattern("new java.math.BigDecimal(10.00f)"), | ||
@TriggerPattern("new java.math.BigDecimal(10d)"), | ||
@TriggerPattern("new java.math.BigDecimal(10.0d)"), | ||
@TriggerPattern("new java.math.BigDecimal(10.00d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10L)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10.0f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10.00f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10.0d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(10.00d)"),} | ||
) | ||
public static ErrorDescription convertToZero(HintContext ctx) { | ||
|
||
Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBigDecimalConstantsFixTEN(), ctx.getPath(), "java.math.BigDecimal.TEN"); | ||
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBigDecimalConstantsFixTEN(), fix); | ||
} | ||
|
||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...ain/java/de/markiewb/netbeans/plugins/hints/bigdecimal/UseBigDecimalConstantsFixZERO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.markiewb.netbeans.plugins.hints.bigdecimal; | ||
|
||
import org.netbeans.spi.editor.hints.ErrorDescription; | ||
import org.netbeans.spi.editor.hints.Fix; | ||
import org.netbeans.spi.editor.hints.Severity; | ||
import org.netbeans.spi.java.hints.ErrorDescriptionFactory; | ||
import org.netbeans.spi.java.hints.Hint; | ||
import org.netbeans.spi.java.hints.HintContext; | ||
import org.netbeans.spi.java.hints.TriggerPattern; | ||
import org.netbeans.spi.java.hints.TriggerPatterns; | ||
import org.openide.util.NbBundle.Messages; | ||
|
||
@Messages({ | ||
"ERR_UseBigDecimalConstantsFixZERO=Convert to <tt>BigDecimal.ZERO</tt>", | ||
"DN_UseBigDecimalConstantsZERO=Convert to <tt>BigDecimal.ZERO</tt>", | ||
"DESC_UseBigDecimalConstantsZERO=Converts expressions like <tt>new java.math.BigDecimal(0)</tt> to use <tt>BigDecimal.ZERO</tt> ",}) | ||
public class UseBigDecimalConstantsFixZERO { | ||
|
||
@Hint(displayName = "#DN_UseBigDecimalConstantsZERO", description = "#DESC_UseBigDecimalConstantsZERO", category = "Suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT) | ||
@TriggerPatterns( | ||
{ | ||
@TriggerPattern("new java.math.BigDecimal(\"0\")"), | ||
@TriggerPattern("new java.math.BigDecimal(\"0.0\")"), | ||
@TriggerPattern("new java.math.BigDecimal(\"0.00\")"), | ||
@TriggerPattern("new java.math.BigDecimal(0)"), | ||
@TriggerPattern("new java.math.BigDecimal(0L)"), | ||
@TriggerPattern("new java.math.BigDecimal(0f)"), | ||
@TriggerPattern("new java.math.BigDecimal(0.0f)"), | ||
@TriggerPattern("new java.math.BigDecimal(0.00f)"), | ||
@TriggerPattern("new java.math.BigDecimal(0d)"), | ||
@TriggerPattern("new java.math.BigDecimal(0.0d)"), | ||
@TriggerPattern("new java.math.BigDecimal(0.00d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0L)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0.0f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0.00f)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0.0d)"), | ||
@TriggerPattern("java.math.BigDecimal.valueOf(0.00d)"),} | ||
) | ||
public static ErrorDescription convertToZero(HintContext ctx) { | ||
|
||
Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBigDecimalConstantsFixZERO(), ctx.getPath(), "java.math.BigDecimal.ZERO"); | ||
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBigDecimalConstantsFixZERO(), fix); | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
.../java/de/markiewb/netbeans/plugins/hints/bigdecimal/UseBigDecimalConstantsFixONETest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package de.markiewb.netbeans.plugins.hints.bigdecimal; | ||
|
||
import org.junit.Test; | ||
import org.netbeans.modules.java.hints.test.api.HintTest; | ||
|
||
public class UseBigDecimalConstantsFixONETest { | ||
|
||
@Test | ||
public void testConvert_A() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"1\");\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixONE.class) | ||
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBigDecimalConstantsFixONE()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testConvert_B() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"1.0\");\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixONE.class) | ||
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBigDecimalConstantsFixONE()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testConvert_C() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(1.0);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixONE.class) | ||
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBigDecimalConstantsFixONE()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testConvert_D() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(1.00d);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixONE.class) | ||
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBigDecimalConstantsFixONE()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
.../java/de/markiewb/netbeans/plugins/hints/bigdecimal/UseBigDecimalConstantsFixTENTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package de.markiewb.netbeans.plugins.hints.bigdecimal; | ||
|
||
import org.junit.Test; | ||
import org.netbeans.modules.java.hints.test.api.HintTest; | ||
|
||
public class UseBigDecimalConstantsFixTENTest { | ||
|
||
@Test | ||
public void testConvert_A() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"10\");\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixTEN.class) | ||
.findWarning("3:31-3:61:hint:" + Bundle.ERR_UseBigDecimalConstantsFixTEN()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testConvert_B() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"10.0\");\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixTEN.class) | ||
.findWarning("3:31-3:63:hint:" + Bundle.ERR_UseBigDecimalConstantsFixTEN()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testConvert_C() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(10.0);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixTEN.class) | ||
.findWarning("3:31-3:61:hint:" + Bundle.ERR_UseBigDecimalConstantsFixTEN()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testConvert_D() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=new java.math.BigDecimal(10.00d);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.run(UseBigDecimalConstantsFixTEN.class) | ||
.findWarning("3:31-3:63:hint:" + Bundle.ERR_UseBigDecimalConstantsFixTEN()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import java.math.BigDecimal;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
} |
Oops, something went wrong.