1 19 20 package org.netbeans.editor.ext.java; 21 22 import org.netbeans.editor.Syntax; 23 import org.netbeans.editor.TokenID; 24 25 32 33 public class JavaSyntax extends Syntax { 34 35 private static final int ISI_WHITESPACE = 2; private static final int ISI_LINE_COMMENT = 4; private static final int ISI_BLOCK_COMMENT = 5; private static final int ISI_STRING = 6; private static final int ISI_STRING_A_BSLASH = 7; private static final int ISI_CHAR = 8; private static final int ISI_CHAR_A_BSLASH = 9; private static final int ISI_IDENTIFIER = 10; private static final int ISA_SLASH = 11; private static final int ISA_EQ = 12; private static final int ISA_GT = 13; private static final int ISA_GTGT = 14; private static final int ISA_GTGTGT = 15; private static final int ISA_LT = 16; private static final int ISA_LTLT = 17; private static final int ISA_PLUS = 18; private static final int ISA_MINUS = 19; private static final int ISA_STAR = 20; private static final int ISA_STAR_I_BLOCK_COMMENT = 21; private static final int ISA_PIPE = 22; private static final int ISA_PERCENT = 23; private static final int ISA_AND = 24; private static final int ISA_XOR = 25; private static final int ISA_EXCLAMATION = 26; private static final int ISA_ZERO = 27; private static final int ISI_INT = 28; private static final int ISI_OCTAL = 29; private static final int ISI_DOUBLE = 30; private static final int ISI_DOUBLE_EXP = 31; private static final int ISI_HEX = 32; private static final int ISA_DOT = 33; 68 private boolean isJava15 = true; 69 70 private boolean useInJsp = false; 72 73 public JavaSyntax() { 74 tokenContextPath = JavaTokenContext.contextPath; 75 } 76 77 public JavaSyntax(String sourceLevel) { 78 this(); 79 if (sourceLevel != null) { 80 try { 81 isJava15 = Float.parseFloat(sourceLevel) >= 1.5; 82 } catch (NumberFormatException e) { 83 } 85 } 86 } 87 88 public JavaSyntax(String sourceLevel, boolean useInJsp) { 89 this(sourceLevel); 90 this.useInJsp = useInJsp; 91 } 92 93 protected TokenID parseToken() { 94 char actChar; 95 96 while(offset < stopOffset) { 97 actChar = buffer[offset]; 98 99 switch (state) { 100 case INIT: 101 switch (actChar) { 102 case '"': state = ISI_STRING; 104 break; 105 case '\'': 106 state = ISI_CHAR; 107 break; 108 case '/': 109 state = ISA_SLASH; 110 break; 111 case '=': 112 state = ISA_EQ; 113 break; 114 case '>': 115 state = ISA_GT; 116 break; 117 case '<': 118 state = ISA_LT; 119 break; 120 case '+': 121 state = ISA_PLUS; 122 break; 123 case '-': 124 state = ISA_MINUS; 125 break; 126 case '*': 127 state = ISA_STAR; 128 break; 129 case '|': 130 state = ISA_PIPE; 131 break; 132 case '%': 133 state = ISA_PERCENT; 134 break; 135 case '&': 136 state = ISA_AND; 137 break; 138 case '^': 139 state = ISA_XOR; 140 break; 141 case '~': 142 offset++; 143 return JavaTokenContext.NEG; 144 case '!': 145 state = ISA_EXCLAMATION; 146 break; 147 case '0': 148 state = ISA_ZERO; 149 break; 150 case '.': 151 state = ISA_DOT; 152 break; 153 case ',': 154 offset++; 155 return JavaTokenContext.COMMA; 156 case ';': 157 offset++; 158 return JavaTokenContext.SEMICOLON; 159 case ':': 160 offset++; 161 return JavaTokenContext.COLON; 162 case '?': 163 offset++; 164 return JavaTokenContext.QUESTION; 165 case '(': 166 offset++; 167 return JavaTokenContext.LPAREN; 168 case ')': 169 offset++; 170 return JavaTokenContext.RPAREN; 171 case '[': 172 offset++; 173 return JavaTokenContext.LBRACKET; 174 case ']': 175 offset++; 176 return JavaTokenContext.RBRACKET; 177 case '{': 178 offset++; 179 return JavaTokenContext.LBRACE; 180 case '}': 181 offset++; 182 return JavaTokenContext.RBRACE; 183 case '@': offset++; 185 return JavaTokenContext.ANNOTATION; 186 187 default: 188 if (Character.isWhitespace(actChar)) { 190 state = ISI_WHITESPACE; 191 break; 192 } 193 194 if (Character.isDigit(actChar)) { 196 state = ISI_INT; 197 break; 198 } 199 200 if (Character.isJavaIdentifierStart(actChar)) { 202 state = ISI_IDENTIFIER; 203 break; 204 } 205 206 offset++; 207 return JavaTokenContext.INVALID_CHAR; 208 } 209 break; 210 211 case ISI_WHITESPACE: if (!Character.isWhitespace(actChar)) { 213 state = INIT; 214 return JavaTokenContext.WHITESPACE; 215 } 216 break; 217 218 case ISI_LINE_COMMENT: 219 switch (actChar) { 220 case '\n': 221 state = INIT; 222 return JavaTokenContext.LINE_COMMENT; 223 } 224 break; 225 226 case ISI_BLOCK_COMMENT: 227 switch (actChar) { 228 case '*': 229 state = ISA_STAR_I_BLOCK_COMMENT; 230 break; 231 case '\n': 233 if(useInJsp) { 234 offset++; 237 return JavaTokenContext.BLOCK_COMMENT; 238 } 239 } 240 break; 241 242 case ISI_STRING: 243 switch (actChar) { 244 case '\\': 245 state = ISI_STRING_A_BSLASH; 246 break; 247 case '\n': 248 state = INIT; 249 supposedTokenID = JavaTokenContext.STRING_LITERAL; 250 return supposedTokenID; 252 case '"': offset++; 254 state = INIT; 255 return JavaTokenContext.STRING_LITERAL; 256 } 257 break; 258 259 case ISI_STRING_A_BSLASH: 260 switch (actChar) { 261 case '"': case '\\': 263 break; 264 default: 265 offset--; 266 break; 267 } 268 state = ISI_STRING; 269 break; 270 271 case ISI_CHAR: 272 switch (actChar) { 273 case '\\': 274 state = ISI_CHAR_A_BSLASH; 275 break; 276 case '\n': 277 state = INIT; 278 supposedTokenID = JavaTokenContext.CHAR_LITERAL; 279 return supposedTokenID; 281 case '\'': 282 offset++; 283 state = INIT; 284 return JavaTokenContext.CHAR_LITERAL; 285 } 286 break; 287 288 case ISI_CHAR_A_BSLASH: 289 switch (actChar) { 290 case '\'': 291 case '\\': 292 break; 293 default: 294 offset--; 295 break; 296 } 297 state = ISI_CHAR; 298 break; 299 300 case ISI_IDENTIFIER: 301 if (!(Character.isJavaIdentifierPart(actChar))) { 302 state = INIT; 303 TokenID tid = matchKeyword(buffer, tokenOffset, offset - tokenOffset); 304 return (tid != null) ? tid : JavaTokenContext.IDENTIFIER; 305 } 306 break; 307 308 case ISA_SLASH: 309 switch (actChar) { 310 case '=': 311 offset++; 312 state = INIT; 313 return JavaTokenContext.DIV_EQ; 314 case '/': 315 state = ISI_LINE_COMMENT; 316 break; 317 case '*': 318 state = ISI_BLOCK_COMMENT; 319 break; 320 default: 321 state = INIT; 322 return JavaTokenContext.DIV; 323 } 324 break; 325 326 case ISA_EQ: 327 switch (actChar) { 328 case '=': 329 offset++; 330 return JavaTokenContext.EQ_EQ; 331 default: 332 state = INIT; 333 return JavaTokenContext.EQ; 334 } 335 337 case ISA_GT: 338 switch (actChar) { 339 case '>': 340 state = ISA_GTGT; 341 break; 342 case '=': 343 offset++; 344 return JavaTokenContext.GT_EQ; 345 default: 346 state = INIT; 347 return JavaTokenContext.GT; 348 } 349 break; 350 351 case ISA_GTGT: 352 switch (actChar) { 353 case '>': 354 state = ISA_GTGTGT; 355 break; 356 case '=': 357 offset++; 358 return JavaTokenContext.RSSHIFT_EQ; 359 default: 360 state = INIT; 361 return JavaTokenContext.RSSHIFT; 362 } 363 break; 364 365 case ISA_GTGTGT: 366 switch (actChar) { 367 case '=': 368 offset++; 369 return JavaTokenContext.RUSHIFT_EQ; 370 default: 371 state = INIT; 372 return JavaTokenContext.RUSHIFT; 373 } 374 376 377 case ISA_LT: 378 switch (actChar) { 379 case '<': 380 state = ISA_LTLT; 381 break; 382 case '=': 383 offset++; 384 return JavaTokenContext.LT_EQ; 385 default: 386 state = INIT; 387 return JavaTokenContext.LT; 388 } 389 break; 390 391 case ISA_LTLT: 392 switch (actChar) { 393 case '<': 394 state = INIT; 395 offset++; 396 return JavaTokenContext.INVALID_OPERATOR; 397 case '=': 398 offset++; 399 return JavaTokenContext.LSHIFT_EQ; 400 default: 401 state = INIT; 402 return JavaTokenContext.LSHIFT; 403 } 404 405 case ISA_PLUS: 406 switch (actChar) { 407 case '+': 408 offset++; 409 return JavaTokenContext.PLUS_PLUS; 410 case '=': 411 offset++; 412 return JavaTokenContext.PLUS_EQ; 413 default: 414 state = INIT; 415 return JavaTokenContext.PLUS; 416 } 417 418 case ISA_MINUS: 419 switch (actChar) { 420 case '-': 421 offset++; 422 return JavaTokenContext.MINUS_MINUS; 423 case '=': 424 offset++; 425 return JavaTokenContext.MINUS_EQ; 426 default: 427 state = INIT; 428 return JavaTokenContext.MINUS; 429 } 430 431 case ISA_STAR: 432 switch (actChar) { 433 case '=': 434 offset++; 435 return JavaTokenContext.MUL_EQ; 436 case '/': 437 offset++; 438 state = INIT; 439 return JavaTokenContext.INVALID_COMMENT_END; default: 441 state = INIT; 442 return JavaTokenContext.MUL; 443 } 444 445 case ISA_STAR_I_BLOCK_COMMENT: 446 switch (actChar) { 447 case '/': 448 offset++; 449 state = INIT; 450 return JavaTokenContext.BLOCK_COMMENT; 451 default: 452 offset--; 453 state = ISI_BLOCK_COMMENT; 454 break; 455 } 456 break; 457 458 case ISA_PIPE: 459 switch (actChar) { 460 case '=': 461 offset++; 462 state = INIT; 463 return JavaTokenContext.OR_EQ; 464 case '|': 465 offset++; 466 state = INIT; 467 return JavaTokenContext.OR_OR; 468 default: 469 state = INIT; 470 return JavaTokenContext.OR; 471 } 472 474 case ISA_PERCENT: 475 switch (actChar) { 476 case '=': 477 offset++; 478 state = INIT; 479 return JavaTokenContext.MOD_EQ; 480 default: 481 state = INIT; 482 return JavaTokenContext.MOD; 483 } 484 486 case ISA_AND: 487 switch (actChar) { 488 case '=': 489 offset++; 490 state = INIT; 491 return JavaTokenContext.AND_EQ; 492 case '&': 493 offset++; 494 state = INIT; 495 return JavaTokenContext.AND_AND; 496 default: 497 state = INIT; 498 return JavaTokenContext.AND; 499 } 500 502 case ISA_XOR: 503 switch (actChar) { 504 case '=': 505 offset++; 506 state = INIT; 507 return JavaTokenContext.XOR_EQ; 508 default: 509 state = INIT; 510 return JavaTokenContext.XOR; 511 } 512 514 case ISA_EXCLAMATION: 515 switch (actChar) { 516 case '=': 517 offset++; 518 state = INIT; 519 return JavaTokenContext.NOT_EQ; 520 default: 521 state = INIT; 522 return JavaTokenContext.NOT; 523 } 524 526 case ISA_ZERO: 527 switch (actChar) { 528 case '.': 529 state = ISI_DOUBLE; 530 break; 531 case 'x': 532 case 'X': 533 state = ISI_HEX; 534 break; 535 case 'l': 536 case 'L': 537 offset++; 538 state = INIT; 539 return JavaTokenContext.LONG_LITERAL; 540 case 'f': 541 case 'F': 542 offset++; 543 state = INIT; 544 return JavaTokenContext.FLOAT_LITERAL; 545 case 'd': 546 case 'D': 547 offset++; 548 state = INIT; 549 return JavaTokenContext.DOUBLE_LITERAL; 550 case '8': case '9': 552 state = INIT; 553 offset++; 554 return JavaTokenContext.INVALID_OCTAL_LITERAL; 555 case 'e': 556 case 'E': 557 state = ISI_DOUBLE_EXP; 558 break; 559 default: 560 if (Character.isDigit(actChar)) { state = ISI_OCTAL; 562 break; 563 } 564 state = INIT; 565 return JavaTokenContext.INT_LITERAL; 566 } 567 break; 568 569 case ISI_INT: 570 switch (actChar) { 571 case 'l': 572 case 'L': 573 offset++; 574 state = INIT; 575 return JavaTokenContext.LONG_LITERAL; 576 case '.': 577 state = ISI_DOUBLE; 578 break; 579 case 'f': 580 case 'F': 581 offset++; 582 state = INIT; 583 return JavaTokenContext.FLOAT_LITERAL; 584 case 'd': 585 case 'D': 586 offset++; 587 state = INIT; 588 return JavaTokenContext.DOUBLE_LITERAL; 589 case 'e': 590 case 'E': 591 state = ISI_DOUBLE_EXP; 592 break; 593 default: 594 if (!(actChar >= '0' && actChar <= '9')) { 595 state = INIT; 596 return JavaTokenContext.INT_LITERAL; 597 } 598 } 599 break; 600 601 case ISI_OCTAL: 602 if (!(actChar >= '0' && actChar <= '7')) { 603 604 state = INIT; 605 return JavaTokenContext.OCTAL_LITERAL; 606 } 607 break; 608 609 case ISI_DOUBLE: 610 switch (actChar) { 611 case 'f': 612 case 'F': 613 offset++; 614 state = INIT; 615 return JavaTokenContext.FLOAT_LITERAL; 616 case 'd': 617 case 'D': 618 offset++; 619 state = INIT; 620 return JavaTokenContext.DOUBLE_LITERAL; 621 case 'e': 622 case 'E': 623 state = ISI_DOUBLE_EXP; 624 break; 625 default: 626 if (!((actChar >= '0' && actChar <= '9') 627 || actChar == '.')) { 628 629 state = INIT; 630 return JavaTokenContext.DOUBLE_LITERAL; 631 } 632 } 633 break; 634 635 case ISI_DOUBLE_EXP: 636 switch (actChar) { 637 case 'f': 638 case 'F': 639 offset++; 640 state = INIT; 641 return JavaTokenContext.FLOAT_LITERAL; 642 case 'd': 643 case 'D': 644 offset++; 645 state = INIT; 646 return JavaTokenContext.DOUBLE_LITERAL; 647 default: 648 if (!(Character.isDigit(actChar) 649 || actChar == '-' || actChar == '+')) { 650 state = INIT; 651 return JavaTokenContext.DOUBLE_LITERAL; 652 } 653 } 654 break; 655 656 case ISI_HEX: 657 if (!((actChar >= 'a' && actChar <= 'f') 658 || (actChar >= 'A' && actChar <= 'F') 659 || Character.isDigit(actChar)) 660 ) { 661 662 state = INIT; 663 return JavaTokenContext.HEX_LITERAL; 664 } 665 break; 666 667 case ISA_DOT: 668 if (Character.isDigit(actChar)) { 669 state = ISI_DOUBLE; 670 } else if (actChar == '.' && offset + 1 < stopOffset && buffer[offset + 1] == '.') { 671 offset += 2; 672 state = INIT; 673 return JavaTokenContext.ELLIPSIS; 674 } else { state = INIT; 676 return JavaTokenContext.DOT; 677 } 678 break; 679 680 } 682 offset++; 683 } 685 689 690 if (lastBuffer) { 691 switch(state) { 692 case ISI_WHITESPACE: 693 state = INIT; 694 return JavaTokenContext.WHITESPACE; 695 case ISI_IDENTIFIER: 696 state = INIT; 697 TokenID kwd = matchKeyword(buffer, tokenOffset, offset - tokenOffset); 698 return (kwd != null) ? kwd : JavaTokenContext.IDENTIFIER; 699 case ISI_LINE_COMMENT: 700 return JavaTokenContext.LINE_COMMENT; case ISI_BLOCK_COMMENT: 702 case ISA_STAR_I_BLOCK_COMMENT: 703 return JavaTokenContext.BLOCK_COMMENT; case ISI_STRING: 705 case ISI_STRING_A_BSLASH: 706 return JavaTokenContext.STRING_LITERAL; case ISI_CHAR: 708 case ISI_CHAR_A_BSLASH: 709 return JavaTokenContext.CHAR_LITERAL; case ISA_ZERO: 711 case ISI_INT: 712 state = INIT; 713 return JavaTokenContext.INT_LITERAL; 714 case ISI_OCTAL: 715 state = INIT; 716 return JavaTokenContext.OCTAL_LITERAL; 717 case ISI_DOUBLE: 718 case ISI_DOUBLE_EXP: 719 state = INIT; 720 return JavaTokenContext.DOUBLE_LITERAL; 721 case ISI_HEX: 722 state = INIT; 723 return JavaTokenContext.HEX_LITERAL; 724 case ISA_DOT: 725 state = INIT; 726 return JavaTokenContext.DOT; 727 case ISA_SLASH: 728 state = INIT; 729 return JavaTokenContext.DIV; 730 case ISA_EQ: 731 state = INIT; 732 return JavaTokenContext.EQ; 733 case ISA_GT: 734 state = INIT; 735 return JavaTokenContext.GT; 736 case ISA_GTGT: 737 state = INIT; 738 return JavaTokenContext.RSSHIFT; 739 case ISA_GTGTGT: 740 state = INIT; 741 return JavaTokenContext.RUSHIFT; 742 case ISA_LT: 743 state = INIT; 744 return JavaTokenContext.LT; 745 case ISA_LTLT: 746 state = INIT; 747 return JavaTokenContext.LSHIFT; 748 case ISA_PLUS: 749 state = INIT; 750 return JavaTokenContext.PLUS; 751 case ISA_MINUS: 752 state = INIT; 753 return JavaTokenContext.MINUS; 754 case ISA_STAR: 755 state = INIT; 756 return JavaTokenContext.MUL; 757 case ISA_PIPE: 758 state = INIT; 759 return JavaTokenContext.OR; 760 case ISA_PERCENT: 761 state = INIT; 762 return JavaTokenContext.MOD; 763 case ISA_AND: 764 state = INIT; 765 return JavaTokenContext.AND; 766 case ISA_XOR: 767 state = INIT; 768 return JavaTokenContext.XOR; 769 case ISA_EXCLAMATION: 770 state = INIT; 771 return JavaTokenContext.NOT; 772 } 773 } 774 775 781 782 switch (state) { 783 case ISI_WHITESPACE: 784 return JavaTokenContext.WHITESPACE; 785 } 786 787 return null; } 789 790 public String getStateName(int stateNumber) { 791 switch(stateNumber) { 792 case ISI_WHITESPACE: 793 return "ISI_WHITESPACE"; case ISI_LINE_COMMENT: 795 return "ISI_LINE_COMMENT"; case ISI_BLOCK_COMMENT: 797 return "ISI_BLOCK_COMMENT"; case ISI_STRING: 799 return "ISI_STRING"; case ISI_STRING_A_BSLASH: 801 return "ISI_STRING_A_BSLASH"; case ISI_CHAR: 803 return "ISI_CHAR"; case ISI_CHAR_A_BSLASH: 805 return "ISI_CHAR_A_BSLASH"; case ISI_IDENTIFIER: 807 return "ISI_IDENTIFIER"; case ISA_SLASH: 809 return "ISA_SLASH"; case ISA_EQ: 811 return "ISA_EQ"; case ISA_GT: 813 return "ISA_GT"; case ISA_GTGT: 815 return "ISA_GTGT"; case ISA_GTGTGT: 817 return "ISA_GTGTGT"; case ISA_LT: 819 return "ISA_LT"; case ISA_LTLT: 821 return "ISA_LTLT"; case ISA_PLUS: 823 return "ISA_PLUS"; case ISA_MINUS: 825 return "ISA_MINUS"; case ISA_STAR: 827 return "ISA_STAR"; case ISA_STAR_I_BLOCK_COMMENT: 829 return "ISA_STAR_I_BLOCK_COMMENT"; case ISA_PIPE: 831 return "ISA_PIPE"; case ISA_PERCENT: 833 return "ISA_PERCENT"; case ISA_AND: 835 return "ISA_AND"; case ISA_XOR: 837 return "ISA_XOR"; case ISA_EXCLAMATION: 839 return "ISA_EXCLAMATION"; case ISA_ZERO: 841 return "ISA_ZERO"; case ISI_INT: 843 return "ISI_INT"; case ISI_OCTAL: 845 return "ISI_OCTAL"; case ISI_DOUBLE: 847 return "ISI_DOUBLE"; case ISI_DOUBLE_EXP: 849 return "ISI_DOUBLE_EXP"; case ISI_HEX: 851 return "ISI_HEX"; case ISA_DOT: 853 return "ISA_DOT"; 855 default: 856 return super.getStateName(stateNumber); 857 } 858 } 859 860 public TokenID matchKeyword(char[] buffer, int offset, int len) { 861 if (len > 12) 862 return null; 863 if (len <= 1) 864 return null; 865 switch (buffer[offset++]) { 866 case 'a': 867 if (len <= 5) 868 return null; 869 switch (buffer[offset++]) { 870 case 'b': 871 return (len == 8 872 && buffer[offset++] == 's' 873 && buffer[offset++] == 't' 874 && buffer[offset++] == 'r' 875 && buffer[offset++] == 'a' 876 && buffer[offset++] == 'c' 877 && buffer[offset++] == 't') 878 ? JavaTokenContext.ABSTRACT : null; 879 case 's': 880 return (len == 6 881 && buffer[offset++] == 's' 882 && buffer[offset++] == 'e' 883 && buffer[offset++] == 'r' 884 && buffer[offset++] == 't') 885 ? JavaTokenContext.ASSERT : null; 886 default: 887 return null; 888 } 889 case 'b': 890 if (len <= 3) 891 return null; 892 switch (buffer[offset++]) { 893 case 'o': 894 return (len == 7 895 && buffer[offset++] == 'o' 896 && buffer[offset++] == 'l' 897 && buffer[offset++] == 'e' 898 && buffer[offset++] == 'a' 899 && buffer[offset++] == 'n') 900 ? JavaTokenContext.BOOLEAN : null; 901 case 'r': 902 return (len == 5 903 && buffer[offset++] == 'e' 904 && buffer[offset++] == 'a' 905 && buffer[offset++] == 'k') 906 ? JavaTokenContext.BREAK : null; 907 case 'y': 908 return (len == 4 909 && buffer[offset++] == 't' 910 && buffer[offset++] == 'e') 911 ? JavaTokenContext.BYTE : null; 912 default: 913 return null; 914 } 915 case 'c': 916 if (len <= 3) 917 return null; 918 switch (buffer[offset++]) { 919 case 'a': 920 switch (buffer[offset++]) { 921 case 's': 922 return (len == 4 923 && buffer[offset++] == 'e') 924 ? JavaTokenContext.CASE : null; 925 case 't': 926 return (len == 5 927 && buffer[offset++] == 'c' 928 && buffer[offset++] == 'h') 929 ? JavaTokenContext.CATCH : null; 930 default: 931 return null; 932 } 933 case 'h': 934 return (len == 4 935 && buffer[offset++] == 'a' 936 && buffer[offset++] == 'r') 937 ? JavaTokenContext.CHAR : null; 938 case 'l': 939 return (len == 5 940 && buffer[offset++] == 'a' 941 && buffer[offset++] == 's' 942 && buffer[offset++] == 's') 943 ? JavaTokenContext.CLASS : null; 944 case 'o': 945 if (len <= 4) 946 return null; 947 if (buffer[offset++] != 'n') 948 return null; 949 switch (buffer[offset++]) { 950 case 's': 951 return (len == 5 952 && buffer[offset++] == 't') 953 ? JavaTokenContext.CONST : null; 954 case 't': 955 return (len == 8 956 && buffer[offset++] == 'i' 957 && buffer[offset++] == 'n' 958 && buffer[offset++] == 'u' 959 && buffer[offset++] == 'e') 960 ? JavaTokenContext.CONTINUE : null; 961 default: 962 return null; 963 } 964 default: 965 return null; 966 } 967 case 'd': 968 switch (buffer[offset++]) { 969 case 'e': 970 return (len == 7 971 && buffer[offset++] == 'f' 972 && buffer[offset++] == 'a' 973 && buffer[offset++] == 'u' 974 && buffer[offset++] == 'l' 975 && buffer[offset++] == 't') 976 ? JavaTokenContext.DEFAULT : null; 977 case 'o': 978 if (len == 2) 979 return JavaTokenContext.DO; 980 switch (buffer[offset++]) { 981 case 'u': 982 return (len == 6 983 && buffer[offset++] == 'b' 984 && buffer[offset++] == 'l' 985 && buffer[offset++] == 'e') 986 ? JavaTokenContext.DOUBLE : null; 987 default: 988 return null; 989 } 990 default: 991 return null; 992 } 993 case 'e': 994 if (len <= 3) 995 return null; 996 switch (buffer[offset++]) { 997 case 'l': 998 return (len == 4 999 && buffer[offset++] == 's' 1000 && buffer[offset++] == 'e') 1001 ? JavaTokenContext.ELSE : null; 1002 case 'n': 1003 return (len == 4 1004 && buffer[offset++] == 'u' 1005 && buffer[offset++] == 'm') 1006 ? isJava15 ? JavaTokenContext.ENUM : null : null; 1007 case 'x': 1008 return (len == 7 1009 && buffer[offset++] == 't' 1010 && buffer[offset++] == 'e' 1011 && buffer[offset++] == 'n' 1012 && buffer[offset++] == 'd' 1013 && buffer[offset++] == 's') 1014 ? JavaTokenContext.EXTENDS : null; 1015 default: 1016 return null; 1017 } 1018 case 'f': 1019 if (len <= 2) 1020 return null; 1021 switch (buffer[offset++]) { 1022 case 'a': 1023 return (len == 5 1024 && buffer[offset++] == 'l' 1025 && buffer[offset++] == 's' 1026 && buffer[offset++] == 'e') 1027 ? JavaTokenContext.FALSE : null; 1028 case 'i': 1029 if (len <= 4) 1030 return null; 1031 if (buffer[offset++] != 'n' 1032 || buffer[offset++] != 'a' 1033 || buffer[offset++] != 'l') 1034 return null; 1035 if (len == 5) 1036 return JavaTokenContext.FINAL; 1037 if (len <= 6) 1038 return null; 1039 if (buffer[offset++] != 'l' 1040 || buffer[offset++] != 'y') 1041 return null; 1042 if (len == 7) 1043 return JavaTokenContext.FINALLY; 1044 return null; 1045 case 'l': 1046 return (len == 5 1047 && buffer[offset++] == 'o' 1048 && buffer[offset++] == 'a' 1049 && buffer[offset++] == 't') 1050 ? JavaTokenContext.FLOAT : null; 1051 case 'o': 1052 return (len == 3 1053 && buffer[offset++] == 'r') 1054 ? JavaTokenContext.FOR : null; 1055 default: 1056 return null; 1057 } 1058 case 'g': 1059 return (len == 4 1060 && buffer[offset++] == 'o' 1061 && buffer[offset++] == 't' 1062 && buffer[offset++] == 'o') 1063 ? JavaTokenContext.GOTO : null; 1064 case 'i': 1065 switch (buffer[offset++]) { 1066 case 'f': 1067 return (len == 2) 1068 ? JavaTokenContext.IF : null; 1069 case 'm': 1070 if (len <= 5) 1071 return null; 1072 if (buffer[offset++] != 'p') 1073 return null; 1074 switch (buffer[offset++]) { 1075 case 'l': 1076 return (len == 10 1077 && buffer[offset++] == 'e' 1078 && buffer[offset++] == 'm' 1079 && buffer[offset++] == 'e' 1080 && buffer[offset++] == 'n' 1081 && buffer[offset++] == 't' 1082 && buffer[offset++] == 's') 1083 ? JavaTokenContext.IMPLEMENTS : null; 1084 case 'o': 1085 return (len == 6 1086 && buffer[offset++] == 'r' 1087 && buffer[offset++] == 't') 1088 ? JavaTokenContext.IMPORT : null; 1089 default: 1090 return null; 1091 } 1092 case 'n': 1093 if (len <= 2) 1094 return null; 1095 switch (buffer[offset++]) { 1096 case 's': 1097 return (len == 10 1098 && buffer[offset++] == 't' 1099 && buffer[offset++] == 'a' 1100 && buffer[offset++] == 'n' 1101 && buffer[offset++] == 'c' 1102 && buffer[offset++] == 'e' 1103 && buffer[offset++] == 'o' 1104 && buffer[offset++] == 'f') 1105 ? JavaTokenContext.INSTANCEOF : null; 1106 case 't': 1107 if (len == 3) 1108 return JavaTokenContext.INT; 1109 switch (buffer[offset++]) { 1110 case 'e': 1111 return (len == 9 1112 && buffer[offset++] == 'r' 1113 && buffer[offset++] == 'f' 1114 && buffer[offset++] == 'a' 1115 && buffer[offset++] == 'c' 1116 && buffer[offset++] == 'e') 1117 ? JavaTokenContext.INTERFACE : null; 1118 default: 1119 return null; 1120 } 1121 default: 1122 return null; 1123 } 1124 default: 1125 return null; 1126 } 1127 case 'l': 1128 return (len == 4 1129 && buffer[offset++] == 'o' 1130 && buffer[offset++] == 'n' 1131 && buffer[offset++] == 'g') 1132 ? JavaTokenContext.LONG : null; 1133 case 'n': 1134 if (len <= 2) 1135 return null; 1136 switch (buffer[offset++]) { 1137 case 'a': 1138 return (len == 6 1139 && buffer[offset++] == 't' 1140 && buffer[offset++] == 'i' 1141 && buffer[offset++] == 'v' 1142 && buffer[offset++] == 'e') 1143 ? JavaTokenContext.NATIVE : null; 1144 case 'e': 1145 return (len == 3 1146 && buffer[offset++] == 'w') 1147 ? JavaTokenContext.NEW : null; 1148 case 'u': 1149 return (len == 4 1150 && buffer[offset++] == 'l' 1151 && buffer[offset++] == 'l') 1152 ? JavaTokenContext.NULL : null; 1153 default: 1154 return null; 1155 } 1156 case 'p': 1157 if (len <= 5) 1158 return null; 1159 switch (buffer[offset++]) { 1160 case 'a': 1161 return (len == 7 1162 && buffer[offset++] == 'c' 1163 && buffer[offset++] == 'k' 1164 && buffer[offset++] == 'a' 1165 && buffer[offset++] == 'g' 1166 && buffer[offset++] == 'e') 1167 ? JavaTokenContext.PACKAGE : null; 1168 case 'r': 1169 if (len <= 6) 1170 return null; 1171 switch (buffer[offset++]) { 1172 case 'i': 1173 return (len == 7 1174 && buffer[offset++] == 'v' 1175 && buffer[offset++] == 'a' 1176 && buffer[offset++] == 't' 1177 && buffer[offset++] == 'e') 1178 ? JavaTokenContext.PRIVATE : null; 1179 case 'o': 1180 return (len == 9 1181 && buffer[offset++] == 't' 1182 && buffer[offset++] == 'e' 1183 && buffer[offset++] == 'c' 1184 && buffer[offset++] == 't' 1185 && buffer[offset++] == 'e' 1186 && buffer[offset++] == 'd') 1187 ? JavaTokenContext.PROTECTED : null; 1188 default: 1189 return null; 1190 } 1191 case 'u': 1192 return (len == 6 1193 && buffer[offset++] == 'b' 1194 && buffer[offset++] == 'l' 1195 && buffer[offset++] == 'i' 1196 && buffer[offset++] == 'c') 1197 ? JavaTokenContext.PUBLIC : null; 1198 default: 1199 return null; 1200 } 1201 case 'r': 1202 return (len == 6 1203 && buffer[offset++] == 'e' 1204 && buffer[offset++] == 't' 1205 && buffer[offset++] == 'u' 1206 && buffer[offset++] == 'r' 1207 && buffer[offset++] == 'n') 1208 ? JavaTokenContext.RETURN : null; 1209 case 's': 1210 if (len <= 4) 1211 return null; 1212 switch (buffer[offset++]) { 1213 case 'h': 1214 return (len == 5 1215 && buffer[offset++] == 'o' 1216 && buffer[offset++] == 'r' 1217 && buffer[offset++] == 't') 1218 ? JavaTokenContext.SHORT : null; 1219 case 't': 1220 if (len <= 5) 1221 return null; 1222 switch (buffer[offset++]) { 1223 case 'a': 1224 return (len == 6 1225 && buffer[offset++] == 't' 1226 && buffer[offset++] == 'i' 1227 && buffer[offset++] == 'c') 1228 ? JavaTokenContext.STATIC : null; 1229 case 'r': 1230 return (len == 8 1231 && buffer[offset++] == 'i' 1232 && buffer[offset++] == 'c' 1233 && buffer[offset++] == 't' 1234 && buffer[offset++] == 'f' 1235 && buffer[offset++] == 'p') 1236 ? JavaTokenContext.STRICTFP : null; 1237 default: 1238 return null; 1239 } 1240 case 'u': 1241 return (len == 5 1242 && buffer[offset++] == 'p' 1243 && buffer[offset++] == 'e' 1244 && buffer[offset++] == 'r') 1245 ? JavaTokenContext.SUPER : null; 1246 case 'w': 1247 return (len == 6 1248 && buffer[offset++] == 'i' 1249 && buffer[offset++] == 't' 1250 && buffer[offset++] == 'c' 1251 && buffer[offset++] == 'h') 1252 ? JavaTokenContext.SWITCH : null; 1253 case 'y': 1254 return (len == 12 1255 && buffer[offset++] == 'n' 1256 && buffer[offset++] == 'c' 1257 && buffer[offset++] == 'h' 1258 && buffer[offset++] == 'r' 1259 && buffer[offset++] == 'o' 1260 && buffer[offset++] == 'n' 1261 && buffer[offset++] == 'i' 1262 && buffer[offset++] == 'z' 1263 && buffer[offset++] == 'e' 1264 && buffer[offset++] == 'd') 1265 ? JavaTokenContext.SYNCHRONIZED : null; 1266 default: 1267 return null; 1268 } 1269 case 't': 1270 if (len <= 2) 1271 return null; 1272 switch (buffer[offset++]) { 1273 case 'h': 1274 if (len <= 3) 1275 return null; 1276 switch (buffer[offset++]) { 1277 case 'i': 1278 return (len == 4 1279 && buffer[offset++] == 's') 1280 ? JavaTokenContext.THIS : null; 1281 case 'r': 1282 if (len <= 4) 1283 return null; 1284 if (buffer[offset++] != 'o' 1285 || buffer[offset++] != 'w') 1286 return null; 1287 if (len == 5) 1288 return JavaTokenContext.THROW; 1289 if (buffer[offset++] != 's') 1290 return null; 1291 if (len == 6) 1292 return JavaTokenContext.THROWS; 1293 return null; 1294 default: 1295 return null; 1296 } 1297 case 'r': 1298 switch (buffer[offset++]) { 1299 case 'a': 1300 return (len == 9 1301 && buffer[offset++] == 'n' 1302 && buffer[offset++] == 's' 1303 && buffer[offset++] == 'i' 1304 && buffer[offset++] == 'e' 1305 && buffer[offset++] == 'n' 1306 && buffer[offset++] == 't') 1307 ? JavaTokenContext.TRANSIENT : null; 1308 case 'u': 1309 return (len == 4 1310 && buffer[offset++] == 'e') 1311 ? JavaTokenContext.TRUE : null; 1312 case 'y': 1313 return (len == 3) 1314 ? JavaTokenContext.TRY : null; 1315 default: 1316 return null; 1317 } 1318 default: 1319 return null; 1320 } 1321 case 'v': 1322 if (len <= 3) 1323 return null; 1324 if (buffer[offset++] != 'o') 1325 return null; 1326 switch (buffer[offset++]) { 1327 case 'i': 1328 return (len == 4 1329 && buffer[offset++] == 'd') 1330 ? JavaTokenContext.VOID : null; 1331 case 'l': 1332 return (len == 8 1333 && buffer[offset++] == 'a' 1334 && buffer[offset++] == 't' 1335 && buffer[offset++] == 'i' 1336 && buffer[offset++] == 'l' 1337 && buffer[offset++] == 'e') 1338 ? JavaTokenContext.VOLATILE : null; 1339 default: 1340 return null; 1341 } 1342 case 'w': 1343 return (len == 5 1344 && buffer[offset++] == 'h' 1345 && buffer[offset++] == 'i' 1346 && buffer[offset++] == 'l' 1347 && buffer[offset++] == 'e') 1348 ? JavaTokenContext.WHILE : null; 1349 default: 1350 return null; 1351 } 1352 } 1353 1354} 1355 | Popular Tags |