Fixing octal integer constant handling in AddUnderscores hint.
authorJan Lahoda <jlahoda@netbeans.org>
Fri, 28 Oct 2011 00:53:20 +0200
changeset 1765854a0ce91f44e
parent 17657 99f0f6d43c81
child 17659 917566f2a1d5
Fixing octal integer constant handling in AddUnderscores hint.
javahints/nbproject/project.properties
javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscores.java
javahints/test/unit/src/org/netbeans/modules/javahints/jdk/AddUnderscoresTest.java
     1.1 --- a/javahints/nbproject/project.properties	Thu Oct 27 17:22:19 2011 +0200
     1.2 +++ b/javahints/nbproject/project.properties	Fri Oct 28 00:53:20 2011 +0200
     1.3 @@ -50,7 +50,7 @@
     1.4  auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width=80
     1.5  javac.compilerargs=-Xlint:unchecked
     1.6  javac.source=1.5
     1.7 -spec.version.base=2.46.0
     1.8 +spec.version.base=2.47.0
     1.9  
    1.10  nbm.needs.restart=true
    1.11  requires.nb.javac=true
     2.1 --- a/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscores.java	Thu Oct 27 17:22:19 2011 +0200
     2.2 +++ b/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscores.java	Fri Oct 28 00:53:20 2011 +0200
     2.3 @@ -80,6 +80,7 @@
     2.4          String literal = ctx.getInfo().getText().substring(start, end);
     2.5          if (!isReplaceLiteralsWithUnderscores(ctx.getPreferences()) && literal.contains("_")) return null;
     2.6          RadixInfo info = radixInfo(literal);
     2.7 +        if (info.radix == 8) return null;//octals ignored for now
     2.8          String normalized = info.constant.replaceAll(Pattern.quote("_"), "");
     2.9          int separateCount = getSizeForRadix(ctx.getPreferences(), info.radix);
    2.10          StringBuilder split = new StringBuilder();
    2.11 @@ -147,6 +148,13 @@
    2.12  
    2.13  
    2.14      public static RadixInfo radixInfo(String literal) {
    2.15 +        String suffix = "";
    2.16 +
    2.17 +        if (literal.endsWith("l") || literal.endsWith("L")) {
    2.18 +            suffix = literal.substring(literal.length() - 1);
    2.19 +            literal = literal.substring(0, literal.length() - 1);
    2.20 +        }
    2.21 +
    2.22          int currentRadix = 10;
    2.23          String prefix = "";
    2.24  
    2.25 @@ -158,19 +166,12 @@
    2.26              currentRadix = 2;
    2.27              prefix = literal.substring(0, 2);
    2.28              literal = literal.substring(2);
    2.29 -        } else if (literal.startsWith("0")) {
    2.30 +        } else if (literal.startsWith("0") && literal.length() > 1) {
    2.31              currentRadix = 8;
    2.32              prefix = literal.substring(0, 1);
    2.33              literal = literal.substring(1);
    2.34          }
    2.35  
    2.36 -        String suffix = "";
    2.37 -
    2.38 -        if (literal.endsWith("l") || literal.endsWith("L")) {
    2.39 -            suffix = literal.substring(literal.length() - 1);
    2.40 -            literal = literal.substring(0, literal.length() - 1);
    2.41 -        }
    2.42 -
    2.43          return new RadixInfo(prefix, literal, suffix, currentRadix);
    2.44      }
    2.45  
     3.1 --- a/javahints/test/unit/src/org/netbeans/modules/javahints/jdk/AddUnderscoresTest.java	Thu Oct 27 17:22:19 2011 +0200
     3.2 +++ b/javahints/test/unit/src/org/netbeans/modules/javahints/jdk/AddUnderscoresTest.java	Fri Oct 28 00:53:20 2011 +0200
     3.3 @@ -126,6 +126,19 @@
     3.4                         "}\n").replaceAll("[ \t\n]+", " "));
     3.5      }
     3.6  
     3.7 +    public void testZeroIsNotOctal() throws Exception {
     3.8 +        assertEquals(10, AddUnderscores.radixInfo("0").radix);
     3.9 +        assertEquals(10, AddUnderscores.radixInfo("0L").radix);
    3.10 +    }
    3.11 +
    3.12 +    public void testIgnoreOctalConstantsForNow() throws Exception {
    3.13 +        performAnalysisTest("test/Test.java",
    3.14 +                            "package test;\n" +
    3.15 +                            "public class Test {\n" +
    3.16 +                            "    private static final int CONST = 0123;\n" +
    3.17 +                            "}\n");
    3.18 +    }
    3.19 +
    3.20      private Preferences prefs;
    3.21  
    3.22      @Override