fast edition with 'read line' implement

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1308 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
alfred 2006-08-17 07:47:37 +00:00
parent 3637381bec
commit 1af2e90c2e
1 changed files with 19 additions and 19 deletions

View File

@ -17,7 +17,7 @@ import java.io.*;
public class Critic implements Common.ForDoAll { public class Critic implements Common.ForDoAll {
private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL); private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
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 Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL); 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*"); private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(.*)\\s*");
private static Matcher mtrinfequation; private static Matcher mtrinfequation;
@ -28,6 +28,7 @@ public class Critic implements Common.ForDoAll {
BufferedReader rd = null; BufferedReader rd = null;
String line = null; String line = null;
StringBuffer templine = new StringBuffer(); StringBuffer templine = new StringBuffer();
boolean incomment = false;
boolean description = false; boolean description = false;
boolean arguments = false; boolean arguments = false;
boolean returns = false; boolean returns = false;
@ -36,52 +37,51 @@ public class Critic implements Common.ForDoAll {
String wholeline = Common.file2string(filepath); String wholeline = Common.file2string(filepath);
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/"); wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
//wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$2$3$4$1$5"); wholeline = Common.replaceAll(wholeline, ptnfunccomment, "/**$2**/$3$1$4");
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/"); //wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
/*
rd = new BufferedReader(new StringReader(wholeline)); rd = new BufferedReader(new StringReader(wholeline));
while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
if (line.contains("\\-\\-\\*\\/")) { if (line.matches("\\/\\*\\*")) {
description = false; incomment = true;
arguments = false;
returns = false;
templine.append(line + "\n"); templine.append(line + "\n");
} else if (line.contains("Routine Description:")) { } else if (line.matches("\\*\\*\\/")) {
incomment = false;
templine.append(line + "\n");
} else if (incomment && line.contains("Routine Description:")) {
description = true; description = true;
arguments = false; arguments = false;
returns = false; returns = false;
} else if (line.contains("Arguments:")) { } else if (incomment && line.contains("Arguments:")) {
description = false; description = false;
arguments = true; arguments = true;
returns = false; returns = false;
} else if (line.contains("Returns:")) { } else if (incomment && line.contains("Returns:")) {
description = false; description = false;
arguments = false; arguments = false;
returns = true; returns = true;
} else if (description) { } else if (incomment && description) {
templine.append(line + "\n"); templine.append(line + "\n");
//System.out.println("Description:" + line); } else if (incomment && arguments) {
} else if (arguments) {
mtrinfequation = ptninfequation.matcher(line); mtrinfequation = ptninfequation.matcher(line);
if (mtrinfequation.find()) { if (mtrinfequation.find()) {
templine.append(" @param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n"); templine.append(" @param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");
} else { } else {
templine.append(line + "\n"); templine.append(line + "\n");
} }
//System.out.println("Arguments:" + line); } else if (incomment && returns) {
} else if (returns) {
mtrinfequation = ptninfequation.matcher(line); mtrinfequation = ptninfequation.matcher(line);
if (mtrinfequation.find()) { if (mtrinfequation.find()) {
templine.append(" @retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n"); templine.append(" @retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");
} else { } else {
templine.append(line + "\n"); templine.append(line + "\n");
} }
//System.out.println("Returns:" + line);
} else { } else {
templine.append(line + "\n"); templine.append(line + "\n");
} }
} }
wholeline = templine.toString();*/ wholeline = templine.toString();
/* -----slow edition of replacefirst with stringbuffer----- /* -----slow edition of replacefirst with stringbuffer-----
line.append(wholeline); line.append(wholeline);
mtrfunccomment = ptnfunccomment.matcher(line); mtrfunccomment = ptnfunccomment.matcher(line);
@ -89,13 +89,13 @@ public class Critic implements Common.ForDoAll {
line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5")); line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));
} }
*/ */
// -----slow edition of replacefirst with string----- /* -----slow edition of replacefirst with string-----
while ((mtrfunccomment = ptnfunccomment.matcher(wholeline)).find()) { while ((mtrfunccomment = ptnfunccomment.matcher(wholeline)).find()) {
//funccomment = mtrfunccomment.group(2); //funccomment = mtrfunccomment.group(2);
//mtrcommentstructure = ptncommentstructure.matcher(funccomment); //mtrcommentstructure = ptncommentstructure.matcher(funccomment);
wholeline = mtrfunccomment.replaceFirst("$2$4$3$1$5"); wholeline = mtrfunccomment.replaceFirst("$2$4$3$1$5");
} }
*/
/* /*
// edit func comment // edit func comment
mtrtempcomment = ptntempcomment.matcher(wholeline); mtrtempcomment = ptntempcomment.matcher(wholeline);