diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-08 12:32:06 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-08 23:24:17 +0400 |
commit | 691ae00bf9e8cdfe5bd5528f2c58f8c5415601e2 (patch) | |
tree | 637820eaece32edeab676bea703cf3787f5e2c35 /sonar-duplications/src/main/java/org | |
parent | 070b2dd35a49fbf4a6bd22bd7426c49e437b4a8b (diff) | |
download | sonarqube-691ae00bf9e8cdfe5bd5528f2c58f8c5415601e2.tar.gz sonarqube-691ae00bf9e8cdfe5bd5528f2c58f8c5415601e2.zip |
SONAR-1091 Sonar-CPD: support Java 7 (JSR334)
* Binary integer literals
* Underscores in numeric literals
Diffstat (limited to 'sonar-duplications/src/main/java/org')
-rw-r--r-- | sonar-duplications/src/main/java/org/sonar/duplications/java/JavaTokenProducer.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/java/JavaTokenProducer.java b/sonar-duplications/src/main/java/org/sonar/duplications/java/JavaTokenProducer.java index d9d922fcb27..41a25d38be5 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/java/JavaTokenProducer.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/java/JavaTokenProducer.java @@ -23,6 +23,7 @@ import org.sonar.duplications.token.TokenChunker; /** * See <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html">The Java Language Specification, Third Edition: Lexical Structure</a> + * and <a href="http://www.jcp.org/en/jsr/detail?id=334">JSR334 (Java 7 - binary integral literals and underscores in numeric literals)</a>. * * <p> * We decided to use dollar sign as a prefix for normalization, even if it can be a part of an identifier, @@ -38,8 +39,8 @@ public final class JavaTokenProducer { private static final String NORMALIZED_CHARACTER_LITERAL = "$CHARS"; private static final String NORMALIZED_NUMERIC_LITERAL = "$NUMBER"; - private static final String EXP = "([Ee][+-]?+[0-9]++)"; - private static final String BINARY_EXP = "([Pp][+-]?+[0-9]++)"; + private static final String EXP = "([Ee][+-]?+[0-9_]++)"; + private static final String BINARY_EXP = "([Pp][+-]?+[0-9_]++)"; private static final String FLOAT_SUFFIX = "[fFdD]"; private static final String INT_SUFFIX = "[lL]"; @@ -58,14 +59,15 @@ public final class JavaTokenProducer { // Identifiers, Keywords, Boolean Literals, The Null Literal .token("\\p{javaJavaIdentifierStart}++\\p{javaJavaIdentifierPart}*+") // Floating-Point Literals - .token("[0-9]++\\.([0-9]++)?+" + EXP + "?+" + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) - .token("\\.[0-9]++" + EXP + "?+" + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) - .token("[0-9]++" + EXP + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) - .token("0[xX][0-9a-fA-F]++\\.[0-9a-fA-F]*+" + BINARY_EXP + "?+" + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) - .token("0[xX][0-9a-fA-F]++" + BINARY_EXP + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) + .token("[0-9_]++\\.([0-9_]++)?+" + EXP + "?+" + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Decimal + .token("\\.[0-9_]++" + EXP + "?+" + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Decimal + .token("[0-9_]++" + EXP + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Decimal + .token("0[xX][0-9a-fA-F_]++\\.[0-9a-fA-F_]*+" + BINARY_EXP + "?+" + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Hexadecimal + .token("0[xX][0-9a-fA-F_]++" + BINARY_EXP + FLOAT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Hexadecimal // Integer Literals - .token("0[xX][0-9a-fA-F]++" + INT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) - .token("[0-9]++" + INT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) + .token("0[xX][0-9a-fA-F_]++" + INT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Hexadecimal + .token("0[bB][01_]++" + INT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Binary (Java 7) + .token("[0-9_]++" + INT_SUFFIX + "?+", NORMALIZED_NUMERIC_LITERAL) // Decimal and Octal // Any other character .token(".") .build(); |