📄 javacodeviewer.java
字号:
state = NUMBER_HEX_BEGIN;
}
else {
state = NUMBER_BIN_INT_FLOAT_OCTAL;
}
}
else {
state = INTERIM;
}
}
else if (curr_char == '+' || curr_char == '-') { // number literals
if (i<char_line.length-1) {
if (!Character.isDigit(char_line[i+1])) { // +0x43 <-- this cannot be hex
buffer.append(curr_char);
state = ENTRY;
}
else {
head_idx = i;
state = NUMBER_BIN_INT_FLOAT_OCTAL;
}
}
else {
buffer.append(curr_char);
state = NUMBER_BIN_INT_FLOAT_OCTAL;
}
}
else if (curr_char == '/') { // comment
head_idx = i;
state = IGNORE_BEGIN;
}
else if (curr_char == '\"') { // string
head_idx = i;
state = STRING_ENTRY;
}
else if (curr_char == '\'') { // character
head_idx = i;
state = CHARACTER_ENTRY;
}
else if (curr_char == '{' || curr_char == '}') { // scope bracket
buffer.append(bracketStart);
buffer.append(curr_char);
buffer.append(bracketEnd);
state = ACCEPT;
}
else if (curr_char == '\n') { // in case of multiple newlines
buffer.append(curr_char);
state = NEWLINE_ENTRY;
}
else { // space, =, >, <, \t, white_space, etc
buffer.append(curr_char);
state = ENTRY;
}
break;
case NUMBER_BIN_INT_FLOAT_OCTAL:
if (Character.isJavaIdentifierPart(curr_char)) {
// 1f 1xf 67.6 1. -1 +2 0l
if (Character.isDigit(curr_char)) {
// 87 10 12 00-0L
state = NUMBER_BIN_INT_FLOAT_OCTAL;
}
else if (curr_char == 'l' || curr_char == 'L') { // cheating... +l +L
tail_idx = i;
if (filterNumber) {
buffer.append(numberStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx));
if (filterNumber) {
buffer.append(numberEnd);
}
state = ACCEPT;
}
else {
//-E +f 5e 1x 34234x 7979/7897 79+897 890-7989
if (char_line[i-1] == '-' || char_line[i-1] == '+') {
// -E +f -l -0l
tail_idx = i;
buffer.append(char_line, head_idx, (tail_idx-head_idx));
state = ACCEPT;
}
else { // must be numbers infront
// 5e 1x 34234x 2342static 243} 243;
tail_idx = i;
if (filterNumber) {
buffer.append(numberStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx));
if (filterNumber) {
buffer.append(numberEnd);
}
state = ACCEPT;
i--;
}
}
}
else {
// 12324\ 23423\n 23432. 2432\r 2423\t 2421{ 423: 2342~ 242& 6868- 768+
tail_idx = i;
if (filterNumber) {
buffer.append(numberStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx));
if (filterNumber) {
buffer.append(numberEnd);
}
state = ACCEPT;
i--;
}
break;
case NUMBER_HEX_BEGIN:
if (Character.isJavaIdentifierPart(curr_char)) {
// 0X 0B 05 0i 0x 00x3 0x0x0 0x00x 0x0005fg
if (curr_char == 'x') { // this accounts for proper case
// 0xn 0xf 0xl
state = NUMBER_HEX_REST;
}
else if (Character.isDigit(curr_char)) {
// 0000.0 05 078799
state = NUMBER_BIN_INT_FLOAT_OCTAL;
}
else { // upper case letters, lower case minus 'x'
// 0X 0b 0static 0case
tail_idx = i;
if (filterNumber) {
buffer.append(numberStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx));
if (filterNumber) {
buffer.append(numberEnd);
}
state = ACCEPT;
i--;
}
}
else {
// 0. 0\n 0\t 0\r 0' '
tail_idx = i;
if (filterNumber) {
buffer.append(numberStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx));
if (filterNumber) {
buffer.append(numberEnd);
}
state = ACCEPT;
i--;
}
break;
case NUMBER_HEX_REST:
if (Character.isDigit(curr_char)) {
state = NUMBER_HEX_REST;
}
else if (((int)curr_char >= 97 && (int)curr_char <= 102) || ((int)curr_char >= 65 && (int)curr_char <= 70)) {
// else if (curr_char == 'a' || curr_char == 'b' || curr_char == 'c' || curr_char == 'd' || curr_char == 'e' || curr_char == 'f' || curr_char == 'A' || curr_char == 'B' || curr_char == 'C' || curr_char == 'D' || curr_char == 'E' || curr_char == 'F') {
// 0x0 -> 0xf 0xFEef
state = NUMBER_HEX_REST;
}
else if (curr_char == 'l' || curr_char == 'L') {
tail_idx = i;
if (filterNumber) {
buffer.append(numberStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx+1));
if (filterNumber) {
buffer.append(numberEnd);
}
state = ACCEPT;
}
else {
// 0xg 0x~ 0x\n 0x\t 0x{
tail_idx = i;
if (filterNumber) {
buffer.append(numberStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx));
if (filterNumber) {
buffer.append(numberEnd);
}
state = ACCEPT;
i--;
}
break;
// this is only for iterating through a sequence of \n's until we read something else
case NEWLINE_ENTRY: // to be in here, we've got to have read at least 1 newline already
if (curr_char == '\n') { // definitely have at least 2 consecutive newlines now
// just keep on adding 's until we read something else
buffer.append(nbsp);
buffer.append(curr_char);
state = NEWLINE_ENTRY;
}
else { // anything else we process next time
state = ACCEPT;
i--;
}
break;
case STRING_ENTRY: // tabs are caught also
if (curr_char != '\"' && curr_char != '\n' && curr_char != '\r') {
state = STRING_ENTRY; // still reading a string
}
else if (curr_char == '\"') {
if(char_line[i-1] != stringEscape) {
tail_idx = i;
buffer.append(stringStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx+1));
buffer.append(stringEnd);
state = ACCEPT;
}
else { // escape this character's usual meaning
state = STRING_ENTRY;
}
}
else if (curr_char == '\n') { // chop it off at previous char
tail_idx = i;
buffer.append(stringStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(stringEnd);
state = ACCEPT;
i--;
}
else if (curr_char == '\r') { // shouldn't happen, as carriage returns were erased
// but ignore it just in case
tail_idx = i;
buffer.append(stringStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx+1));
buffer.append(stringEnd);
state = ACCEPT;
i--;
}
else { // what did we miss
;
}
break;
case CHARACTER_ENTRY:
if (curr_char != '\'' && curr_char != '\n' && curr_char != '\r') { // tabs are caught also
state = CHARACTER_ENTRY; // still reading a string
}
else if (curr_char == '\'') {
if(char_line[i-1] != characterEscape) {
tail_idx = i;
buffer.append(characterStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx+1));
buffer.append(characterEnd);
state = ACCEPT;
}
else { // escape this character's usual meaning
state = CHARACTER_ENTRY;
}
}
else if (curr_char == '\n') {
tail_idx = i;
buffer.append(characterStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(characterEnd);
state = ACCEPT;
i--;
}
else if (curr_char == '\r') { // shouldn't happen, as carriage returns were erased
tail_idx = i;
buffer.append(characterStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(characterEnd);
state = ACCEPT;
i--;
}
else { // what did we miss
; // stay in character_entry
}
break;
case INTERIM:
if (Character.isJavaIdentifierPart(curr_char) || curr_char == '.') {
state = INTERIM;
}
else if (curr_char == '(') {
tail_idx = i;
token = new String(char_line, head_idx, (tail_idx-head_idx));
if(reservedWords.containsKey(token)) { // keyword
buffer.append(reservedWordStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(reservedWordEnd);
}
else { // method
if (filterMethod) {
buffer.append(methodStart);
}
buffer.append(char_line, head_idx, (tail_idx-head_idx));
if (filterMethod) {
buffer.append(methodEnd);
}
}
buffer.append(curr_char);
state = ACCEPT;
}
else if (curr_char == ')') {
tail_idx = i;
token = new String(char_line, head_idx, (tail_idx-head_idx));
if(reservedWords.containsKey(token)) { // keyword
buffer.append(reservedWordStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(reservedWordEnd);
buffer.append(curr_char);
state = ACCEPT;
}
else {
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(curr_char);
state = ENTRY;
}
}
else if (curr_char == ':') {
// eg: default: etc
tail_idx = i;
token = new String(char_line, head_idx, (tail_idx-head_idx));
if(reservedWords.containsKey(token)) {
buffer.append(reservedWordStart);
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(reservedWordEnd);
buffer.append(curr_char);
state = ACCEPT;
}
else {
buffer.append(char_line, head_idx, (tail_idx-head_idx));
buffer.append(curr_char);
state = ENTRY;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -