0001: /*
0002: * Sun Public License Notice
0003: *
0004: * The contents of this file are subject to the Sun Public License
0005: * Version 1.0 (the "License"). You may not use this file except in
0006: * compliance with the License. A copy of the License is available at
0007: * http://www.sun.com/
0008: *
0009: * The Original Code is NetBeans. The Initial Developer of the Original
0010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
0011: * Microsystems, Inc. All Rights Reserved.
0012: */
0013:
0014: package org.netbeans.editor.ext.java;
0015:
0016: import org.netbeans.editor.Syntax;
0017: import org.netbeans.editor.TokenID;
0018:
0019: /**
0020: * Syntax analyzes for Java source files. Tokens and internal states are given
0021: * below.
0022: *
0023: * @author Miloslav Metelka
0024: * @version 1.00
0025: */
0026:
0027: public class JavaSyntax extends Syntax {
0028:
0029: // Internal states
0030: private static final int ISI_WHITESPACE = 2; // inside white space
0031: private static final int ISI_LINE_COMMENT = 4; // inside line comment //
0032: private static final int ISI_BLOCK_COMMENT = 5; // inside block comment /*
0033: // ... */
0034: private static final int ISI_STRING = 6; // inside string constant
0035: private static final int ISI_STRING_A_BSLASH = 7; // inside string
0036: // constant after
0037: // backslash
0038: private static final int ISI_CHAR = 8; // inside char constant
0039: private static final int ISI_CHAR_A_BSLASH = 9; // inside char constant
0040: // after backslash
0041: private static final int ISI_IDENTIFIER = 10; // inside identifier
0042: private static final int ISA_SLASH = 11; // slash char
0043: private static final int ISA_EQ = 12; // after '='
0044: private static final int ISA_GT = 13; // after '>'
0045: private static final int ISA_GTGT = 14; // after '>>'
0046: private static final int ISA_GTGTGT = 15; // after '>>>'
0047: private static final int ISA_LT = 16; // after '<'
0048: private static final int ISA_LTLT = 17; // after '<<'
0049: private static final int ISA_PLUS = 18; // after '+'
0050: private static final int ISA_MINUS = 19; // after '-'
0051: private static final int ISA_STAR = 20; // after '*'
0052: private static final int ISA_STAR_I_BLOCK_COMMENT = 21; // after '*'
0053: private static final int ISA_PIPE = 22; // after '|'
0054: private static final int ISA_PERCENT = 23; // after '%'
0055: private static final int ISA_AND = 24; // after '&'
0056: private static final int ISA_XOR = 25; // after '^'
0057: private static final int ISA_EXCLAMATION = 26; // after '!'
0058: private static final int ISA_ZERO = 27; // after '0'
0059: private static final int ISI_INT = 28; // integer number
0060: private static final int ISI_OCTAL = 29; // octal number
0061: private static final int ISI_DOUBLE = 30; // double number
0062: private static final int ISI_DOUBLE_EXP = 31; // double number
0063: private static final int ISI_HEX = 32; // hex number
0064: private static final int ISA_DOT = 33; // after '.'
0065:
0066: public JavaSyntax() {
0067: tokenContextPath = JavaTokenContext.contextPath;
0068: }
0069:
0070: protected TokenID parseToken() {
0071: char actChar;
0072:
0073: while (offset < stopOffset) {
0074: actChar = buffer[offset];
0075:
0076: switch (state) {
0077: case INIT:
0078: switch (actChar) {
0079: case '"': // NOI18N
0080: state = ISI_STRING;
0081: break;
0082: case '\'':
0083: state = ISI_CHAR;
0084: break;
0085: case '/':
0086: state = ISA_SLASH;
0087: break;
0088: case '=':
0089: state = ISA_EQ;
0090: break;
0091: case '>':
0092: state = ISA_GT;
0093: break;
0094: case '<':
0095: state = ISA_LT;
0096: break;
0097: case '+':
0098: state = ISA_PLUS;
0099: break;
0100: case '-':
0101: state = ISA_MINUS;
0102: break;
0103: case '*':
0104: state = ISA_STAR;
0105: break;
0106: case '|':
0107: state = ISA_PIPE;
0108: break;
0109: case '%':
0110: state = ISA_PERCENT;
0111: break;
0112: case '&':
0113: state = ISA_AND;
0114: break;
0115: case '^':
0116: state = ISA_XOR;
0117: break;
0118: case '~':
0119: offset++;
0120: return JavaTokenContext.NEG;
0121: case '!':
0122: state = ISA_EXCLAMATION;
0123: break;
0124: case '0':
0125: state = ISA_ZERO;
0126: break;
0127: case '.':
0128: state = ISA_DOT;
0129: break;
0130: case ',':
0131: offset++;
0132: return JavaTokenContext.COMMA;
0133: case ';':
0134: offset++;
0135: return JavaTokenContext.SEMICOLON;
0136: case ':':
0137: offset++;
0138: return JavaTokenContext.COLON;
0139: case '?':
0140: offset++;
0141: return JavaTokenContext.QUESTION;
0142: case '(':
0143: offset++;
0144: return JavaTokenContext.LPAREN;
0145: case ')':
0146: offset++;
0147: return JavaTokenContext.RPAREN;
0148: case '[':
0149: offset++;
0150: return JavaTokenContext.LBRACKET;
0151: case ']':
0152: offset++;
0153: return JavaTokenContext.RBRACKET;
0154: case '{':
0155: offset++;
0156: return JavaTokenContext.LBRACE;
0157: case '}':
0158: offset++;
0159: return JavaTokenContext.RBRACE;
0160:
0161: default:
0162: // Check for whitespace
0163: if (Character.isWhitespace(actChar)) {
0164: state = ISI_WHITESPACE;
0165: break;
0166: }
0167:
0168: // Check for digit
0169: if (Character.isDigit(actChar)) {
0170: state = ISI_INT;
0171: break;
0172: }
0173:
0174: // Check for identifier
0175: if (Character.isJavaIdentifierStart(actChar)) {
0176: state = ISI_IDENTIFIER;
0177: break;
0178: }
0179:
0180: offset++;
0181: return JavaTokenContext.INVALID_CHAR;
0182: }
0183: break;
0184:
0185: case ISI_WHITESPACE: // white space
0186: if (!Character.isWhitespace(actChar)) {
0187: state = INIT;
0188: return JavaTokenContext.WHITESPACE;
0189: }
0190: break;
0191:
0192: case ISI_LINE_COMMENT:
0193: switch (actChar) {
0194: case '\n':
0195: state = INIT;
0196: return JavaTokenContext.LINE_COMMENT;
0197: }
0198: break;
0199:
0200: case ISI_BLOCK_COMMENT:
0201: switch (actChar) {
0202: case '*':
0203: state = ISA_STAR_I_BLOCK_COMMENT;
0204: break;
0205: }
0206: break;
0207:
0208: case ISI_STRING:
0209: switch (actChar) {
0210: case '\\':
0211: state = ISI_STRING_A_BSLASH;
0212: break;
0213: case '\n':
0214: state = INIT;
0215: supposedTokenID = JavaTokenContext.STRING_LITERAL;
0216: // !!! return JavaTokenContext.INCOMPLETE_STRING_LITERAL;
0217: return supposedTokenID;
0218: case '"': // NOI18N
0219: offset++;
0220: state = INIT;
0221: return JavaTokenContext.STRING_LITERAL;
0222: }
0223: break;
0224:
0225: case ISI_STRING_A_BSLASH:
0226: switch (actChar) {
0227: case '"': // NOI18N
0228: case '\\':
0229: break;
0230: default:
0231: offset--;
0232: break;
0233: }
0234: state = ISI_STRING;
0235: break;
0236:
0237: case ISI_CHAR:
0238: switch (actChar) {
0239: case '\\':
0240: state = ISI_CHAR_A_BSLASH;
0241: break;
0242: case '\n':
0243: state = INIT;
0244: supposedTokenID = JavaTokenContext.CHAR_LITERAL;
0245: // !!! return JavaTokenContext.INCOMPLETE_CHAR_LITERAL;
0246: return supposedTokenID;
0247: case '\'':
0248: offset++;
0249: state = INIT;
0250: return JavaTokenContext.CHAR_LITERAL;
0251: }
0252: break;
0253:
0254: case ISI_CHAR_A_BSLASH:
0255: switch (actChar) {
0256: case '\'':
0257: case '\\':
0258: break;
0259: default:
0260: offset--;
0261: break;
0262: }
0263: state = ISI_CHAR;
0264: break;
0265:
0266: case ISI_IDENTIFIER:
0267: if (!(Character.isJavaIdentifierPart(actChar))) {
0268: state = INIT;
0269: TokenID tid = matchKeyword(buffer, tokenOffset,
0270: offset - tokenOffset);
0271: return (tid != null) ? tid
0272: : JavaTokenContext.IDENTIFIER;
0273: }
0274: break;
0275:
0276: case ISA_SLASH:
0277: switch (actChar) {
0278: case '=':
0279: offset++;
0280: state = INIT;
0281: return JavaTokenContext.DIV_EQ;
0282: case '/':
0283: state = ISI_LINE_COMMENT;
0284: break;
0285: case '*':
0286: state = ISI_BLOCK_COMMENT;
0287: break;
0288: default:
0289: state = INIT;
0290: return JavaTokenContext.DIV;
0291: }
0292: break;
0293:
0294: case ISA_EQ:
0295: switch (actChar) {
0296: case '=':
0297: offset++;
0298: return JavaTokenContext.EQ_EQ;
0299: default:
0300: state = INIT;
0301: return JavaTokenContext.EQ;
0302: }
0303: // break;
0304:
0305: case ISA_GT:
0306: switch (actChar) {
0307: case '>':
0308: state = ISA_GTGT;
0309: break;
0310: case '=':
0311: offset++;
0312: return JavaTokenContext.GT_EQ;
0313: default:
0314: state = INIT;
0315: return JavaTokenContext.GT;
0316: }
0317: break;
0318:
0319: case ISA_GTGT:
0320: switch (actChar) {
0321: case '>':
0322: state = ISA_GTGTGT;
0323: break;
0324: case '=':
0325: offset++;
0326: return JavaTokenContext.RSSHIFT_EQ;
0327: default:
0328: state = INIT;
0329: return JavaTokenContext.RSSHIFT;
0330: }
0331: break;
0332:
0333: case ISA_GTGTGT:
0334: switch (actChar) {
0335: case '=':
0336: offset++;
0337: return JavaTokenContext.RUSHIFT_EQ;
0338: default:
0339: state = INIT;
0340: return JavaTokenContext.RUSHIFT;
0341: }
0342: // break;
0343:
0344: case ISA_LT:
0345: switch (actChar) {
0346: case '<':
0347: state = ISA_LTLT;
0348: break;
0349: case '=':
0350: offset++;
0351: return JavaTokenContext.LT_EQ;
0352: default:
0353: state = INIT;
0354: return JavaTokenContext.LT;
0355: }
0356: break;
0357:
0358: case ISA_LTLT:
0359: switch (actChar) {
0360: case '<':
0361: state = INIT;
0362: offset++;
0363: return JavaTokenContext.INVALID_OPERATOR;
0364: case '=':
0365: offset++;
0366: return JavaTokenContext.LSHIFT_EQ;
0367: default:
0368: state = INIT;
0369: return JavaTokenContext.LSHIFT;
0370: }
0371:
0372: case ISA_PLUS:
0373: switch (actChar) {
0374: case '+':
0375: offset++;
0376: return JavaTokenContext.PLUS_PLUS;
0377: case '=':
0378: offset++;
0379: return JavaTokenContext.PLUS_EQ;
0380: default:
0381: state = INIT;
0382: return JavaTokenContext.PLUS;
0383: }
0384:
0385: case ISA_MINUS:
0386: switch (actChar) {
0387: case '-':
0388: offset++;
0389: return JavaTokenContext.MINUS_MINUS;
0390: case '=':
0391: offset++;
0392: return JavaTokenContext.MINUS_EQ;
0393: default:
0394: state = INIT;
0395: return JavaTokenContext.MINUS;
0396: }
0397:
0398: case ISA_STAR:
0399: switch (actChar) {
0400: case '=':
0401: offset++;
0402: return JavaTokenContext.MUL_EQ;
0403: case '/':
0404: offset++;
0405: state = INIT;
0406: return JavaTokenContext.INVALID_COMMENT_END; // '*/'
0407: // outside
0408: // comment
0409: default:
0410: state = INIT;
0411: return JavaTokenContext.MUL;
0412: }
0413:
0414: case ISA_STAR_I_BLOCK_COMMENT:
0415: switch (actChar) {
0416: case '/':
0417: offset++;
0418: state = INIT;
0419: return JavaTokenContext.BLOCK_COMMENT;
0420: default:
0421: offset--;
0422: state = ISI_BLOCK_COMMENT;
0423: break;
0424: }
0425: break;
0426:
0427: case ISA_PIPE:
0428: switch (actChar) {
0429: case '=':
0430: offset++;
0431: state = INIT;
0432: return JavaTokenContext.OR_EQ;
0433: case '|':
0434: offset++;
0435: state = INIT;
0436: return JavaTokenContext.OR_OR;
0437: default:
0438: state = INIT;
0439: return JavaTokenContext.OR;
0440: }
0441: // break;
0442:
0443: case ISA_PERCENT:
0444: switch (actChar) {
0445: case '=':
0446: offset++;
0447: state = INIT;
0448: return JavaTokenContext.MOD_EQ;
0449: default:
0450: state = INIT;
0451: return JavaTokenContext.MOD;
0452: }
0453: // break;
0454:
0455: case ISA_AND:
0456: switch (actChar) {
0457: case '=':
0458: offset++;
0459: state = INIT;
0460: return JavaTokenContext.AND_EQ;
0461: case '&':
0462: offset++;
0463: state = INIT;
0464: return JavaTokenContext.AND_AND;
0465: default:
0466: state = INIT;
0467: return JavaTokenContext.AND;
0468: }
0469: // break;
0470:
0471: case ISA_XOR:
0472: switch (actChar) {
0473: case '=':
0474: offset++;
0475: state = INIT;
0476: return JavaTokenContext.XOR_EQ;
0477: default:
0478: state = INIT;
0479: return JavaTokenContext.XOR;
0480: }
0481: // break;
0482:
0483: case ISA_EXCLAMATION:
0484: switch (actChar) {
0485: case '=':
0486: offset++;
0487: state = INIT;
0488: return JavaTokenContext.NOT_EQ;
0489: default:
0490: state = INIT;
0491: return JavaTokenContext.NOT;
0492: }
0493: // break;
0494:
0495: case ISA_ZERO:
0496: switch (actChar) {
0497: case '.':
0498: state = ISI_DOUBLE;
0499: break;
0500: case 'x':
0501: case 'X':
0502: state = ISI_HEX;
0503: break;
0504: case 'l':
0505: case 'L':
0506: offset++;
0507: state = INIT;
0508: return JavaTokenContext.LONG_LITERAL;
0509: case 'f':
0510: case 'F':
0511: offset++;
0512: state = INIT;
0513: return JavaTokenContext.FLOAT_LITERAL;
0514: case 'd':
0515: case 'D':
0516: offset++;
0517: state = INIT;
0518: return JavaTokenContext.DOUBLE_LITERAL;
0519: case '8': // it's error to have '8' and '9' in octal number
0520: case '9':
0521: state = INIT;
0522: offset++;
0523: return JavaTokenContext.INVALID_OCTAL_LITERAL;
0524: case 'e':
0525: case 'E':
0526: state = ISI_DOUBLE_EXP;
0527: break;
0528: default:
0529: if (Character.isDigit(actChar)) { // '8' and '9' already
0530: // handled
0531: state = ISI_OCTAL;
0532: break;
0533: }
0534: state = INIT;
0535: return JavaTokenContext.INT_LITERAL;
0536: }
0537: break;
0538:
0539: case ISI_INT:
0540: switch (actChar) {
0541: case 'l':
0542: case 'L':
0543: offset++;
0544: state = INIT;
0545: return JavaTokenContext.LONG_LITERAL;
0546: case '.':
0547: state = ISI_DOUBLE;
0548: break;
0549: case 'f':
0550: case 'F':
0551: offset++;
0552: state = INIT;
0553: return JavaTokenContext.FLOAT_LITERAL;
0554: case 'd':
0555: case 'D':
0556: offset++;
0557: state = INIT;
0558: return JavaTokenContext.DOUBLE_LITERAL;
0559: case 'e':
0560: case 'E':
0561: state = ISI_DOUBLE_EXP;
0562: break;
0563: default:
0564: if (!(actChar >= '0' && actChar <= '9')) {
0565: state = INIT;
0566: return JavaTokenContext.INT_LITERAL;
0567: }
0568: }
0569: break;
0570:
0571: case ISI_OCTAL:
0572: if (!(actChar >= '0' && actChar <= '7')) {
0573:
0574: state = INIT;
0575: return JavaTokenContext.OCTAL_LITERAL;
0576: }
0577: break;
0578:
0579: case ISI_DOUBLE:
0580: switch (actChar) {
0581: case 'f':
0582: case 'F':
0583: offset++;
0584: state = INIT;
0585: return JavaTokenContext.FLOAT_LITERAL;
0586: case 'd':
0587: case 'D':
0588: offset++;
0589: state = INIT;
0590: return JavaTokenContext.DOUBLE_LITERAL;
0591: case 'e':
0592: case 'E':
0593: state = ISI_DOUBLE_EXP;
0594: break;
0595: default:
0596: if (!((actChar >= '0' && actChar <= '9') || actChar == '.')) {
0597:
0598: state = INIT;
0599: return JavaTokenContext.DOUBLE_LITERAL;
0600: }
0601: }
0602: break;
0603:
0604: case ISI_DOUBLE_EXP:
0605: switch (actChar) {
0606: case 'f':
0607: case 'F':
0608: offset++;
0609: state = INIT;
0610: return JavaTokenContext.FLOAT_LITERAL;
0611: case 'd':
0612: case 'D':
0613: offset++;
0614: state = INIT;
0615: return JavaTokenContext.DOUBLE_LITERAL;
0616: default:
0617: if (!(Character.isDigit(actChar) || actChar == '-' || actChar == '+')) {
0618: state = INIT;
0619: return JavaTokenContext.DOUBLE_LITERAL;
0620: }
0621: }
0622: break;
0623:
0624: case ISI_HEX:
0625: if (!((actChar >= 'a' && actChar <= 'f')
0626: || (actChar >= 'A' && actChar <= 'F') || Character
0627: .isDigit(actChar))) {
0628:
0629: state = INIT;
0630: return JavaTokenContext.HEX_LITERAL;
0631: }
0632: break;
0633:
0634: case ISA_DOT:
0635: if (Character.isDigit(actChar)) {
0636: state = ISI_DOUBLE;
0637:
0638: } else { // only single dot
0639: state = INIT;
0640: return JavaTokenContext.DOT;
0641: }
0642: break;
0643:
0644: } // end of switch(state)
0645:
0646: offset++;
0647: } // end of while(offset...)
0648:
0649: /**
0650: * At this stage there's no more text in the scanned buffer. Scanner
0651: * first checks whether this is completely the last available buffer.
0652: */
0653:
0654: if (lastBuffer) {
0655: switch (state) {
0656: case ISI_WHITESPACE:
0657: state = INIT;
0658: return JavaTokenContext.WHITESPACE;
0659: case ISI_IDENTIFIER:
0660: state = INIT;
0661: TokenID kwd = matchKeyword(buffer, tokenOffset, offset
0662: - tokenOffset);
0663: return (kwd != null) ? kwd
0664: : JavaTokenContext.IDENTIFIER;
0665: case ISI_LINE_COMMENT:
0666: return JavaTokenContext.LINE_COMMENT; // stay in line-comment
0667: // state
0668: case ISI_BLOCK_COMMENT:
0669: case ISA_STAR_I_BLOCK_COMMENT:
0670: return JavaTokenContext.BLOCK_COMMENT; // stay in block-comment
0671: // state
0672: case ISI_STRING:
0673: case ISI_STRING_A_BSLASH:
0674: return JavaTokenContext.STRING_LITERAL; // hold the state
0675: case ISI_CHAR:
0676: case ISI_CHAR_A_BSLASH:
0677: return JavaTokenContext.CHAR_LITERAL; // hold the state
0678: case ISA_ZERO:
0679: case ISI_INT:
0680: state = INIT;
0681: return JavaTokenContext.INT_LITERAL;
0682: case ISI_OCTAL:
0683: state = INIT;
0684: return JavaTokenContext.OCTAL_LITERAL;
0685: case ISI_DOUBLE:
0686: case ISI_DOUBLE_EXP:
0687: state = INIT;
0688: return JavaTokenContext.DOUBLE_LITERAL;
0689: case ISI_HEX:
0690: state = INIT;
0691: return JavaTokenContext.HEX_LITERAL;
0692: case ISA_DOT:
0693: state = INIT;
0694: return JavaTokenContext.DOT;
0695: case ISA_SLASH:
0696: state = INIT;
0697: return JavaTokenContext.DIV;
0698: case ISA_EQ:
0699: state = INIT;
0700: return JavaTokenContext.EQ;
0701: case ISA_GT:
0702: state = INIT;
0703: return JavaTokenContext.GT;
0704: case ISA_GTGT:
0705: state = INIT;
0706: return JavaTokenContext.RSSHIFT;
0707: case ISA_GTGTGT:
0708: state = INIT;
0709: return JavaTokenContext.RUSHIFT;
0710: case ISA_LT:
0711: state = INIT;
0712: return JavaTokenContext.LT;
0713: case ISA_LTLT:
0714: state = INIT;
0715: return JavaTokenContext.LSHIFT;
0716: case ISA_PLUS:
0717: state = INIT;
0718: return JavaTokenContext.PLUS;
0719: case ISA_MINUS:
0720: state = INIT;
0721: return JavaTokenContext.MINUS;
0722: case ISA_STAR:
0723: state = INIT;
0724: return JavaTokenContext.MUL;
0725: case ISA_PIPE:
0726: state = INIT;
0727: return JavaTokenContext.OR;
0728: case ISA_PERCENT:
0729: state = INIT;
0730: return JavaTokenContext.MOD;
0731: case ISA_AND:
0732: state = INIT;
0733: return JavaTokenContext.AND;
0734: case ISA_XOR:
0735: state = INIT;
0736: return JavaTokenContext.XOR;
0737: case ISA_EXCLAMATION:
0738: state = INIT;
0739: return JavaTokenContext.NOT;
0740: }
0741: }
0742:
0743: /*
0744: * At this stage there's no more text in the scanned buffer, but this
0745: * buffer is not the last so the scan will continue on another buffer.
0746: * The scanner tries to minimize the amount of characters that will be
0747: * prescanned in the next buffer by returning the token where possible.
0748: */
0749:
0750: switch (state) {
0751: case ISI_WHITESPACE:
0752: return JavaTokenContext.WHITESPACE;
0753: }
0754:
0755: return null; // nothing found
0756: }
0757:
0758: public String getStateName(int stateNumber) {
0759: switch (stateNumber) {
0760: case ISI_WHITESPACE:
0761: return "ISI_WHITESPACE"; // NOI18N
0762: case ISI_LINE_COMMENT:
0763: return "ISI_LINE_COMMENT"; // NOI18N
0764: case ISI_BLOCK_COMMENT:
0765: return "ISI_BLOCK_COMMENT"; // NOI18N
0766: case ISI_STRING:
0767: return "ISI_STRING"; // NOI18N
0768: case ISI_STRING_A_BSLASH:
0769: return "ISI_STRING_A_BSLASH"; // NOI18N
0770: case ISI_CHAR:
0771: return "ISI_CHAR"; // NOI18N
0772: case ISI_CHAR_A_BSLASH:
0773: return "ISI_CHAR_A_BSLASH"; // NOI18N
0774: case ISI_IDENTIFIER:
0775: return "ISI_IDENTIFIER"; // NOI18N
0776: case ISA_SLASH:
0777: return "ISA_SLASH"; // NOI18N
0778: case ISA_EQ:
0779: return "ISA_EQ"; // NOI18N
0780: case ISA_GT:
0781: return "ISA_GT"; // NOI18N
0782: case ISA_GTGT:
0783: return "ISA_GTGT"; // NOI18N
0784: case ISA_GTGTGT:
0785: return "ISA_GTGTGT"; // NOI18N
0786: case ISA_LT:
0787: return "ISA_LT"; // NOI18N
0788: case ISA_LTLT:
0789: return "ISA_LTLT"; // NOI18N
0790: case ISA_PLUS:
0791: return "ISA_PLUS"; // NOI18N
0792: case ISA_MINUS:
0793: return "ISA_MINUS"; // NOI18N
0794: case ISA_STAR:
0795: return "ISA_STAR"; // NOI18N
0796: case ISA_STAR_I_BLOCK_COMMENT:
0797: return "ISA_STAR_I_BLOCK_COMMENT"; // NOI18N
0798: case ISA_PIPE:
0799: return "ISA_PIPE"; // NOI18N
0800: case ISA_PERCENT:
0801: return "ISA_PERCENT"; // NOI18N
0802: case ISA_AND:
0803: return "ISA_AND"; // NOI18N
0804: case ISA_XOR:
0805: return "ISA_XOR"; // NOI18N
0806: case ISA_EXCLAMATION:
0807: return "ISA_EXCLAMATION"; // NOI18N
0808: case ISA_ZERO:
0809: return "ISA_ZERO"; // NOI18N
0810: case ISI_INT:
0811: return "ISI_INT"; // NOI18N
0812: case ISI_OCTAL:
0813: return "ISI_OCTAL"; // NOI18N
0814: case ISI_DOUBLE:
0815: return "ISI_DOUBLE"; // NOI18N
0816: case ISI_DOUBLE_EXP:
0817: return "ISI_DOUBLE_EXP"; // NOI18N
0818: case ISI_HEX:
0819: return "ISI_HEX"; // NOI18N
0820: case ISA_DOT:
0821: return "ISA_DOT"; // NOI18N
0822:
0823: default:
0824: return super .getStateName(stateNumber);
0825: }
0826: }
0827:
0828: public static TokenID matchKeyword(char[] buffer, int offset,
0829: int len) {
0830: if (len > 12)
0831: return null;
0832: if (len <= 1)
0833: return null;
0834: switch (buffer[offset++]) {
0835: case 'a':
0836: return (len == 8 && buffer[offset++] == 'b'
0837: && buffer[offset++] == 's'
0838: && buffer[offset++] == 't'
0839: && buffer[offset++] == 'r'
0840: && buffer[offset++] == 'a'
0841: && buffer[offset++] == 'c' && buffer[offset++] == 't') ? JavaTokenContext.ABSTRACT
0842: : null;
0843: case 'b':
0844: if (len <= 3)
0845: return null;
0846: switch (buffer[offset++]) {
0847: case 'o':
0848: return (len == 7 && buffer[offset++] == 'o'
0849: && buffer[offset++] == 'l'
0850: && buffer[offset++] == 'e'
0851: && buffer[offset++] == 'a' && buffer[offset++] == 'n') ? JavaTokenContext.BOOLEAN
0852: : null;
0853: case 'r':
0854: return (len == 5 && buffer[offset++] == 'e'
0855: && buffer[offset++] == 'a' && buffer[offset++] == 'k') ? JavaTokenContext.BREAK
0856: : null;
0857: case 'y':
0858: return (len == 4 && buffer[offset++] == 't' && buffer[offset++] == 'e') ? JavaTokenContext.BYTE
0859: : null;
0860: default:
0861: return null;
0862: }
0863: case 'c':
0864: if (len <= 3)
0865: return null;
0866: switch (buffer[offset++]) {
0867: case 'a':
0868: switch (buffer[offset++]) {
0869: case 's':
0870: return (len == 4 && buffer[offset++] == 'e') ? JavaTokenContext.CASE
0871: : null;
0872: case 't':
0873: return (len == 5 && buffer[offset++] == 'c' && buffer[offset++] == 'h') ? JavaTokenContext.CATCH
0874: : null;
0875: default:
0876: return null;
0877: }
0878: case 'h':
0879: return (len == 4 && buffer[offset++] == 'a' && buffer[offset++] == 'r') ? JavaTokenContext.CHAR
0880: : null;
0881: case 'l':
0882: return (len == 5 && buffer[offset++] == 'a'
0883: && buffer[offset++] == 's' && buffer[offset++] == 's') ? JavaTokenContext.CLASS
0884: : null;
0885: case 'o':
0886: if (len <= 4)
0887: return null;
0888: if (buffer[offset++] != 'n')
0889: return null;
0890: switch (buffer[offset++]) {
0891: case 's':
0892: return (len == 5 && buffer[offset++] == 't') ? JavaTokenContext.CONST
0893: : null;
0894: case 't':
0895: return (len == 8 && buffer[offset++] == 'i'
0896: && buffer[offset++] == 'n'
0897: && buffer[offset++] == 'u' && buffer[offset++] == 'e') ? JavaTokenContext.CONTINUE
0898: : null;
0899: default:
0900: return null;
0901: }
0902: default:
0903: return null;
0904: }
0905: case 'd':
0906: switch (buffer[offset++]) {
0907: case 'e':
0908: return (len == 7 && buffer[offset++] == 'f'
0909: && buffer[offset++] == 'a'
0910: && buffer[offset++] == 'u'
0911: && buffer[offset++] == 'l' && buffer[offset++] == 't') ? JavaTokenContext.DEFAULT
0912: : null;
0913: case 'o':
0914: if (len == 2)
0915: return JavaTokenContext.DO;
0916: switch (buffer[offset++]) {
0917: case 'u':
0918: return (len == 6 && buffer[offset++] == 'b'
0919: && buffer[offset++] == 'l' && buffer[offset++] == 'e') ? JavaTokenContext.DOUBLE
0920: : null;
0921: default:
0922: return null;
0923: }
0924: default:
0925: return null;
0926: }
0927: case 'e':
0928: if (len <= 3)
0929: return null;
0930: switch (buffer[offset++]) {
0931: case 'l':
0932: return (len == 4 && buffer[offset++] == 's' && buffer[offset++] == 'e') ? JavaTokenContext.ELSE
0933: : null;
0934: case 'x':
0935: return (len == 7 && buffer[offset++] == 't'
0936: && buffer[offset++] == 'e'
0937: && buffer[offset++] == 'n'
0938: && buffer[offset++] == 'd' && buffer[offset++] == 's') ? JavaTokenContext.EXTENDS
0939: : null;
0940: default:
0941: return null;
0942: }
0943: case 'f':
0944: if (len <= 2)
0945: return null;
0946: switch (buffer[offset++]) {
0947: case 'a':
0948: return (len == 5 && buffer[offset++] == 'l'
0949: && buffer[offset++] == 's' && buffer[offset++] == 'e') ? JavaTokenContext.FALSE
0950: : null;
0951: case 'i':
0952: if (len <= 4)
0953: return null;
0954: if (buffer[offset++] != 'n' || buffer[offset++] != 'a'
0955: || buffer[offset++] != 'l')
0956: return null;
0957: if (len == 5)
0958: return JavaTokenContext.FINAL;
0959: if (len <= 6)
0960: return null;
0961: if (buffer[offset++] != 'l' || buffer[offset++] != 'y')
0962: return null;
0963: if (len == 7)
0964: return JavaTokenContext.FINALLY;
0965: return null;
0966: case 'l':
0967: return (len == 5 && buffer[offset++] == 'o'
0968: && buffer[offset++] == 'a' && buffer[offset++] == 't') ? JavaTokenContext.FLOAT
0969: : null;
0970: case 'o':
0971: return (len == 3 && buffer[offset++] == 'r') ? JavaTokenContext.FOR
0972: : null;
0973: default:
0974: return null;
0975: }
0976: case 'g':
0977: return (len == 4 && buffer[offset++] == 'o'
0978: && buffer[offset++] == 't' && buffer[offset++] == 'o') ? JavaTokenContext.GOTO
0979: : null;
0980: case 'i':
0981: switch (buffer[offset++]) {
0982: case 'f':
0983: return (len == 2) ? JavaTokenContext.IF : null;
0984: case 'm':
0985: if (len <= 5)
0986: return null;
0987: if (buffer[offset++] != 'p')
0988: return null;
0989: switch (buffer[offset++]) {
0990: case 'l':
0991: return (len == 10 && buffer[offset++] == 'e'
0992: && buffer[offset++] == 'm'
0993: && buffer[offset++] == 'e'
0994: && buffer[offset++] == 'n'
0995: && buffer[offset++] == 't' && buffer[offset++] == 's') ? JavaTokenContext.IMPLEMENTS
0996: : null;
0997: case 'o':
0998: return (len == 6 && buffer[offset++] == 'r' && buffer[offset++] == 't') ? JavaTokenContext.IMPORT
0999: : null;
1000: default:
1001: return null;
1002: }
1003: case 'n':
1004: if (len <= 2)
1005: return null;
1006: switch (buffer[offset++]) {
1007: case 's':
1008: return (len == 10 && buffer[offset++] == 't'
1009: && buffer[offset++] == 'a'
1010: && buffer[offset++] == 'n'
1011: && buffer[offset++] == 'c'
1012: && buffer[offset++] == 'e'
1013: && buffer[offset++] == 'o' && buffer[offset++] == 'f') ? JavaTokenContext.INSTANCEOF
1014: : null;
1015: case 't':
1016: if (len == 3)
1017: return JavaTokenContext.INT;
1018: switch (buffer[offset++]) {
1019: case 'e':
1020: return (len == 9 && buffer[offset++] == 'r'
1021: && buffer[offset++] == 'f'
1022: && buffer[offset++] == 'a'
1023: && buffer[offset++] == 'c' && buffer[offset++] == 'e') ? JavaTokenContext.INTERFACE
1024: : null;
1025: default:
1026: return null;
1027: }
1028: default:
1029: return null;
1030: }
1031: default:
1032: return null;
1033: }
1034: case 'l':
1035: return (len == 4 && buffer[offset++] == 'o'
1036: && buffer[offset++] == 'n' && buffer[offset++] == 'g') ? JavaTokenContext.LONG
1037: : null;
1038: case 'n':
1039: if (len <= 2)
1040: return null;
1041: switch (buffer[offset++]) {
1042: case 'a':
1043: return (len == 6 && buffer[offset++] == 't'
1044: && buffer[offset++] == 'i'
1045: && buffer[offset++] == 'v' && buffer[offset++] == 'e') ? JavaTokenContext.NATIVE
1046: : null;
1047: case 'e':
1048: return (len == 3 && buffer[offset++] == 'w') ? JavaTokenContext.NEW
1049: : null;
1050: case 'u':
1051: return (len == 4 && buffer[offset++] == 'l' && buffer[offset++] == 'l') ? JavaTokenContext.NULL
1052: : null;
1053: default:
1054: return null;
1055: }
1056: case 'p':
1057: if (len <= 5)
1058: return null;
1059: switch (buffer[offset++]) {
1060: case 'a':
1061: return (len == 7 && buffer[offset++] == 'c'
1062: && buffer[offset++] == 'k'
1063: && buffer[offset++] == 'a'
1064: && buffer[offset++] == 'g' && buffer[offset++] == 'e') ? JavaTokenContext.PACKAGE
1065: : null;
1066: case 'r':
1067: if (len <= 6)
1068: return null;
1069: switch (buffer[offset++]) {
1070: case 'i':
1071: return (len == 7 && buffer[offset++] == 'v'
1072: && buffer[offset++] == 'a'
1073: && buffer[offset++] == 't' && buffer[offset++] == 'e') ? JavaTokenContext.PRIVATE
1074: : null;
1075: case 'o':
1076: return (len == 9 && buffer[offset++] == 't'
1077: && buffer[offset++] == 'e'
1078: && buffer[offset++] == 'c'
1079: && buffer[offset++] == 't'
1080: && buffer[offset++] == 'e' && buffer[offset++] == 'd') ? JavaTokenContext.PROTECTED
1081: : null;
1082: default:
1083: return null;
1084: }
1085: case 'u':
1086: return (len == 6 && buffer[offset++] == 'b'
1087: && buffer[offset++] == 'l'
1088: && buffer[offset++] == 'i' && buffer[offset++] == 'c') ? JavaTokenContext.PUBLIC
1089: : null;
1090: default:
1091: return null;
1092: }
1093: case 'r':
1094: return (len == 6 && buffer[offset++] == 'e'
1095: && buffer[offset++] == 't'
1096: && buffer[offset++] == 'u'
1097: && buffer[offset++] == 'r' && buffer[offset++] == 'n') ? JavaTokenContext.RETURN
1098: : null;
1099: case 's':
1100: if (len <= 4)
1101: return null;
1102: switch (buffer[offset++]) {
1103: case 'h':
1104: return (len == 5 && buffer[offset++] == 'o'
1105: && buffer[offset++] == 'r' && buffer[offset++] == 't') ? JavaTokenContext.SHORT
1106: : null;
1107: case 't':
1108: if (len <= 5)
1109: return null;
1110: switch (buffer[offset++]) {
1111: case 'a':
1112: return (len == 6 && buffer[offset++] == 't'
1113: && buffer[offset++] == 'i' && buffer[offset++] == 'c') ? JavaTokenContext.STATIC
1114: : null;
1115: case 'r':
1116: return (len == 8 && buffer[offset++] == 'i'
1117: && buffer[offset++] == 'c'
1118: && buffer[offset++] == 't'
1119: && buffer[offset++] == 'f' && buffer[offset++] == 'p') ? JavaTokenContext.STRICTFP
1120: : null;
1121: default:
1122: return null;
1123: }
1124: case 'u':
1125: return (len == 5 && buffer[offset++] == 'p'
1126: && buffer[offset++] == 'e' && buffer[offset++] == 'r') ? JavaTokenContext.SUPER
1127: : null;
1128: case 'w':
1129: return (len == 6 && buffer[offset++] == 'i'
1130: && buffer[offset++] == 't'
1131: && buffer[offset++] == 'c' && buffer[offset++] == 'h') ? JavaTokenContext.SWITCH
1132: : null;
1133: case 'y':
1134: return (len == 12 && buffer[offset++] == 'n'
1135: && buffer[offset++] == 'c'
1136: && buffer[offset++] == 'h'
1137: && buffer[offset++] == 'r'
1138: && buffer[offset++] == 'o'
1139: && buffer[offset++] == 'n'
1140: && buffer[offset++] == 'i'
1141: && buffer[offset++] == 'z'
1142: && buffer[offset++] == 'e' && buffer[offset++] == 'd') ? JavaTokenContext.SYNCHRONIZED
1143: : null;
1144: default:
1145: return null;
1146: }
1147: case 't':
1148: if (len <= 2)
1149: return null;
1150: switch (buffer[offset++]) {
1151: case 'h':
1152: if (len <= 3)
1153: return null;
1154: switch (buffer[offset++]) {
1155: case 'i':
1156: return (len == 4 && buffer[offset++] == 's') ? JavaTokenContext.THIS
1157: : null;
1158: case 'r':
1159: if (len <= 4)
1160: return null;
1161: if (buffer[offset++] != 'o'
1162: || buffer[offset++] != 'w')
1163: return null;
1164: if (len == 5)
1165: return JavaTokenContext.THROW;
1166: if (buffer[offset++] != 's')
1167: return null;
1168: if (len == 6)
1169: return JavaTokenContext.THROWS;
1170: return null;
1171: default:
1172: return null;
1173: }
1174: case 'r':
1175: switch (buffer[offset++]) {
1176: case 'a':
1177: return (len == 9 && buffer[offset++] == 'n'
1178: && buffer[offset++] == 's'
1179: && buffer[offset++] == 'i'
1180: && buffer[offset++] == 'e'
1181: && buffer[offset++] == 'n' && buffer[offset++] == 't') ? JavaTokenContext.TRANSIENT
1182: : null;
1183: case 'u':
1184: return (len == 4 && buffer[offset++] == 'e') ? JavaTokenContext.TRUE
1185: : null;
1186: case 'y':
1187: return (len == 3) ? JavaTokenContext.TRY : null;
1188: default:
1189: return null;
1190: }
1191: default:
1192: return null;
1193: }
1194: case 'v':
1195: if (len <= 3)
1196: return null;
1197: if (buffer[offset++] != 'o')
1198: return null;
1199: switch (buffer[offset++]) {
1200: case 'i':
1201: return (len == 4 && buffer[offset++] == 'd') ? JavaTokenContext.VOID
1202: : null;
1203: case 'l':
1204: return (len == 8 && buffer[offset++] == 'a'
1205: && buffer[offset++] == 't'
1206: && buffer[offset++] == 'i'
1207: && buffer[offset++] == 'l' && buffer[offset++] == 'e') ? JavaTokenContext.VOLATILE
1208: : null;
1209: default:
1210: return null;
1211: }
1212: case 'w':
1213: return (len == 5 && buffer[offset++] == 'h'
1214: && buffer[offset++] == 'i'
1215: && buffer[offset++] == 'l' && buffer[offset++] == 'e') ? JavaTokenContext.WHILE
1216: : null;
1217: default:
1218: return null;
1219: }
1220: }
1221:
1222: }
|