forked from afkT/JavaDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanguAnalyeMain.java
More file actions
157 lines (144 loc) · 5.77 KB
/
Copy pathPanguAnalyeMain.java
File metadata and controls
157 lines (144 loc) · 5.77 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package other;
import dev.utils.common.FileIOUtils;
import dev.utils.common.FileUtils;
import dev.utils.common.MapUtils;
import dev.utils.common.StringUtils;
import javadoc.Utils;
import javadoc.dev_utils.ApiConfig;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
/**
* detail: 全局检测处理
* @author Ttt
*/
public class PanguAnalyeMain {
// 代码间距等规范处理
private static final Pangu sPangu = new Pangu();
// 判断是否覆盖文件内容
private static boolean sCoverText = true;
// 代码注释空格间距异常记录
private static HashMap<String, String> sAnnotationSpaceMap = new HashMap<>();
// 代码注释重复换行记录
private static HashMap<String, ArrayList<String>> sAnnotationRepeatLineMap = new HashMap<>();
public static void main(String[] args) {
String path = ApiConfig.LOCAL_PROJECT_PATH;
ArrayList<File> lists = Utils.getFileCatalogLists(path);
forReader(lists, new Filter() {
@Override
public boolean filter(File file) {
// 获取完整路径
String absolutePath = file.getAbsolutePath();
if (absolutePath.indexOf("\\.git") == -1
&& absolutePath.indexOf("\\.idea") == -1
&& absolutePath.indexOf("\\.gradlew") == -1
&& absolutePath.indexOf("\\wrapper") == -1
&& absolutePath.indexOf("\\.gradle") == -1
&& absolutePath.indexOf("\\build") == -1
&& !FileUtils.isAudioFormats(file)
&& !FileUtils.isVideoFormats(file)
&& !FileUtils.isImageFormats(file)
&& !absolutePath.endsWith("LICENSE")
&& !absolutePath.endsWith(".zip")
&& !absolutePath.endsWith(".rar")
&& !absolutePath.endsWith(".iml")) {
// && absolutePath.endsWith(".xml")
// && absolutePath.endsWith(".properties")
// && absolutePath.endsWith(".pro")
// && absolutePath.endsWith(".gradle")
// && absolutePath.endsWith(".gradle")
// && absolutePath.endsWith(".java")
return false;
}
return true;
}
});
System.out.println("处理结束");
// 统一拼接打印数据
LinkedHashMap<String, HashMap<String, ArrayList<String>>> printMap = new LinkedHashMap<>();
printMap.put("1.代码注释重复换行记录", sAnnotationRepeatLineMap);
// 转换 JSON 数据
String mapJSON = Utils.toJsonFormat(printMap, true);
System.out.println(mapJSON);
}
/**
* detail: 过滤处理
* @author Ttt
*/
private interface Filter {
/**
* 过滤文件处理
* @param file {@link File}
* @return 是否过滤该文件
*/
boolean filter(File file);
}
// ================
// = 内部处理方法 =
// ================
/**
* 循环读取处理
* @param lists 文件列表
*/
private static void forReader(final ArrayList<File> lists, final Filter filter) {
// 循环子文件
for (File file : lists) {
if (file.isDirectory() && !filter.filter(file)) {
forReader(Utils.getFileCatalogLists(file.getAbsolutePath() + "/"), filter);
} else {
if (!filter.filter(file)) {
System.out.println("处理: " + file.getAbsolutePath());
// = 慎用, 需要仔细对比部分代码差异化, 如 " " 会被替换成 "" 等 =
// 读取文件内容
String text = FileIOUtils.readFileToString(file, null);
if (text != null) {
// 处理后的代码
String newText = sPangu.spacingText(text);
newText = sPangu.spacingText(newText); // 多次处理
// 判断一样
if (!newText.equals(text)) {
sAnnotationSpaceMap.put(file.getName(), newText);
// 不一样才覆盖
if (sCoverText) {
FileUtils.saveFile(file.getParent(), file.getName(), newText);
}
}
}
// 读取文件
readFile(file);
}
}
}
}
/**
* 读取文件
* @param file 文件
*/
private static void readFile(final File file) {
// 读取文件内容
List<String> lists = FileIOUtils.readFileToList(file, 0, Integer.MAX_VALUE);
if (lists != null) {
// 判断是否需要判断 重复出现情况
boolean repeat = false;
// 循环判断
for (int i = 0, len = lists.size(); i < len; i++) {
// 获取每一行代码
String code = lists.get(i);
// 判断是否 null
boolean isSpace = StringUtils.isSpace(code);
// 防止为 null
if (!isSpace) {
repeat = false; // 不需要判断重复
} else {
if (code != null && repeat) {
MapUtils.putToList(sAnnotationRepeatLineMap, file.getName(), (i + 1) + "");
}
// 表示需要检测重复
repeat = true;
}
}
}
}
}