mirror of https://github.com/acidanthera/audk.git
Modify Critic
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1302 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
daa4663bdd
commit
a756211f3f
|
@ -29,6 +29,14 @@ public class Common {
|
||||||
return wholefile.toString();
|
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) {
|
public static void ensureDir(String objFileWhole) {
|
||||||
File tempdir;
|
File tempdir;
|
||||||
Matcher mtrseparate = ptnseparate.matcher(objFileWhole);
|
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
|
public static HashSet<String> dirScan(String path) { // use HashSet, persue speed rather than space
|
||||||
HashSet<String> filelist = new HashSet<String>();
|
HashSet<String> filelist = new HashSet<String>();
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
|
@ -63,6 +63,14 @@ public class Common {
|
||||||
return filelist;
|
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 {
|
public static String dirCopy_(String src) throws Exception {
|
||||||
Matcher mtrseparate = Common.ptnseparate.matcher(src);
|
Matcher mtrseparate = Common.ptnseparate.matcher(src);
|
||||||
if (mtrseparate.find()) {
|
if (mtrseparate.find()) {
|
||||||
|
|
|
@ -15,46 +15,36 @@ package org.tianocore.migration;
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
public class Critic implements Common.ForDoAll {
|
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 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 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("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
|
||||||
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 Pattern ptninfequation = Pattern.compile("#%%\\s*([^\\s]*\\s*-\\s*.*\\s*)*",Pattern.MULTILINE);
|
||||||
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 Matcher mtrinfequation;
|
private static Matcher mtrinfequation;
|
||||||
|
|
||||||
public void toDo(String filepath) throws Exception {
|
public void toDo(String filepath) throws Exception {
|
||||||
String funccomment = null;
|
|
||||||
if (filepath.contains(".c") || filepath.contains(".h")) {
|
if (filepath.contains(".c") || filepath.contains(".h")) {
|
||||||
System.out.println("Criticing " + filepath);
|
System.out.println("Criticing " + filepath);
|
||||||
String wholeline = Common.file2string(filepath);
|
String wholeline = Common.file2string(filepath);
|
||||||
|
|
||||||
// find head comment
|
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
|
||||||
mtrheadcomment = ptnheadcomment.matcher(wholeline);
|
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$2$3$4$1$5");
|
||||||
if (mtrheadcomment.find()) { //as we find only the head comment here, use 'if' not 'while'
|
wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
||||||
wholeline = mtrheadcomment.replaceFirst("/** @file$1**/");
|
|
||||||
}
|
|
||||||
|
|
||||||
// find func comment
|
/* -----slow edition of replacefirst with stringbuffer-----
|
||||||
mtrfunccomment = ptnfunccomment.matcher(wholeline);
|
line.append(wholeline);
|
||||||
|
mtrfunccomment = ptnfunccomment.matcher(line);
|
||||||
while (mtrfunccomment.find()) {
|
while (mtrfunccomment.find()) {
|
||||||
funccomment = mtrfunccomment.group(2) + "&%";
|
line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));
|
||||||
mtrcommentstructure = ptncommentstructure.matcher(funccomment);
|
|
||||||
wholeline = mtrfunccomment.replaceAll("$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
|
// edit func comment
|
||||||
mtrtempcomment = ptntempcomment.matcher(wholeline);
|
mtrtempcomment = ptntempcomment.matcher(wholeline);
|
||||||
while (mtrtempcomment.find()) {
|
while (mtrtempcomment.find()) {
|
||||||
|
@ -62,6 +52,7 @@ public class Critic implements Common.ForDoAll {
|
||||||
System.out.println(mtrtempcomment.group());
|
System.out.println(mtrtempcomment.group());
|
||||||
System.out.println("-----------------------------");
|
System.out.println("-----------------------------");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
Common.string2file(wholeline, filepath);
|
Common.string2file(wholeline, filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue