From: alfred Date: Thu, 17 Aug 2006 05:06:49 +0000 (+0000) Subject: Modify Critic X-Git-Tag: edk2-stable201903~24571 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=a756211f3f6af8c5ec72e7d114213a4257b3bfa5;hp=daa4663bdd6c65b7e4423bd7b9f8b2cc72ee9bab;ds=inline Modify Critic git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1302 6f19259b-4bc3-4df7-8a09-765794883524 --- 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 dirScan(String path) { // use HashSet, persue speed rather than space HashSet filelist = new HashSet(); 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); } }