import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;


 public class FindNoSpace {
 public static void main(String[] args) throws Exception {
FindNoSpace instance = new FindNoSpace();
 {
 String[] folderNames = {"E:\\MyJava\\src"};
ArrayList fileList = instance.getFileListByFileNames(folderNames, false);
 fileList = instance.getFileListByParentFolder(fileList, new String[] {".java"}, true);
instance.findNoSpaceFunction(fileList);
}
// {
// String[] folderNames = {"E:\\MyJava\\src\\F01.java"};
// ArrayList fileList = instance.getFileListByFileNames(folderNames, true);
// instance.findNoSpaceFunction(fileList);
// }
}
 public ArrayList getFileListByParentFolder(ArrayList fileList, String[] endWith, boolean hasChildFoldersChildrens) {
boolean hasFolder = true;
 while (hasFolder) {
hasFolder = false;
 if (fileList.size() <= 0) {
break;
}
ArrayList newFileList = new ArrayList();
 for (int i = 0; i < fileList.size(); i++) {
File fTem = (File)fileList.get(i);
 if (fTem.isDirectory()) {
hasFolder = true;
File[] filelisttem = fTem.listFiles();
 for (int j = 0; j < filelisttem.length; j++) {
if (filelisttem[j].isDirectory() || isEndWith(filelisttem[j].getName(), endWith))
newFileList.add(filelisttem[j]);
}
 } else if (fTem.isFile()) {
if (isEndWith(fTem.getName(), endWith))
newFileList.add(fTem);
}
}
fileList = newFileList;
 if (!hasChildFoldersChildrens) {
newFileList = new ArrayList();
 for (int i = 0; i <= fileList.size(); i++) {
File f = (File)fileList.get(i);
 if (f.isFile()) {
newFileList.add(f);
}
}
fileList = newFileList;
break;
}
}
return fileList;
}
 public ArrayList getFileListByFileNames(String[] fileNames, boolean onlyGetFile) {
ArrayList fileList = new ArrayList();
 for (int i = 0; i < fileNames.length; i++) {
File f = new File(fileNames[i]);
 if (onlyGetFile && f.isFile()) {
fileList.add(f);
 } else {
fileList.add(f);
}
}
return fileList;
}
 private boolean isEndWith(String str, String[] endWith) {
 if (endWith.length <= 0) {
return true;
}
str = str.toLowerCase();
 for (int i = 0; i < endWith.length; i++) {
 if (str.endsWith(endWith[i])) {
return true;
}
}
return false;
}
 public void findNoSpaceFunction(ArrayList fileList) throws Exception {
String line = "";
 String[] macher = {".*\\w(\\{|==|!=|<=|>=|&&|\\*=|/=|\\+=|-=|%=|^=|\\+|\\-|\\*|/|%|=|<|>)(\\s|\\t).*",
".*(\\s|\\t)(==|!=|<=|>=|&&|\\*=|/=|\\+=|-=|%=|^=|\\+|\\-|\\*|/|%|=|<|>)[\\w|-].*",
".*\\w(==|!=|<=|>=|&&|\\*=|/=|\\+=|-=|%=|^=|\\+|\\-|\\*|/|%|=|<|>)\\w.*",
".*(\\s|\\t)if\\(.*"};
int onefilelinecount = 0;
boolean isPrintfile;
 for (int i = 0; i < fileList.size(); i++) {
onefilelinecount = 0;
isPrintfile = true;
File f = (File)fileList.get(i);
BufferedReader bfreader = new BufferedReader(new FileReader(f));
 while (bfreader.ready()) {
onefilelinecount++;
line = bfreader.readLine();
 if (line.trim().length() <= 0) {
continue;
}
char lt = line.trim().charAt(0);
 if ("{}0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(lt) < 0) {
continue;
}
 if (line.matches(".*\\s-\\d.*")) {
continue;
}
line = line.split("//")[0];
line = line.split("/*")[0];
 if (line.indexOf('"') >= 0) {
String[] liness = line.split("\"");
 for (int lc = 0; lc < liness.length; lc++) {
 if (lc % 2 == 0) {
line += liness[lc];
}
}
}
String teststr = line.replaceAll("\\+\\+", "\\-\\-");
teststr = teststr.replaceAll("\\-\\-", "OO");
 for (int j = 0; j < macher.length; j++) {
 if (teststr.matches(macher[j]) || teststr.indexOf("if(") >= 0) {
 if (isPrintfile) {
isPrintfile = false;
System.out.println(f.getAbsolutePath());
}
System.out.println(onefilelinecount + "\t" + line);
break;
}
}
}
}
System.out.println("Find Over");
}
}

|
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 |
|
导航
统计
- 随笔: 115
- 文章: 1
- 评论: 86
- 引用: 0
常用链接
留言簿(5)
随笔档案(115)
网址
搜索
积分与排名
最新评论

阅读排行榜
评论排行榜
|
|