| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aad493e commit b569440
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,6 +159,20 @@ public static List<Edit> addPublicToTopLevelMethods(CompilationUnit cu) { | |||
| 159 | 159 | return edits; | |
| 160 | 160 | } | |
| 161 | 161 | ||
| 162 | + | ||
| 163 | + // Verifies that whole input String is floating point literal. Can't be used for searching. | ||
| 164 | + // https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-DecimalFloatingPointLiteral | ||
| 165 | + public static final Pattern FLOATING_POINT_LITERAL_VERIFIER; | ||
| 166 | + static { | ||
| 167 | + final String DIGITS = "(?:[0-9]|[0-9][0-9_]*[0-9])"; | ||
| 168 | + final String EXPONENT_PART = "(?:[eE][+-]?" + DIGITS + ")"; | ||
| 169 | + FLOATING_POINT_LITERAL_VERIFIER = Pattern.compile( | ||
| 170 | + "(?:^" + DIGITS + "\\." + DIGITS + "?" + EXPONENT_PART + "?[fFdD]?$)|" + | ||
| 171 | + "(?:^\\." + DIGITS + EXPONENT_PART + "?[fFdD]?$)|" + | ||
| 172 | + "(?:^" + DIGITS + EXPONENT_PART + "[fFdD]?$)|" + | ||
| 173 | + "(?:^" + DIGITS + EXPONENT_PART + "?[fFdD]$)"); | ||
| 174 | + } | ||
| 175 | + | ||
| 162 | 176 | public static List<Edit> replaceColorAndFixFloats(CompilationUnit cu) { | |
| 163 | 177 | final List<Edit> edits = new ArrayList<>(); | |
| 164 | 178 | ||
@@ -175,7 +189,7 @@ public boolean visit(SimpleType node) { | |||
| 175 | 189 | @Override | |
| 176 | 190 | public boolean visit(NumberLiteral node) { | |
| 177 | 191 | String s = node.getToken().toLowerCase(); | |
| 178 | - if (!s.endsWith("f") && !s.endsWith("d") && (s.contains(".") || s.contains("e"))) { | ||
| 192 | + if (FLOATING_POINT_LITERAL_VERIFIER.matcher(s).matches() && !s.endsWith("f") && !s.endsWith("d")) { | ||
| 179 | 193 | edits.add(Edit.insert(node.getStartPosition() + node.getLength(), "f")); | |
| 180 | 194 | } | |
| 181 | 195 | return super.visit(node); | |
@@ -202,6 +216,7 @@ public static List<Edit> replaceColorRegex(CharSequence source) { | |||
| 202 | 216 | return edits; | |
| 203 | 217 | } | |
| 204 | 218 | ||
| 219 | + | ||
| 205 | 220 | public static final Pattern NUMBER_LITERAL_REGEX = | |
| 206 | 221 | Pattern.compile("[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?"); | |
| 207 | 222 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments