2023年6月8日17:44:06
parent
f815ccae87
commit
976f6bcc74
|
|
@ -6,6 +6,7 @@ import com.zhangmeng.tools.components.RecursiveFileList;
|
|||
import com.zhangmeng.tools.languages.ProcessGO;
|
||||
import com.zhangmeng.tools.languages.ProcessHtml;
|
||||
import com.zhangmeng.tools.languages.ProcessJava;
|
||||
import com.zhangmeng.tools.languages.ProcessSql;
|
||||
import com.zhangmeng.tools.utils.AlertUtils;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
|
|
@ -376,6 +377,9 @@ public class FileEditController {
|
|||
if (type.equals(Type.HTML)) {
|
||||
matcher = ProcessHtml.PATTERN.matcher(text);
|
||||
}
|
||||
if (type.equals(Type.SQL)) {
|
||||
matcher = ProcessSql.PATTERN.matcher(text);
|
||||
}
|
||||
int lastKwEnd = 0;
|
||||
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
|
||||
while (matcher.find()) {
|
||||
|
|
@ -425,7 +429,20 @@ public class FileEditController {
|
|||
null; /* never happens */
|
||||
}
|
||||
|
||||
|
||||
if (type.equals(Type.SQL)){
|
||||
styleClass = matcher.group("PAREN") != null ? "paren" :
|
||||
matcher.group("BRACE") != null ? "brace" :
|
||||
matcher.group("BRACKET") != null ? "bracket" :
|
||||
matcher.group("SEMICOLON") != null ? "semicolon" :
|
||||
matcher.group("STRING") != null ? "string" :
|
||||
matcher.group("COMMENT") != null ? "comment" :
|
||||
matcher.group("ANNOTATION") != null ? "annotation" :
|
||||
matcher.group("PARAMS") != null ? "parameter" :
|
||||
matcher.group("METHOD") != null ? "method" :
|
||||
matcher.group("HTMLKEYWORDS") != null ? "html-keyword" : //html 标签
|
||||
matcher.group("HTMLKEYWORDS2") != null ? "html-keyword2" : //html 属性
|
||||
null;
|
||||
}
|
||||
assert styleClass != null;
|
||||
spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
|
||||
spansBuilder.add(Collections.singleton(styleClass), matcher.end() - matcher.start());
|
||||
|
|
|
|||
|
|
@ -47,84 +47,4 @@ public class ProcessHtml {
|
|||
+ "|(?<HTMLKEYWORDS2>" + HTMLKEYWORDS_PATTERN2 + ")"
|
||||
|
||||
);
|
||||
|
||||
public static String SAMPLE_CODE = "package com.dashidao.server.model;\n" +
|
||||
"\n" +
|
||||
"import java.util.Date;\n" +
|
||||
"\n" +
|
||||
"public class PosterGroupCouponCode extends BaseEntity<Long> {\n" +
|
||||
"\n" +
|
||||
"\tprivate Date addTime;\n" +
|
||||
"\tprivate Boolean deleteStatus;\n" +
|
||||
"\tprivate String groupCouponCode;\n" +
|
||||
"\tprivate Integer groupCouponStatus;\n" +
|
||||
"\tprivate Date writeOffTime;\n" +
|
||||
"\tprivate Long orderFormId;\n" +
|
||||
"\tprivate Long posterGoodsCartId;\n" +
|
||||
"\tprivate Long tuiKuanShouHouId;\n" +
|
||||
"\tprivate Long orderMealUserId;\n" +
|
||||
"\tprivate String groupSkusJson;\n" +
|
||||
"\n" +
|
||||
"\tpublic Date getAddTime() {\n" +
|
||||
"\t\treturn addTime;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setAddTime(Date addTime) {\n" +
|
||||
"\t\tthis.addTime = addTime;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic Boolean getDeleteStatus() {\n" +
|
||||
"\t\treturn deleteStatus;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setDeleteStatus(Boolean deleteStatus) {\n" +
|
||||
"\t\tthis.deleteStatus = deleteStatus;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic String getGroupCouponCode() {\n" +
|
||||
"\t\treturn groupCouponCode;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setGroupCouponCode(String groupCouponCode) {\n" +
|
||||
"\t\tthis.groupCouponCode = groupCouponCode;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic Integer getGroupCouponStatus() {\n" +
|
||||
"\t\treturn groupCouponStatus;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setGroupCouponStatus(Integer groupCouponStatus) {\n" +
|
||||
"\t\tthis.groupCouponStatus = groupCouponStatus;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic Date getWriteOffTime() {\n" +
|
||||
"\t\treturn writeOffTime;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setWriteOffTime(Date writeOffTime) {\n" +
|
||||
"\t\tthis.writeOffTime = writeOffTime;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic Long getOrderFormId() {\n" +
|
||||
"\t\treturn orderFormId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setOrderFormId(Long orderFormId) {\n" +
|
||||
"\t\tthis.orderFormId = orderFormId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic Long getPosterGoodsCartId() {\n" +
|
||||
"\t\treturn posterGoodsCartId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setPosterGoodsCartId(Long posterGoodsCartId) {\n" +
|
||||
"\t\tthis.posterGoodsCartId = posterGoodsCartId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic Long getTuiKuanShouHouId() {\n" +
|
||||
"\t\treturn tuiKuanShouHouId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setTuiKuanShouHouId(Long tuiKuanShouHouId) {\n" +
|
||||
"\t\tthis.tuiKuanShouHouId = tuiKuanShouHouId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic Long getOrderMealUserId() {\n" +
|
||||
"\t\treturn orderMealUserId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setOrderMealUserId(Long orderMealUserId) {\n" +
|
||||
"\t\tthis.orderMealUserId = orderMealUserId;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic String getGroupSkusJson() {\n" +
|
||||
"\t\treturn groupSkusJson;\n" +
|
||||
"\t}\n" +
|
||||
"\tpublic void setGroupSkusJson(String groupSkusJson) {\n" +
|
||||
"\t\tthis.groupSkusJson = groupSkusJson;\n" +
|
||||
"\t}\n" +
|
||||
"\n" +
|
||||
"}\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
package com.zhangmeng.tools.languages;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-06-01 11:01
|
||||
*/
|
||||
public class ProcessSql {
|
||||
|
||||
public static final String[] HTMLKEYWORDS = new String[] {
|
||||
"CREATE","create", "drop", "DROP", "INSERT","insert",
|
||||
"SELECT", "select","UPDATE","update","DELETE","delete", "FORMAT", "SUM","DATE",
|
||||
"title","img", "hr", "a", "table","div","span",
|
||||
"ul", "dl","dd","i","script","li","link"
|
||||
};
|
||||
|
||||
public static final String[] HTMLKEYWORDS2 = new String[] {
|
||||
"use", "IF", "if", "PRIMARY KEY", "FROM", "from","order","group","INNER","JOIN","ON","values","ALTER","SHOW",
|
||||
"by","INTO","VALUES","WHERE","where","SET","set","LIKE","like","UNION","ORDER","BY","GROUP","EXISTS","TABLE","table"
|
||||
};
|
||||
|
||||
public static final String HTMLKEYWORDS_PATTERN = "\\b(" + String.join("|", HTMLKEYWORDS) + ")\\b";
|
||||
public static final String HTMLKEYWORDS_PATTERN2 = "\\b(" + String.join("|", HTMLKEYWORDS2) + ")\\b";
|
||||
public static final String PAREN_PATTERN = "\\(|\\)";
|
||||
public static final String BRACE_PATTERN = "\\{|\\}";
|
||||
public static final String BRACKET_PATTERN = "\\[|\\]";
|
||||
public static final String SEMICOLON_PATTERN = "\\;";
|
||||
public static final String STRING_PATTERN = "\"([^\"\\\\]|\\\\.)*\"";
|
||||
public static final String COMMENT_PATTERN = "//[^\n]*" + "|" + "/\\*(.|\\R)*?\\*/";
|
||||
public static final String ANNOTATION_PATTERN = "@[a-zA-Z]+";
|
||||
public static final String PARAMS_PATTERN = "\\\\b([a-zA-Z]+)\\\\s*=\\\\s*([a-zA-Z0-9]+)\\\\b";
|
||||
public static final String METHOD_PATTERN = "\\w+\\((\\w+,\\s*)*\\w*\\)";
|
||||
|
||||
public static final Pattern PATTERN = Pattern.compile(
|
||||
"(?<HTMLKEYWORDS>" + HTMLKEYWORDS_PATTERN + ")"
|
||||
+ "|(?<PAREN>" + PAREN_PATTERN + ")"
|
||||
+ "|(?<BRACE>" + BRACE_PATTERN + ")"
|
||||
+ "|(?<BRACKET>" + BRACKET_PATTERN + ")"
|
||||
+ "|(?<SEMICOLON>" + SEMICOLON_PATTERN + ")"
|
||||
+ "|(?<STRING>" + STRING_PATTERN + ")"
|
||||
+ "|(?<COMMENT>" + COMMENT_PATTERN + ")"
|
||||
+ "|(?<ANNOTATION>" + ANNOTATION_PATTERN + ")"
|
||||
+ "|(?<PARAMS>" + PARAMS_PATTERN + ")"
|
||||
+ "|(?<METHOD>" + METHOD_PATTERN + ")"
|
||||
+ "|(?<HTMLKEYWORDS2>" + HTMLKEYWORDS_PATTERN2 + ")"
|
||||
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue