📄 java2ansi.java
字号:
else {
currentType = NONTYPE;
lineBuffer.append(contents[i]);
continue;
}
}
}
//如果当前类型是引用
else if (currentType == QUOTE) {
//如果当前字符不是引号或者如果是引号但是他的前一个字符是'\'则
//表明是引用的内容,添加内容
if (contents[i] != '\"' || contents[i - 1] == '\\') {
lineBuffer.append(contents[i]);
continue;
}
//否则表明是引用的结束,添加内容并结束字体设置
else {
lineBuffer.append(contents[i]);
lineBuffer.append(styleQuote.getEnd());
currentType = NONTYPE;
continue;
}
}
//如果当前类型是多行注释
else if (currentType == COMMENT) {
//如果是第一个字符则表明是多行注释的继续的一行,添加字体设置
if (i == 0) {
lineBuffer.append(styleComment.getBegin());
}
//如果当前字符是'/'并且他的前一个字符是'*'则表明是注释的结束
//,添加内容并结束字体设置
if (contents[i] == '/' && contents[i - 1] == '*') {
lineBuffer.append(contents[i]);
lineBuffer.append(styleComment.getEnd());
currentType = NONTYPE;
continue;
}
//否则表明不是注释的结束,添加内容
else {
lineBuffer.append(contents[i]);
continue;
}
}
}
//对最后一个字符进行处理并结束本行的转换
char endChar = contents[end];
//如果是没有任何类型,最后一个字符不能构成任何特殊类,直接添加内容
if (currentType == NONTYPE) {
lineBuffer.append(endChar);
return lineBuffer.toString();
}
//如果是单词
else if (currentType == WORD) {
//如果最后一个字符是标识符的一部分,添加内容并结束风格设置
if (Character.isJavaIdentifierPart(endChar)) {
wordBuffer.append(endChar);
lineBuffer.append(convertWord(wordBuffer.toString()));
wordBuffer = new StringBuffer();
}
//否则表明单词已经结束,转换单词后作为普通内容添加。
else {
lineBuffer.append(convertWord(wordBuffer.toString()));
wordBuffer = new StringBuffer();
lineBuffer.append(endChar);
}
currentType = NONTYPE;
return lineBuffer.toString();
}
//如果是引用,由于字符串不能跨行,因此结束字符串引用不会有问题。
else if (currentType == QUOTE) {
lineBuffer.append(endChar);
lineBuffer.append(styleQuote.getEnd());
currentType = NONTYPE;
return lineBuffer.toString();
} else {
//如果最后一个字符是'/'并且他的前一个字符是'*'则表明是注释的结束
//,添加内容并结束字体设置
if (endChar == '/' && contents[end - 1] == '*') {
lineBuffer.append(endChar);
lineBuffer.append(styleComment.getEnd());
currentType = NONTYPE;
}
//否则表明不是注释的结束,添加内容
else {
lineBuffer.append(endChar);
lineBuffer.append(styleComment.getEnd());
}
return lineBuffer.toString();
}
}
/**
* 将单词转换为具有风格的结果。
* @param word 原始的单词
* @return 转换后的结果
*/
private String convertWord(String word) {
if(reserved.contains(word)) {
return reservedWordsStyle.getBegin()
+ word
+ reservedWordsStyle.getEnd();
} else if (classNames.contains(word)) {
return sytleClassName.getBegin() + word + sytleClassName.getEnd();
} else if (methods.contains(word)) {
return sytleMethod.getBegin() + word + sytleMethod.getEnd();
} else {
return word;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -