]>
Commit | Line | Data |
---|---|---|
8c4eeeb6 | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | **/\r | |
fed802b1 | 13 | package org.tianocore.migration;\r |
14 | \r | |
15 | import java.util.regex.*;\r | |
16 | \r | |
17 | public class Critic implements Common.ForDoAll {\r | |
fed802b1 | 18 | private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r |
8c4eeeb6 | 19 | private static Pattern ptnfunccomment = Pattern.compile("([\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)(\\/\\*\\+\\+.*?)(\\-\\-\\*\\/\\s*)(.*?)([\\{;])",Pattern.DOTALL);\r |
a756211f | 20 | private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r |
21 | private static Pattern ptninfequation = Pattern.compile("#%%\\s*([^\\s]*\\s*-\\s*.*\\s*)*",Pattern.MULTILINE);\r | |
8c4eeeb6 | 22 | private static Matcher mtrinfequation;\r |
fed802b1 | 23 | \r |
24 | public void toDo(String filepath) throws Exception {\r | |
25 | if (filepath.contains(".c") || filepath.contains(".h")) {\r | |
8c4eeeb6 | 26 | System.out.println("Criticing " + filepath);\r |
fed802b1 | 27 | String wholeline = Common.file2string(filepath);\r |
8c4eeeb6 | 28 | \r |
a756211f | 29 | wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");\r |
30 | wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$2$3$4$1$5");\r | |
31 | wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r | |
8c4eeeb6 | 32 | \r |
a756211f | 33 | /* -----slow edition of replacefirst with stringbuffer-----\r |
34 | line.append(wholeline);\r | |
35 | mtrfunccomment = ptnfunccomment.matcher(line);\r | |
8c4eeeb6 | 36 | while (mtrfunccomment.find()) {\r |
a756211f | 37 | line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));\r |
8c4eeeb6 | 38 | }\r |
a756211f | 39 | */\r |
40 | /* -----slow edition of replacefirst with string-----\r | |
41 | while ((mtrfunccomment = ptnfunccomment.matcher(wholeline)).find()) {\r | |
42 | //funccomment = mtrfunccomment.group(2);\r | |
43 | //mtrcommentstructure = ptncommentstructure.matcher(funccomment);\r | |
44 | wholeline = mtrfunccomment.replaceFirst("$2$4$3$1$5");\r | |
45 | }\r | |
46 | */\r | |
47 | /*\r | |
8c4eeeb6 | 48 | // edit func comment\r |
49 | mtrtempcomment = ptntempcomment.matcher(wholeline);\r | |
50 | while (mtrtempcomment.find()) {\r | |
51 | System.out.println("-----------------------------");\r | |
52 | System.out.println(mtrtempcomment.group());\r | |
53 | System.out.println("-----------------------------");\r | |
54 | }\r | |
a756211f | 55 | */\r |
8c4eeeb6 | 56 | Common.string2file(wholeline, filepath);\r |
fed802b1 | 57 | }\r |
58 | }\r | |
59 | \r | |
60 | public static void fireAt(String path) throws Exception {\r | |
8c4eeeb6 | 61 | Critic critic = new Critic();\r |
62 | Common.toDoAll(Common.dirCopy_(path), critic);\r | |
fed802b1 | 63 | System.out.println("Critic Done");\r |
64 | }\r | |
65 | }\r | |
8c4eeeb6 | 66 | //analyze func comment\r |
67 | /*if (mtrcommentstructure.find()) {\r | |
68 | newcomment.append("/*++\n\n" + mtrcommentstructure.group(1) + "\n\n");\r | |
69 | \r | |
70 | //System.out.println("-------1-------");\r | |
71 | //System.out.println(mtrcommentstructure.group(1));\r | |
72 | \r | |
73 | // arg\r | |
74 | //System.out.println("-------2-------");\r | |
75 | //System.out.println(mtrcommentstructure.group(2));\r | |
76 | mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(2));\r | |
77 | while (mtrinfequation.find()) {\r | |
78 | newcomment.append("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r | |
79 | //System.out.println("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r | |
80 | }\r | |
81 | newcomment.append("\n");\r | |
82 | // return\r | |
83 | //System.out.println("-------3-------");\r | |
84 | //System.out.println(mtrcommentstructure.group(3));\r | |
85 | mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(3));\r | |
86 | while (mtrinfequation.find()) {\r | |
87 | newcomment.append("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r | |
88 | //System.out.println("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r | |
89 | }\r | |
90 | System.out.println(newcomment);\r | |
91 | } else {\r | |
92 | System.out.println("Error: Comment Style Incorrect");\r | |
93 | }*/ |