我有一个函数,它分解源文件,并根据关键字列表检查每个令牌,以确定它是否是特定的文件类型。如何改进这个函数?Tokenization是一个包含分解源代码的函数的类。
public static boolean validationTypeOfSQL(String sourceFile, Tokenization tokenization,ArrayList<String> uniqueKeywordList) {
ArrayList<Token> createSourceCodeTokens = tokenization.createSourceCodeTokens(sourceFile);
for (Token x : createSourceCodeTokens) {
String smallerTokens[] = tokenization.tokenToSmallerToken(x.getToken());
for (String smallerTOkenValue : smallerTokens) {
Boolean result = smallerTOkenValue.contains(",");
if (result == true) {
String[] tokenSplit = smallerTOkenValue.split(",");
for (String ts : tokenSplit) {
for (String t : uniqueKeywordList) {
if (t.toLowerCase().equals(ts.toLowerCase().replace("(", "").replace(",", "").replace(")", "").replace("\t", ""))) {
// System.out.println("This is a mysql file Mysql");
return true;
}
}
}
}
else {
for (String uniqueKeyword : uniqueKeywordList) {
if (uniqueKeyword.toLowerCase().equals(smallerTOkenValue.toLowerCase().replace("(", "").replace(",", "").replace(")", "")))
{
return true;
}
}
}
}
}
return false;
}发布于 2015-07-18 21:42:04
关于你的名字:
我想重命名:
validationTypeOfSQL()到isSQL()createSourceCodeTokens到sourceCodeTokenscreateSourceCodeTokens()到sourceCodeTokens()x到tokentokenToSmallerToken()到smallerTokens()smallerTOkenValue到smallerTokenresult to containsComma (当然,根据Robert的回答,完全删除它更好)。tokenSplit到splitTokensts到st或splitTokent到k或keyworduniqueKeyword到keyword我会把String smallerTokens[]改成String[] ...。不管怎么说,当你写完它的时候,你要写4行。
我将使用replaceAll(字符串正则表达式,字符串替换)和replaceAll("[(,)\t]", ""),而不是replace()链。
https://codereview.stackexchange.com/questions/97095
复制相似问题