diff options
author | alfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-08-17 05:06:49 +0000 |
---|---|---|
committer | alfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-08-17 05:06:49 +0000 |
commit | a756211f3f6af8c5ec72e7d114213a4257b3bfa5 (patch) | |
tree | f6ddd844a3e50bd592b2d3be0557a844cb1b9168 /Tools | |
parent | daa4663bdd6c65b7e4423bd7b9f8b2cc72ee9bab (diff) | |
download | edk2-platforms-a756211f3f6af8c5ec72e7d114213a4257b3bfa5.tar.xz |
Modify Critic
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1302 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/Source/MigrationTools/org/tianocore/migration/Common.java | 24 | ||||
-rw-r--r-- | Tools/Source/MigrationTools/org/tianocore/migration/Critic.java | 47 |
2 files changed, 35 insertions, 36 deletions
diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/Common.java b/Tools/Source/MigrationTools/org/tianocore/migration/Common.java index 3468a43ceb..d3d781f322 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/Common.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/Common.java @@ -29,6 +29,14 @@ public class Common { return wholefile.toString();
}
+ public static void string2file(String content, String filename) throws Exception {
+ ensureDir(filename);
+ PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
+ outfile.append(content);
+ outfile.flush();
+ outfile.close();
+ }
+
public static void ensureDir(String objFileWhole) {
File tempdir;
Matcher mtrseparate = ptnseparate.matcher(objFileWhole);
@@ -38,14 +46,6 @@ public class Common { }
}
- public static void string2file(String content, String filename) throws Exception {
- ensureDir(filename);
- PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
- outfile.append(content);
- outfile.flush();
- outfile.close();
- }
-
public static HashSet<String> dirScan(String path) { // use HashSet, persue speed rather than space
HashSet<String> filelist = new HashSet<String>();
String[] list = new File(path).list();
@@ -63,6 +63,14 @@ public class Common { return filelist;
}
+ public static String replaceAll(String line, Pattern ptn, String des) {
+ Matcher mtr = ptn.matcher(line);
+ if (mtr.find()) {
+ return mtr.replaceAll(des);
+ }
+ return line;
+ }
+
public static String dirCopy_(String src) throws Exception {
Matcher mtrseparate = Common.ptnseparate.matcher(src);
if (mtrseparate.find()) {
diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java b/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java index 821305edf0..9c81282038 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java @@ -15,46 +15,36 @@ package org.tianocore.migration; import java.util.regex.*;
public class Critic implements Common.ForDoAll {
- Critic() {
- filepath = null;
- }
- Critic(String path) {
- filepath = path;
- }
-
- private String filepath = null;
-
private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
- private static Matcher mtrheadcomment;
private static Pattern ptnfunccomment = Pattern.compile("([\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)(\\/\\*\\+\\+.*?)(\\-\\-\\*\\/\\s*)(.*?)([\\{;])",Pattern.DOTALL);
- private static Matcher mtrfunccomment;
- private static Pattern ptncommentstructure = Pattern.compile("Routine Description:\\s*(\\w.*?\\w)\\s*Arguments:(\\s*\\w.*?\\w\\s*)Returns:(\\s*\\w.*?\\w\\s*)&%",Pattern.DOTALL);
- private static Matcher mtrcommentstructure;
- private static Pattern ptntempcomment = Pattern.compile("\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*[\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)",Pattern.DOTALL);
- private static Matcher mtrtempcomment;
- private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(\\w.*\\w)");
+ private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
+ private static Pattern ptninfequation = Pattern.compile("#%%\\s*([^\\s]*\\s*-\\s*.*\\s*)*",Pattern.MULTILINE);
private static Matcher mtrinfequation;
public void toDo(String filepath) throws Exception {
- String funccomment = null;
if (filepath.contains(".c") || filepath.contains(".h")) {
System.out.println("Criticing " + filepath);
String wholeline = Common.file2string(filepath);
- // find head comment
- mtrheadcomment = ptnheadcomment.matcher(wholeline);
- if (mtrheadcomment.find()) { //as we find only the head comment here, use 'if' not 'while'
- wholeline = mtrheadcomment.replaceFirst("/** @file$1**/");
- }
+ wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
+ wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$2$3$4$1$5");
+ wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
- // find func comment
- mtrfunccomment = ptnfunccomment.matcher(wholeline);
+ /* -----slow edition of replacefirst with stringbuffer-----
+ line.append(wholeline);
+ mtrfunccomment = ptnfunccomment.matcher(line);
while (mtrfunccomment.find()) {
- funccomment = mtrfunccomment.group(2) + "&%";
- mtrcommentstructure = ptncommentstructure.matcher(funccomment);
- wholeline = mtrfunccomment.replaceAll("$2$4$3$1$5");
+ line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));
}
-
+ */
+ /* -----slow edition of replacefirst with string-----
+ while ((mtrfunccomment = ptnfunccomment.matcher(wholeline)).find()) {
+ //funccomment = mtrfunccomment.group(2);
+ //mtrcommentstructure = ptncommentstructure.matcher(funccomment);
+ wholeline = mtrfunccomment.replaceFirst("$2$4$3$1$5");
+ }
+ */
+ /*
// edit func comment
mtrtempcomment = ptntempcomment.matcher(wholeline);
while (mtrtempcomment.find()) {
@@ -62,6 +52,7 @@ public class Critic implements Common.ForDoAll { System.out.println(mtrtempcomment.group());
System.out.println("-----------------------------");
}
+ */
Common.string2file(wholeline, filepath);
}
}
|