📄 javaexceptiontokenmaker.java
字号:
/*
* 03/22/2005
*
* JavaExceptionTokenMaker.java - Parses input and translates it into tokens
* representing a Java exception stack trace.
* Copyright (C) 2005 Robert Futrell
* email@address.com
* www.website.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.fife.rtext;
import java.util.regex.*;
import javax.swing.text.Segment;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.TokenMap;
import org.fife.ui.rsyntaxtextarea.custom.*;
/**
* Token maker for Java exceptions. This scheme is used by RText's custom
* Exception dialog to make it a little more pretty.<p>
*
* Note that we only use this syntax highlighting when we're certain that the
* JVM in which we're running is a Sun JVM, as we're only positive of the
* stack trace format in this case (it's not specified in any JVM spec).
*
* @author Robert Futrell
* @version 0.1
*/
public class JavaExceptionTokenMaker extends AbstractRegExTokenMaker {
private RuleSet ruleSet;
/*****************************************************************************/
public JavaExceptionTokenMaker() {
ruleSet = createRuleSet();
}
/*****************************************************************************/
private final RuleSet createRuleSet() {
Rule[] rules = new Rule[7];
// Exception/error rule.
String p = "[\\w\\.\\\\$]+\\..*(Exception|Error|Throwable)";
rules[0] = new Rule(p, Token.COMMENT_EOL, true);
// Method descriptor rule.
p = "([\\w\\\\$]+[\\.])+[\\w\\\\$]+";
rules[1] = new Rule(p, Token.RESERVED_WORD, true);
// Operator rule.
p = "[:]";
rules[2] = new Rule(p, Token.OPERATOR, true);
// Identifier rule (should catch words not exception-specific).
p = "[\\w\\\\$;,]+";
rules[3] = new Rule(p, Token.IDENTIFIER, true);
// Line number/Unknown Source/Native method rule.
p = "\\([^\\)\\n]*\\)";
rules[4] = new Rule(p, Token.LITERAL_STRING_DOUBLE_QUOTE, true);
// Whitespace rule.
p = "\\s+";
rules[5] = new Rule(p, Token.WHITESPACE, true);
// Catchall rule in case we missed something or some implementation
// does a different format for stack traces.
p = ".";
rules[6] = new Rule(p, Token.ERROR_IDENTIFIER, true);
TokenMap wordsToHighlight = getWordsToHighlight();
return new RuleSet(rules, wordsToHighlight);
}
/*****************************************************************************/
protected RuleSet getRuleSet(int state) {
return ruleSet;
}
/*****************************************************************************/
/**
* Returns the words to highlight (which is empty).
*
* @return A <code>TokenMap</code> containing the words to highlight.
*/
public TokenMap getWordsToHighlight() {
return new TokenMap();//null;
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -