This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 236244
Collapse All | Expand All

(-)java.hints/src/org/netbeans/modules/java/hints/suggestions/UseBDConstFixONE.java (+91 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.suggestions;
43
44
import org.netbeans.spi.editor.hints.ErrorDescription;
45
import org.netbeans.spi.editor.hints.Fix;
46
import org.netbeans.spi.editor.hints.Severity;
47
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
48
import org.netbeans.spi.java.hints.Hint;
49
import org.netbeans.spi.java.hints.HintContext;
50
import org.netbeans.spi.java.hints.TriggerPattern;
51
import org.netbeans.spi.java.hints.TriggerPatterns;
52
import org.openide.util.NbBundle.Messages;
53
54
@Messages({
55
    "ERR_UseBDConstFixONE=Convert to BigDecimal.ONE",
56
    "DN_UseBigDecimalConstantsONE=Convert to BigDecimal.ONE",
57
    "DESC_UseBigDecimalConstantsONE=Converts expressions like <tt>new java.math.BigDecimal(1)</tt> to <tt>BigDecimal.ONE</tt>",})
58
/**
59
 * @author markiewb
60
 */
61
public class UseBDConstFixONE {
62
63
    @Hint(displayName = "#DN_UseBigDecimalConstantsONE", description = "#DESC_UseBigDecimalConstantsONE", category = "suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
64
    @TriggerPatterns(
65
            {
66
                @TriggerPattern("new java.math.BigDecimal(\"1\")"),
67
                @TriggerPattern("new java.math.BigDecimal(\"1.0\")"),
68
                @TriggerPattern("new java.math.BigDecimal(\"1.00\")"),
69
                @TriggerPattern("new java.math.BigDecimal(1)"),
70
                @TriggerPattern("new java.math.BigDecimal(1L)"),
71
                @TriggerPattern("new java.math.BigDecimal(1f)"),
72
                @TriggerPattern("new java.math.BigDecimal(1.0f)"),
73
                @TriggerPattern("new java.math.BigDecimal(1.00f)"),
74
                @TriggerPattern("new java.math.BigDecimal(1d)"),
75
                @TriggerPattern("new java.math.BigDecimal(1.0d)"),
76
                @TriggerPattern("new java.math.BigDecimal(1.00d)"),
77
                @TriggerPattern("java.math.BigDecimal.valueOf(1)"),
78
                @TriggerPattern("java.math.BigDecimal.valueOf(1L)"),
79
                @TriggerPattern("java.math.BigDecimal.valueOf(1f)"),
80
                @TriggerPattern("java.math.BigDecimal.valueOf(1.0f)"),
81
                @TriggerPattern("java.math.BigDecimal.valueOf(1.00f)"),
82
                @TriggerPattern("java.math.BigDecimal.valueOf(1d)"),
83
                @TriggerPattern("java.math.BigDecimal.valueOf(1.0d)"),
84
                @TriggerPattern("java.math.BigDecimal.valueOf(1.00d)"),}
85
    )
86
    public static ErrorDescription convert(HintContext ctx) {
87
        Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBDConstFixONE(), ctx.getPath(), "java.math.BigDecimal.ONE");
88
        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBDConstFixONE(), fix);
89
    }
90
91
}
(-)java.hints/src/org/netbeans/modules/java/hints/suggestions/UseBDConstFixTEN.java (+93 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.suggestions;
43
44
import org.netbeans.spi.editor.hints.ErrorDescription;
45
import org.netbeans.spi.editor.hints.Fix;
46
import org.netbeans.spi.editor.hints.Severity;
47
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
48
import org.netbeans.spi.java.hints.Hint;
49
import org.netbeans.spi.java.hints.HintContext;
50
import org.netbeans.spi.java.hints.TriggerPattern;
51
import org.netbeans.spi.java.hints.TriggerPatterns;
52
import org.openide.util.NbBundle.Messages;
53
54
@Messages({
55
    "ERR_UseBDConstFixTEN=Convert to BigDecimal.TEN",
56
    "DN_UseBigDecimalConstantsTEN=Convert to BigDecimal.TEN",
57
    "DESC_UseBigDecimalConstantsTEN=Converts expressions like <tt>new java.math.BigDecimal(10)</tt> to <tt>BigDecimal.TEN</tt>",})
58
/**
59
 * @author markiewb
60
 */
61
public class UseBDConstFixTEN {
62
63
    @Hint(displayName = "#DN_UseBigDecimalConstantsTEN", description = "#DESC_UseBigDecimalConstantsTEN", category = "suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
64
    @TriggerPatterns(
65
            {
66
                @TriggerPattern("new java.math.BigDecimal(\"10\")"),
67
                @TriggerPattern("new java.math.BigDecimal(\"10.0\")"),
68
                @TriggerPattern("new java.math.BigDecimal(\"10.00\")"),
69
                @TriggerPattern("new java.math.BigDecimal(10)"),
70
                @TriggerPattern("new java.math.BigDecimal(10L)"),
71
                @TriggerPattern("new java.math.BigDecimal(10f)"),
72
                @TriggerPattern("new java.math.BigDecimal(10.0f)"),
73
                @TriggerPattern("new java.math.BigDecimal(10.00f)"),
74
                @TriggerPattern("new java.math.BigDecimal(10d)"),
75
                @TriggerPattern("new java.math.BigDecimal(10.0d)"),
76
                @TriggerPattern("new java.math.BigDecimal(10.00d)"),
77
                @TriggerPattern("java.math.BigDecimal.valueOf(10)"),
78
                @TriggerPattern("java.math.BigDecimal.valueOf(10L)"),
79
                @TriggerPattern("java.math.BigDecimal.valueOf(10f)"),
80
                @TriggerPattern("java.math.BigDecimal.valueOf(10.0f)"),
81
                @TriggerPattern("java.math.BigDecimal.valueOf(10.00f)"),
82
                @TriggerPattern("java.math.BigDecimal.valueOf(10d)"),
83
                @TriggerPattern("java.math.BigDecimal.valueOf(10.0d)"),
84
                @TriggerPattern("java.math.BigDecimal.valueOf(10.00d)"),}
85
    )
86
    public static ErrorDescription convert(HintContext ctx) {
87
88
        Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBDConstFixTEN(), ctx.getPath(), "java.math.BigDecimal.TEN");
89
        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBDConstFixTEN(), fix);
90
    }
91
92
   
93
}
(-)java.hints/src/org/netbeans/modules/java/hints/suggestions/UseBDConstFixZERO.java (+92 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.suggestions;
43
44
import org.netbeans.spi.editor.hints.ErrorDescription;
45
import org.netbeans.spi.editor.hints.Fix;
46
import org.netbeans.spi.editor.hints.Severity;
47
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
48
import org.netbeans.spi.java.hints.Hint;
49
import org.netbeans.spi.java.hints.HintContext;
50
import org.netbeans.spi.java.hints.TriggerPattern;
51
import org.netbeans.spi.java.hints.TriggerPatterns;
52
import org.openide.util.NbBundle.Messages;
53
54
@Messages({
55
    "ERR_UseBDConstFixZERO=Convert to BigDecimal.ZERO",
56
    "DN_UseBigDecimalConstantsZERO=Convert to BigDecimal.ZERO",
57
    "DESC_UseBigDecimalConstantsZERO=Converts expressions like <tt>new java.math.BigDecimal(0)</tt> to use <tt>BigDecimal.ZERO</tt>",})
58
/**
59
 * @author markiewb
60
 */
61
public class UseBDConstFixZERO {
62
63
    @Hint(displayName = "#DN_UseBigDecimalConstantsZERO", description = "#DESC_UseBigDecimalConstantsZERO", category = "suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT)
64
    @TriggerPatterns(
65
            {
66
                @TriggerPattern("new java.math.BigDecimal(\"0\")"),
67
                @TriggerPattern("new java.math.BigDecimal(\"0.0\")"),
68
                @TriggerPattern("new java.math.BigDecimal(\"0.00\")"),
69
                @TriggerPattern("new java.math.BigDecimal(0)"),
70
                @TriggerPattern("new java.math.BigDecimal(0L)"),
71
                @TriggerPattern("new java.math.BigDecimal(0f)"),
72
                @TriggerPattern("new java.math.BigDecimal(0.0f)"),
73
                @TriggerPattern("new java.math.BigDecimal(0.00f)"),
74
                @TriggerPattern("new java.math.BigDecimal(0d)"),
75
                @TriggerPattern("new java.math.BigDecimal(0.0d)"),
76
                @TriggerPattern("new java.math.BigDecimal(0.00d)"),
77
                @TriggerPattern("java.math.BigDecimal.valueOf(0)"),
78
                @TriggerPattern("java.math.BigDecimal.valueOf(0L)"),
79
                @TriggerPattern("java.math.BigDecimal.valueOf(0f)"),
80
                @TriggerPattern("java.math.BigDecimal.valueOf(0.0f)"),
81
                @TriggerPattern("java.math.BigDecimal.valueOf(0.00f)"),
82
                @TriggerPattern("java.math.BigDecimal.valueOf(0d)"),
83
                @TriggerPattern("java.math.BigDecimal.valueOf(0.0d)"),
84
                @TriggerPattern("java.math.BigDecimal.valueOf(0.00d)"),}
85
    )
86
    public static ErrorDescription convert(HintContext ctx) {
87
88
        Fix fix = org.netbeans.spi.java.hints.JavaFixUtilities.rewriteFix(ctx, Bundle.ERR_UseBDConstFixZERO(), ctx.getPath(), "java.math.BigDecimal.ZERO");
89
        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_UseBDConstFixZERO(), fix);
90
    }
91
92
}
(-)java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/UseBDConstFixONETest.java (+140 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.suggestions;
43
44
import org.junit.Test;
45
import org.netbeans.modules.java.hints.test.api.HintTest;
46
47
/**
48
 * @author markiewb
49
 */
50
public class UseBDConstFixONETest {
51
52
    @Test
53
    public void testConvert_A() throws Exception {
54
        HintTest.create()
55
                .input("package test;\n"
56
                        + "public class Test {\n"
57
                        + "    public static void main(String[] args) {\n"
58
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(\"1\");\n"
59
                        + "    }\n"
60
                        + "}\n")
61
                .run(UseBDConstFixONE.class)
62
                .findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixONE())
63
                .applyFix()
64
                .assertCompilable()
65
                .assertOutput("package test;\n"
66
                        + "import java.math.BigDecimal;\n"
67
                        + "public class Test {\n"
68
                        + "    public static void main(String[] args) {\n"
69
                        + "        java.math.BigDecimal a=BigDecimal.ONE;\n"
70
                        + "    }\n"
71
                        + "}\n");
72
73
    }
74
    @Test
75
    public void testConvert_B() throws Exception {
76
        HintTest.create()
77
                .input("package test;\n"
78
                        + "public class Test {\n"
79
                        + "    public static void main(String[] args) {\n"
80
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(\"1.0\");\n"
81
                        + "    }\n"
82
                        + "}\n")
83
                .run(UseBDConstFixONE.class)
84
                .findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixONE())
85
                .applyFix()
86
                .assertCompilable()
87
                .assertOutput("package test;\n"
88
                        + "import java.math.BigDecimal;\n"
89
                        + "public class Test {\n"
90
                        + "    public static void main(String[] args) {\n"
91
                        + "        java.math.BigDecimal a=BigDecimal.ONE;\n"
92
                        + "    }\n"
93
                        + "}\n");
94
95
    }
96
    @Test
97
    public void testConvert_C() throws Exception {
98
        HintTest.create()
99
                .input("package test;\n"
100
                        + "public class Test {\n"
101
                        + "    public static void main(String[] args) {\n"
102
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(1.0);\n"
103
                        + "    }\n"
104
                        + "}\n")
105
                .run(UseBDConstFixONE.class)
106
                .findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixONE())
107
                .applyFix()
108
                .assertCompilable()
109
                .assertOutput("package test;\n"
110
                        + "import java.math.BigDecimal;\n"
111
                        + "public class Test {\n"
112
                        + "    public static void main(String[] args) {\n"
113
                        + "        java.math.BigDecimal a=BigDecimal.ONE;\n"
114
                        + "    }\n"
115
                        + "}\n");
116
117
    }
118
    @Test
119
    public void testConvert_D() throws Exception {
120
        HintTest.create()
121
                .input("package test;\n"
122
                        + "public class Test {\n"
123
                        + "    public static void main(String[] args) {\n"
124
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(1.00d);\n"
125
                        + "    }\n"
126
                        + "}\n")
127
                .run(UseBDConstFixONE.class)
128
                .findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixONE())
129
                .applyFix()
130
                .assertCompilable()
131
                .assertOutput("package test;\n"
132
                        + "import java.math.BigDecimal;\n"
133
                        + "public class Test {\n"
134
                        + "    public static void main(String[] args) {\n"
135
                        + "        java.math.BigDecimal a=BigDecimal.ONE;\n"
136
                        + "    }\n"
137
                        + "}\n");
138
139
    }
140
}
(-)java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/UseBDConstFixTENTest.java (+143 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.suggestions;
43
44
import org.junit.Test;
45
import org.netbeans.modules.java.hints.test.api.HintTest;
46
47
/**
48
 * @author markiewb
49
 */
50
public class UseBDConstFixTENTest {
51
52
    @Test
53
    public void testConvert_A() throws Exception {
54
        HintTest.create()
55
                .input("package test;\n"
56
                        + "public class Test {\n"
57
                        + "    public static void main(String[] args) {\n"
58
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(\"10\");\n"
59
                        + "    }\n"
60
                        + "}\n")
61
                .run(UseBDConstFixTEN.class)
62
                .findWarning("3:31-3:61:hint:" + Bundle.ERR_UseBDConstFixTEN())
63
                .applyFix()
64
                .assertCompilable()
65
                .assertOutput("package test;\n"
66
                        + "import java.math.BigDecimal;\n"
67
                        + "public class Test {\n"
68
                        + "    public static void main(String[] args) {\n"
69
                        + "        java.math.BigDecimal a=BigDecimal.TEN;\n"
70
                        + "    }\n"
71
                        + "}\n");
72
73
    }
74
75
    @Test
76
    public void testConvert_B() throws Exception {
77
        HintTest.create()
78
                .input("package test;\n"
79
                        + "public class Test {\n"
80
                        + "    public static void main(String[] args) {\n"
81
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(\"10.0\");\n"
82
                        + "    }\n"
83
                        + "}\n")
84
                .run(UseBDConstFixTEN.class)
85
                .findWarning("3:31-3:63:hint:" + Bundle.ERR_UseBDConstFixTEN())
86
                .applyFix()
87
                .assertCompilable()
88
                .assertOutput("package test;\n"
89
                        + "import java.math.BigDecimal;\n"
90
                        + "public class Test {\n"
91
                        + "    public static void main(String[] args) {\n"
92
                        + "        java.math.BigDecimal a=BigDecimal.TEN;\n"
93
                        + "    }\n"
94
                        + "}\n");
95
96
    }
97
98
    @Test
99
    public void testConvert_C() throws Exception {
100
        HintTest.create()
101
                .input("package test;\n"
102
                        + "public class Test {\n"
103
                        + "    public static void main(String[] args) {\n"
104
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(10.0);\n"
105
                        + "    }\n"
106
                        + "}\n")
107
                .run(UseBDConstFixTEN.class)
108
                .findWarning("3:31-3:61:hint:" + Bundle.ERR_UseBDConstFixTEN())
109
                .applyFix()
110
                .assertCompilable()
111
                .assertOutput("package test;\n"
112
                        + "import java.math.BigDecimal;\n"
113
                        + "public class Test {\n"
114
                        + "    public static void main(String[] args) {\n"
115
                        + "        java.math.BigDecimal a=BigDecimal.TEN;\n"
116
                        + "    }\n"
117
                        + "}\n");
118
119
    }
120
121
    @Test
122
    public void testConvert_D() throws Exception {
123
        HintTest.create()
124
                .input("package test;\n"
125
                        + "public class Test {\n"
126
                        + "    public static void main(String[] args) {\n"
127
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(10.00d);\n"
128
                        + "    }\n"
129
                        + "}\n")
130
                .run(UseBDConstFixTEN.class)
131
                .findWarning("3:31-3:63:hint:" + Bundle.ERR_UseBDConstFixTEN())
132
                .applyFix()
133
                .assertCompilable()
134
                .assertOutput("package test;\n"
135
                        + "import java.math.BigDecimal;\n"
136
                        + "public class Test {\n"
137
                        + "    public static void main(String[] args) {\n"
138
                        + "        java.math.BigDecimal a=BigDecimal.TEN;\n"
139
                        + "    }\n"
140
                        + "}\n");
141
142
    }
143
}
(-)java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/UseBDConstFixZEROTest.java (+143 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.suggestions;
43
44
import org.junit.Test;
45
import org.netbeans.modules.java.hints.test.api.HintTest;
46
47
/**
48
 * @author markiewb
49
 */
50
public class UseBDConstFixZEROTest {
51
52
    @Test
53
    public void testConvert_A() throws Exception {
54
        HintTest.create()
55
                .input("package test;\n"
56
                        + "public class Test {\n"
57
                        + "    public static void main(String[] args) {\n"
58
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(\"0\");\n"
59
                        + "    }\n"
60
                        + "}\n")
61
                .run(UseBDConstFixZERO.class)
62
                .findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixZERO())
63
                .applyFix()
64
                .assertCompilable()
65
                .assertOutput("package test;\n"
66
                        + "import java.math.BigDecimal;\n"
67
                        + "public class Test {\n"
68
                        + "    public static void main(String[] args) {\n"
69
                        + "        java.math.BigDecimal a=BigDecimal.ZERO;\n"
70
                        + "    }\n"
71
                        + "}\n");
72
73
    }
74
75
    @Test
76
    public void testConvert_B() throws Exception {
77
        HintTest.create()
78
                .input("package test;\n"
79
                        + "public class Test {\n"
80
                        + "    public static void main(String[] args) {\n"
81
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(\"0.0\");\n"
82
                        + "    }\n"
83
                        + "}\n")
84
                .run(UseBDConstFixZERO.class)
85
                .findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixZERO())
86
                .applyFix()
87
                .assertCompilable()
88
                .assertOutput("package test;\n"
89
                        + "import java.math.BigDecimal;\n"
90
                        + "public class Test {\n"
91
                        + "    public static void main(String[] args) {\n"
92
                        + "        java.math.BigDecimal a=BigDecimal.ZERO;\n"
93
                        + "    }\n"
94
                        + "}\n");
95
96
    }
97
98
    @Test
99
    public void testConvert_C() throws Exception {
100
        HintTest.create()
101
                .input("package test;\n"
102
                        + "public class Test {\n"
103
                        + "    public static void main(String[] args) {\n"
104
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(0.0);\n"
105
                        + "    }\n"
106
                        + "}\n")
107
                .run(UseBDConstFixZERO.class)
108
                .findWarning("3:31-3:60:hint:" + Bundle.ERR_UseBDConstFixZERO())
109
                .applyFix()
110
                .assertCompilable()
111
                .assertOutput("package test;\n"
112
                        + "import java.math.BigDecimal;\n"
113
                        + "public class Test {\n"
114
                        + "    public static void main(String[] args) {\n"
115
                        + "        java.math.BigDecimal a=BigDecimal.ZERO;\n"
116
                        + "    }\n"
117
                        + "}\n");
118
119
    }
120
121
    @Test
122
    public void testConvert_D() throws Exception {
123
        HintTest.create()
124
                .input("package test;\n"
125
                        + "public class Test {\n"
126
                        + "    public static void main(String[] args) {\n"
127
                        + "        java.math.BigDecimal a=new java.math.BigDecimal(0.00d);\n"
128
                        + "    }\n"
129
                        + "}\n")
130
                .run(UseBDConstFixZERO.class)
131
                .findWarning("3:31-3:62:hint:" + Bundle.ERR_UseBDConstFixZERO())
132
                .applyFix()
133
                .assertCompilable()
134
                .assertOutput("package test;\n"
135
                        + "import java.math.BigDecimal;\n"
136
                        + "public class Test {\n"
137
                        + "    public static void main(String[] args) {\n"
138
                        + "        java.math.BigDecimal a=BigDecimal.ZERO;\n"
139
                        + "    }\n"
140
                        + "}\n");
141
142
    }
143
}

Return to bug 236244