optimized for jar size.

This commit is contained in:
wenshao
2017-01-15 11:33:42 +08:00
parent 4992d3f3eb
commit 0a8d0802f7
5 changed files with 137 additions and 192 deletions
@@ -256,19 +256,86 @@ public final class JSONLexer {
next();
break;
case 't': // true
scanTrue();
return;
{
if (text.startsWith("true", bp)) {
bp += 4;
ch = charAt(bp);
if (ch == ' ' //
|| ch == ',' //
|| ch == '}' //
|| ch == ']' //
|| ch == '\n' //
|| ch == '\r' //
|| ch == '\t' //
|| ch == EOI //
|| ch == '\f' //
|| ch == '\b' //
|| ch == ':') {
token = JSONToken.TRUE;
return;
}
}
throw new JSONException("scan true error");
}
case 'T': // treeSet
case 'S': // set
case 'u': //undefined
scanIdent();
return;
case 'f': // false
scanFalse();
return;
{
if (text.startsWith("false", bp)) {
bp += 5;
ch = charAt(bp);
if (ch == ' '//
|| ch == ','//
|| ch == '}'//
|| ch == ']'//
|| ch == '\n'//
|| ch == '\r'//
|| ch == '\t'//
|| ch == EOI//
|| ch == '\f'//
|| ch == '\b'//
|| ch == ':') {
token = JSONToken.FALSE;
return;
}
}
throw new JSONException("scan false error");
}
case 'n': // new,null
scanNullOrNew();
return;
{
int token = 0;
if (text.startsWith("null", bp)) {
bp += 4;
token = JSONToken.NULL;
} else if (text.startsWith("new", bp)) {
bp += 3;
token = JSONToken.NEW;
}
if (token != 0) {
ch = charAt(bp);
if (ch == ' ' //
|| ch == ',' //
|| ch == '}' //
|| ch == ']' //
|| ch == '\n' //
|| ch == '\r' //
|| ch == '\t' //
|| ch == EOI //
|| ch == '\f' //
|| ch == '\b') {
this.token = token;
return;
}
}
throw new JSONException("scan null/new error");
}
case '(':
next();
token = LPAREN;
@@ -1110,82 +1177,6 @@ public final class JSONLexer {
return decodeFast(text, np + 1, sp);
}
private void scanTrue() {
if (text.startsWith("true", bp)) {
bp += 4;
ch = charAt(bp);
if (ch == ' ' //
|| ch == ',' //
|| ch == '}' //
|| ch == ']' //
|| ch == '\n' //
|| ch == '\r' //
|| ch == '\t' //
|| ch == EOI //
|| ch == '\f' //
|| ch == '\b' //
|| ch == ':') {
token = JSONToken.TRUE;
return;
}
}
throw new JSONException("scan true error");
}
private void scanNullOrNew() {
int token = 0;
if (text.startsWith("null", bp)) {
bp += 4;
token = JSONToken.NULL;
} else if (text.startsWith("new", bp)) {
bp += 3;
token = JSONToken.NEW;
}
if (token != 0) {
ch = charAt(bp);
if (ch == ' ' //
|| ch == ',' //
|| ch == '}' //
|| ch == ']' //
|| ch == '\n' //
|| ch == '\r' //
|| ch == '\t' //
|| ch == EOI //
|| ch == '\f' //
|| ch == '\b') {
this.token = token;
return;
}
}
throw new JSONException("scan null/new error");
}
private void scanFalse() {
if (text.startsWith("false", bp)) {
bp += 5;
ch = charAt(bp);
if (ch == ' '//
|| ch == ','//
|| ch == '}'//
|| ch == ']'//
|| ch == '\n'//
|| ch == '\r'//
|| ch == '\t'//
|| ch == EOI//
|| ch == '\f'//
|| ch == '\b'//
|| ch == ':') {
token = JSONToken.FALSE;
return;
}
}
throw new JSONException("scan false error");
}
private void scanIdent() {
np = bp - 1;
hasSpecial = false;
@@ -9,34 +9,18 @@ import com.alibaba.fastjson.parser.JSONLexer;
import junit.framework.TestCase;
public class JSONScannerTest_false extends TestCase {
Method method;
protected void setUp() throws Exception {
method = JSONLexer.class.getDeclaredMethod("scanFalse");
method.setAccessible(true);
}
public void test_scan_false_0() throws Exception {
JSONLexer lexer = new JSONLexer("false");
method.invoke(lexer);
}
public void test_scan_false_1() throws Exception {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("zalse");
method.invoke(lexer);
} catch (Exception e) {
error = e;
}
Assert.assertNotNull(error);
lexer.nextToken();
}
public void test_scan_false_2() throws Exception {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("fzlse");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -47,7 +31,7 @@ public class JSONScannerTest_false extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("fazse");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -58,7 +42,7 @@ public class JSONScannerTest_false extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("falze");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -69,7 +53,7 @@ public class JSONScannerTest_false extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("falsz");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -80,7 +64,7 @@ public class JSONScannerTest_false extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("falsee");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -91,7 +75,7 @@ public class JSONScannerTest_false extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("false\"");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -100,46 +84,46 @@ public class JSONScannerTest_false extends TestCase {
public void test_scan_false_7() throws Exception {
JSONLexer lexer = new JSONLexer("false a");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_8() throws Exception {
JSONLexer lexer = new JSONLexer("false,");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_9() throws Exception {
JSONLexer lexer = new JSONLexer("false\na");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_10() throws Exception {
JSONLexer lexer = new JSONLexer("false\ra");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_11() throws Exception {
JSONLexer lexer = new JSONLexer("false\ta");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_12() throws Exception {
JSONLexer lexer = new JSONLexer("false\fa");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_13() throws Exception {
JSONLexer lexer = new JSONLexer("false\ba");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_14() throws Exception {
JSONLexer lexer = new JSONLexer("false}");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_15() throws Exception {
JSONLexer lexer = new JSONLexer("false]");
method.invoke(lexer);
lexer.nextToken();
}
}
@@ -9,23 +9,17 @@ import com.alibaba.fastjson.parser.JSONLexer;
import junit.framework.TestCase;
public class JSONScannerTest_new extends TestCase {
Method method;
protected void setUp() throws Exception {
method = JSONLexer.class.getDeclaredMethod("scanNullOrNew");
method.setAccessible(true);
}
public void test_scan_new_0() throws Exception {
JSONLexer lexer = new JSONLexer("new");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_1() throws Exception {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("nww");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -36,7 +30,7 @@ public class JSONScannerTest_new extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("nee");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -47,7 +41,7 @@ public class JSONScannerTest_new extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("neel");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -58,7 +52,7 @@ public class JSONScannerTest_new extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("neww");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -69,7 +63,7 @@ public class JSONScannerTest_new extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("newe");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -80,7 +74,7 @@ public class JSONScannerTest_new extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("new\"");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -89,46 +83,46 @@ public class JSONScannerTest_new extends TestCase {
public void test_scan_new_7() throws Exception {
JSONLexer lexer = new JSONLexer("new a");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_8() throws Exception {
JSONLexer lexer = new JSONLexer("new,");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_9() throws Exception {
JSONLexer lexer = new JSONLexer("new\na");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_10() throws Exception {
JSONLexer lexer = new JSONLexer("new\ra");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_11() throws Exception {
JSONLexer lexer = new JSONLexer("new\ta");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_12() throws Exception {
JSONLexer lexer = new JSONLexer("new\fa");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_13() throws Exception {
JSONLexer lexer = new JSONLexer("new\ba");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_14() throws Exception {
JSONLexer lexer = new JSONLexer("new}");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_new_15() throws Exception {
JSONLexer lexer = new JSONLexer("new]");
method.invoke(lexer);
lexer.nextToken();
}
}
@@ -10,34 +10,18 @@ import junit.framework.TestCase;
public class JSONScannerTest_null extends TestCase {
Method method;
protected void setUp() throws Exception {
method = JSONLexer.class.getDeclaredMethod("scanNullOrNew");
method.setAccessible(true);
}
public void test_scan_null_0() throws Exception {
JSONLexer lexer = new JSONLexer("null");
method.invoke(lexer);
}
public void test_scan_null_1() throws Exception {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("zull");
method.invoke(lexer);
} catch (Exception e) {
error = e;
}
Assert.assertNotNull(error);
lexer.nextToken();
}
public void test_scan_null_2() throws Exception {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("nzll");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -48,7 +32,7 @@ public class JSONScannerTest_null extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("nuzl");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -59,7 +43,7 @@ public class JSONScannerTest_null extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("nulz");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -70,7 +54,7 @@ public class JSONScannerTest_null extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("nulle");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -81,7 +65,7 @@ public class JSONScannerTest_null extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("null\"");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -90,46 +74,46 @@ public class JSONScannerTest_null extends TestCase {
public void test_scan_null_7() throws Exception {
JSONLexer lexer = new JSONLexer("null a");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_null_8() throws Exception {
JSONLexer lexer = new JSONLexer("null,");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_null_9() throws Exception {
JSONLexer lexer = new JSONLexer("null\na");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_null_10() throws Exception {
JSONLexer lexer = new JSONLexer("null\ra");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_null_11() throws Exception {
JSONLexer lexer = new JSONLexer("null\ta");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_null_12() throws Exception {
JSONLexer lexer = new JSONLexer("null\fa");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_null_13() throws Exception {
JSONLexer lexer = new JSONLexer("null\ba");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_14() throws Exception {
JSONLexer lexer = new JSONLexer("null}");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_15() throws Exception {
JSONLexer lexer = new JSONLexer("null]");
method.invoke(lexer);
lexer.nextToken();
}
}
@@ -10,24 +10,16 @@ import com.alibaba.fastjson.parser.JSONLexer;
import junit.framework.TestCase;
public class JSONScannerTest_true extends TestCase {
Method method;
protected void setUp() throws Exception {
method = JSONLexer.class.getDeclaredMethod("scanTrue");
method.setAccessible(true);
}
public void test_scan_true_0() throws Exception {
JSONLexer lexer = new JSONLexer("true");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_true_1() throws Exception {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("frue");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -38,7 +30,7 @@ public class JSONScannerTest_true extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("ttue");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -49,7 +41,7 @@ public class JSONScannerTest_true extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("trze");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -60,7 +52,7 @@ public class JSONScannerTest_true extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("truz");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -71,7 +63,7 @@ public class JSONScannerTest_true extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("truee");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -82,7 +74,7 @@ public class JSONScannerTest_true extends TestCase {
Exception error = null;
try {
JSONLexer lexer = new JSONLexer("true\"");
method.invoke(lexer);
lexer.nextToken();
} catch (Exception e) {
error = e;
}
@@ -91,46 +83,46 @@ public class JSONScannerTest_true extends TestCase {
public void test_scan_true_7() throws Exception {
JSONLexer lexer = new JSONLexer("true a");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_true_8() throws Exception {
JSONLexer lexer = new JSONLexer("true,");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_true_9() throws Exception {
JSONLexer lexer = new JSONLexer("true\na");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_true_10() throws Exception {
JSONLexer lexer = new JSONLexer("true\ra");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_true_11() throws Exception {
JSONLexer lexer = new JSONLexer("true\ta");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_true_12() throws Exception {
JSONLexer lexer = new JSONLexer("true\fa");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_true_13() throws Exception {
JSONLexer lexer = new JSONLexer("true\ba");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_14() throws Exception {
JSONLexer lexer = new JSONLexer("true}");
method.invoke(lexer);
lexer.nextToken();
}
public void test_scan_false_15() throws Exception {
JSONLexer lexer = new JSONLexer("true]");
method.invoke(lexer);
lexer.nextToken();
}
}