Skip to content

Commit

Permalink
issue #11: Support transformation to BigDecimal constants - fix too l…
Browse files Browse the repository at this point in the history
…ong key exception

* update some descriptions (remove html-tags)
* update category
  • Loading branch information
markiewb committed Nov 7, 2013
1 parent ad32951 commit b1fd71e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.openide.util.NbBundle.Messages;

@Messages({
"ERR_UseBigDecimalConstantsFixONE=Convert to <tt>BigDecimal.ONE</tt>",
"DN_UseBigDecimalConstantsONE=Convert to <tt>BigDecimal.ONE</tt>",
"ERR_UseBDConstFixONE=Convert to BigDecimal.ONE",
"DN_UseBigDecimalConstantsONE=Convert to BigDecimal.ONE",
"DESC_UseBigDecimalConstantsONE=Converts expressions like <tt>new java.math.BigDecimal(1)</tt> to <tt>BigDecimal.ONE</tt> ",})
public class UseBigDecimalConstantsFixONE {
public class UseBDConstFixONE {

@Hint(displayName = "#DN_UseBigDecimalConstantsONE", description = "#DESC_UseBigDecimalConstantsONE", category = "Suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@Hint(displayName = "#DN_UseBigDecimalConstantsONE", description = "#DESC_UseBigDecimalConstantsONE", category = "suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@TriggerPatterns(
{
@TriggerPattern("new java.math.BigDecimal(\"1\")"),
Expand All @@ -39,10 +39,10 @@ public class UseBigDecimalConstantsFixONE {
@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);
public static ErrorDescription convert(HintContext ctx) {
//de.markiewb.netbeans.plugins.hints.bigdecimal.UseBDConstFixTEN.convert
Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBDConstFixONE(), ctx.getPath(), "java.math.BigDecimal.ONE");
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBDConstFixONE(), fix);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.openide.util.NbBundle.Messages;

@Messages({
"ERR_UseBigDecimalConstantsFixTEN=Convert to <tt>BigDecimal.TEN</tt>",
"DN_UseBigDecimalConstantsTEN=Convert to <tt>BigDecimal.TEN</tt>",
"ERR_UseBDConstFixTEN=Convert to BigDecimal.TEN",
"DN_UseBigDecimalConstantsTEN=Convert to BigDecimal.TEN",
"DESC_UseBigDecimalConstantsTEN=Converts expressions like <tt>new java.math.BigDecimal(10)</tt> to <tt>BigDecimal.TEN</tt> ",})
public class UseBigDecimalConstantsFixTEN {
public class UseBDConstFixTEN {

@Hint(displayName = "#DN_UseBigDecimalConstantsTEN", description = "#DESC_UseBigDecimalConstantsTEN", category = "Suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@Hint(displayName = "#DN_UseBigDecimalConstantsTEN", description = "#DESC_UseBigDecimalConstantsTEN", category = "suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@TriggerPatterns(
{
@TriggerPattern("new java.math.BigDecimal(\"10\")"),
Expand All @@ -39,10 +39,10 @@ public class UseBigDecimalConstantsFixTEN {
@TriggerPattern("java.math.BigDecimal.valueOf(10.0d)"),
@TriggerPattern("java.math.BigDecimal.valueOf(10.00d)"),}
)
public static ErrorDescription convertToZero(HintContext ctx) {
public static ErrorDescription convert(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);
Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBDConstFixTEN(), ctx.getPath(), "java.math.BigDecimal.TEN");
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBDConstFixTEN(), fix);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.openide.util.NbBundle.Messages;

@Messages({
"ERR_UseBigDecimalConstantsFixZERO=Convert to <tt>BigDecimal.ZERO</tt>",
"DN_UseBigDecimalConstantsZERO=Convert to <tt>BigDecimal.ZERO</tt>",
"ERR_UseBDConstFixZERO=Convert to BigDecimal.ZERO",
"DN_UseBigDecimalConstantsZERO=Convert to BigDecimal.ZERO",
"DESC_UseBigDecimalConstantsZERO=Converts expressions like <tt>new java.math.BigDecimal(0)</tt> to use <tt>BigDecimal.ZERO</tt> ",})
public class UseBigDecimalConstantsFixZERO {
public class UseBDConstFixZERO {

@Hint(displayName = "#DN_UseBigDecimalConstantsZERO", description = "#DESC_UseBigDecimalConstantsZERO", category = "Suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@Hint(displayName = "#DN_UseBigDecimalConstantsZERO", description = "#DESC_UseBigDecimalConstantsZERO", category = "suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
@TriggerPatterns(
{
@TriggerPattern("new java.math.BigDecimal(\"0\")"),
Expand All @@ -39,10 +39,10 @@ public class UseBigDecimalConstantsFixZERO {
@TriggerPattern("java.math.BigDecimal.valueOf(0.0d)"),
@TriggerPattern("java.math.BigDecimal.valueOf(0.00d)"),}
)
public static ErrorDescription convertToZero(HintContext ctx) {
public static ErrorDescription convert(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);
Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBDConstFixZERO(), ctx.getPath(), "java.math.BigDecimal.ZERO");
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBDConstFixZERO(), fix);
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* 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 {
public class UseBDConstFixONETest {

@Test
public void testConvert_A() throws Exception {
Expand All @@ -19,8 +14,8 @@ public void testConvert_A() throws Exception {
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"1\");\n"
+ " }\n"
+ "}\n")
.run(UseBigDecimalConstantsFixONE.class)
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBigDecimalConstantsFixONE())
.run(UseBDConstFixONE.class)
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixONE())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -41,8 +36,8 @@ public void testConvert_B() throws Exception {
+ " 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())
.run(UseBDConstFixONE.class)
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixONE())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -63,8 +58,8 @@ public void testConvert_C() throws Exception {
+ " 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())
.run(UseBDConstFixONE.class)
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixONE())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -85,8 +80,8 @@ public void testConvert_D() throws Exception {
+ " 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())
.run(UseBDConstFixONE.class)
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixONE())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* 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 {
public class UseBDConstFixTENTest {

@Test
public void testConvert_A() throws Exception {
Expand All @@ -19,8 +14,8 @@ public void testConvert_A() throws Exception {
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"10\");\n"
+ " }\n"
+ "}\n")
.run(UseBigDecimalConstantsFixTEN.class)
.findWarning("3:31-3:61:hint:" + Bundle.ERR_UseBigDecimalConstantsFixTEN())
.run(UseBDConstFixTEN.class)
.findWarning("3:31-3:61:hint:" + Bundle.ERR_UseBDConstFixTEN())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -41,8 +36,8 @@ public void testConvert_B() throws Exception {
+ " 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())
.run(UseBDConstFixTEN.class)
.findWarning("3:31-3:63:hint:" + Bundle.ERR_UseBDConstFixTEN())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -63,8 +58,8 @@ public void testConvert_C() throws Exception {
+ " 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())
.run(UseBDConstFixTEN.class)
.findWarning("3:31-3:61:hint:" + Bundle.ERR_UseBDConstFixTEN())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -85,8 +80,8 @@ public void testConvert_D() throws Exception {
+ " 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())
.run(UseBDConstFixTEN.class)
.findWarning("3:31-3:63:hint:" + Bundle.ERR_UseBDConstFixTEN())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* 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 UseBigDecimalConstantsFixZEROTest {
public class UseBDConstFixZEROTest {

@Test
public void testConvert_A() throws Exception {
Expand All @@ -19,8 +14,8 @@ public void testConvert_A() throws Exception {
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"0\");\n"
+ " }\n"
+ "}\n")
.run(UseBigDecimalConstantsFixZERO.class)
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBigDecimalConstantsFixZERO())
.run(UseBDConstFixZERO.class)
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixZERO())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -41,8 +36,8 @@ public void testConvert_B() throws Exception {
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"0.0\");\n"
+ " }\n"
+ "}\n")
.run(UseBigDecimalConstantsFixZERO.class)
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBigDecimalConstantsFixZERO())
.run(UseBDConstFixZERO.class)
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixZERO())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -63,8 +58,8 @@ public void testConvert_C() throws Exception {
+ " java.math.BigDecimal a=new java.math.BigDecimal(0.0);\n"
+ " }\n"
+ "}\n")
.run(UseBigDecimalConstantsFixZERO.class)
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBigDecimalConstantsFixZERO())
.run(UseBDConstFixZERO.class)
.findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixZERO())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand All @@ -85,8 +80,8 @@ public void testConvert_D() throws Exception {
+ " java.math.BigDecimal a=new java.math.BigDecimal(0.00d);\n"
+ " }\n"
+ "}\n")
.run(UseBigDecimalConstantsFixZERO.class)
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBigDecimalConstantsFixZERO())
.run(UseBDConstFixZERO.class)
.findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixZERO())
.applyFix()
.assertCompilable()
.assertOutput("package test;\n"
Expand Down

0 comments on commit b1fd71e

Please sign in to comment.