⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javacodeviewer.java

📁 非常有影响的 j道 论 坛 源码 国外很有明的专家编写的 ....对java爱好者很有参考价值
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        state = ENTRY;
                        i--;
                        // head_idx = i;
                        // state = string_entry;  // should go to accept and not assign head_idx
                    }
                    else if (curr_char == '\'') {  // should check for keyword
                        tail_idx = i;
                        buffer.append(char_line, head_idx, (tail_idx-head_idx));
                        state = ENTRY;
                        i--;
                        // head_idx = i;
                        // state = character_entry;  // should go to accept and not assign head_idx
                    }
                    else if (curr_char == ' ')
                    {
                        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);
                            state = ACCEPT;
                            i--;
                        }
                        else {  // can also do some highlighing in here, seeing as we have an identifier
                            buffer.append(char_line, head_idx, (tail_idx-head_idx));
                            state = ENTRY;
                            i--;
                        }
                    }
                    else if (curr_char == '\n') {  // possible multiple newlines
                        // check if a keyword is matched
                        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);
                            state = ACCEPT;
                            i--;
                        }
                        else {
                            buffer.append(char_line, head_idx, (tail_idx-head_idx));
                            state = ACCEPT;
                            i--;
                        }
                    }
                    else if (curr_char == '\t') {  // this recognizes keyword\t
                        // eg: else\t...
                        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);
                            state = ACCEPT;
                            i--;
                        }
                        else {
                            buffer.append(char_line, head_idx, (tail_idx-head_idx));
                            state = ACCEPT;
                            i--;
                        }
                    }
                    else {  // so int+, int;, public+, etc, are ignored :)
                        tail_idx = i;
                        buffer.append(char_line, head_idx, (tail_idx-head_idx));
                        state = ENTRY;
                        i--;
                    }
                    break;
                case ACCEPT:
                    if (Character.isJavaIdentifierPart(curr_char)) {  // keyword, id, num literal
                        head_idx = i;
                        if (Character.isDigit(curr_char)) {
                            if (curr_char == '0') {
                                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 == '/') {
                        head_idx = i;
                        state = IGNORE_BEGIN;
                    }
                    else if (curr_char == '\"') {
                        head_idx = i;
                        state = STRING_ENTRY;
                    }
                    else if (curr_char == '{' || curr_char == '}') {
                        buffer.append(bracketStart);
                        buffer.append(curr_char);
                        buffer.append(bracketEnd);
                        state = ACCEPT;
                    }
                    else {
                        state = ENTRY;
                        i--;
                    }
                    break;
                case IGNORE_BEGIN:
                    if (curr_char == '/') {
                        state = INLINE_IGNORE;
                    }
                    else if (curr_char == '*') {
                        state = MULTILINE_IGNORE;
                    }
                    else if (Character.isJavaIdentifierPart(curr_char)) {
                        head_idx = i;
                        if (Character.isDigit(curr_char)) {
                        	buffer.append('/');
                        	if (curr_char == '0') {
                                state = NUMBER_HEX_BEGIN;
                                i--;
                            }
                            else {
                                state = NUMBER_BIN_INT_FLOAT_OCTAL;
                                i--;
                            }
                        }
                        else {
                            buffer.append('/');
                            state = ENTRY;
                            i--;
                        }
                    }
                    else if (curr_char == '\n') {
                        buffer.append('/');
                        state = NEWLINE_ENTRY;
                        i--;
                    }
                    else {  // space, \t, etc
                        buffer.append('/');
                        state = ENTRY;
                        i--;
                    }
                    break;
                case INLINE_IGNORE:
                    if (curr_char != '\n') {
                        state = INLINE_IGNORE;
                    }
                    else if (curr_char == '\n') {
                        tail_idx = i;
                        buffer.append(commentStart);
                        buffer.append(char_line, head_idx, (tail_idx-head_idx));
                        buffer.append(commentEnd);
                        i--;
                        state = ACCEPT;
                    }
                    else { // what did we miss
                        ;
                    }
                    break;
                case MULTILINE_IGNORE:
                    if (curr_char == '*') {
                        state = MULTILINE_EXIT;
                    }
                    else {
                        state = MULTILINE_IGNORE;
                    }
                    break;
                case MULTILINE_EXIT:
                    if (curr_char == '/') {
                        tail_idx = i;
                        buffer.append(commentStart);
                        buffer.append(char_line, head_idx, (tail_idx-head_idx+1));
                        buffer.append(commentEnd);
                        state = ACCEPT;
                    }
                    else if(curr_char == '*') {
                        state = MULTILINE_EXIT;
                    }
                    else {
                        state = MULTILINE_IGNORE;
                    }
                    break;
                default:
                    break;
            }
            i++;
        }
        return buffer.toString();
    }
    
    

    public static HashMap getReservedWords() {
		return reservedWords;
	}

	public static void setReservedWords(HashMap reservedWords) {
		JavaCodeViewer.reservedWords = reservedWords;
	}

	public char[] getBackgroundColor() {
		return backgroundColor;
	}

	public void setBackgroundColor(char[] backgroundColor) {
		this.backgroundColor = backgroundColor;
	}

	public char getCharacterEscape() {
		return characterEscape;
	}

	public void setCharacterEscape(char characterEscape) {
		this.characterEscape = characterEscape;
	}

	public char[] getNbsp() {
		return nbsp;
	}

	public void setNbsp(char[] nbsp) {
		this.nbsp = nbsp;
	}

	public char getStringEscape() {
		return stringEscape;
	}

	public void setStringEscape(char stringEscape) {
		this.stringEscape = stringEscape;
	}

	public void setBracketEnd(char[] bracketEnd) {
		this.bracketEnd = bracketEnd;
	}

	public void setBracketStart(char[] bracketStart) {
		this.bracketStart = bracketStart;
	}

	public void setCharacterEnd(char[] characterEnd) {
		this.characterEnd = characterEnd;
	}

	public void setCharacterStart(char[] characterStart) {
		this.characterStart = characterStart;
	}

	public void setCommentEnd(char[] commentEnd) {
		this.commentEnd = commentEnd;
	}

	public void setCommentStart(char[] commentStart) {
		this.commentStart = commentStart;
	}

	public void setMethodEnd(char[] methodEnd) {
		this.methodEnd = methodEnd;
	}

	public void setMethodStart(char[] methodStart) {
		this.methodStart = methodStart;
	}

	public void setNumberEnd(char[] numberEnd) {
		this.numberEnd = numberEnd;
	}

	public void setNumberStart(char[] numberStart) {
		this.numberStart = numberStart;
	}

	public void setReservedWordEnd(char[] reservedWordEnd) {
		this.reservedWordEnd = reservedWordEnd;
	}

	public void setReservedWordStart(char[] reservedWordStart) {
		this.reservedWordStart = reservedWordStart;
	}

	public void setStringEnd(char[] stringEnd) {
		this.stringEnd = stringEnd;
	}

	public void setStringStart(char[] stringStart) {
		this.stringStart = stringStart;
	}

	/*
     * Load Hashtable (or HashMap) with Java reserved words. Improved list
     * in version 1.1 taken directly from Java language spec.
     */
    private static void loadKeywords() {
        reservedWords.put("abstract", "abstract");
        reservedWords.put("boolean", "boolean");
        reservedWords.put("break", "break");
        reservedWords.put("byte", "byte");
        reservedWords.put("case", "case");
        reservedWords.put("catch", "catch");
        reservedWords.put("char", "char");
        reservedWords.put("class", "class");
        reservedWords.put("const", "const");
        reservedWords.put("continue", "continue");
        reservedWords.put("default", "default");
        reservedWords.put("do", "do");
        reservedWords.put("double", "double");
        reservedWords.put("else", "else");
        reservedWords.put("extends", "extends");
        reservedWords.put("false", "false");
        reservedWords.put("final", "final");
        reservedWords.put("finally", "finally");
        reservedWords.put("float", "float");
        reservedWords.put("for", "for");
        reservedWords.put("goto", "goto");
        reservedWords.put("if", "if");
        reservedWords.put("implements", "implements");
        reservedWords.put("import", "import");
        reservedWords.put("instanceof", "instanceof");
        reservedWords.put("int", "int");
        reservedWords.put("interface", "interface");
        reservedWords.put("long", "long");
        reservedWords.put("native", "native");
        reservedWords.put("new", "new");
        reservedWords.put("package", "package");
        reservedWords.put("private", "private");
        reservedWords.put("protected", "protected");
        reservedWords.put("public", "public");
        reservedWords.put("return", "return");
        reservedWords.put("short", "short");
        reservedWords.put("static", "static");
        reservedWords.put("strictfp", "strictfp");
        reservedWords.put("super", "super");
        reservedWords.put("switch", "switch");
        reservedWords.put("synchronized", "synchronized");
        reservedWords.put("this", "this");
        reservedWords.put("throw", "throw");
        reservedWords.put("throws", "throws");
        reservedWords.put("transient", "transient");
        reservedWords.put("true", "true");
        reservedWords.put("try", "try");
        reservedWords.put("void", "void");
        reservedWords.put("volatile", "volatile");
        reservedWords.put("while", "while");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -