]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/MigrationTools/org/tianocore/migration/Critic.java
Fix EDKT191.
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Critic.java
CommitLineData
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 13package org.tianocore.migration;\r
14\r
15import java.util.regex.*;\r
16\r
17public class Critic implements Common.ForDoAll {\r
18 Critic() {\r
19 filepath = null;\r
20 }\r
21 Critic(String path) {\r
22 filepath = path;\r
23 }\r
24 \r
25 private String filepath = null;\r
26 \r
27 private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
28 private static Matcher mtrheadcomment;\r
8c4eeeb6 29 private static Pattern ptnfunccomment = Pattern.compile("([\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)(\\/\\*\\+\\+.*?)(\\-\\-\\*\\/\\s*)(.*?)([\\{;])",Pattern.DOTALL);\r
30 private static Matcher mtrfunccomment;\r
31 private static Pattern ptncommentstructure = Pattern.compile("Routine Description:\\s*(\\w.*?\\w)\\s*Arguments:(\\s*\\w.*?\\w\\s*)Returns:(\\s*\\w.*?\\w\\s*)&%",Pattern.DOTALL);\r
32 private static Matcher mtrcommentstructure;\r
33 private static Pattern ptntempcomment = Pattern.compile("\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*[\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)",Pattern.DOTALL);\r
34 private static Matcher mtrtempcomment;\r
35 private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(\\w.*\\w)");\r
36 private static Matcher mtrinfequation;\r
fed802b1 37 \r
38 public void toDo(String filepath) throws Exception {\r
8c4eeeb6 39 String funccomment = null;\r
fed802b1 40 if (filepath.contains(".c") || filepath.contains(".h")) {\r
8c4eeeb6 41 System.out.println("Criticing " + filepath);\r
fed802b1 42 String wholeline = Common.file2string(filepath);\r
8c4eeeb6 43 \r
44 // find head comment\r
fed802b1 45 mtrheadcomment = ptnheadcomment.matcher(wholeline);\r
46 if (mtrheadcomment.find()) { //as we find only the head comment here, use 'if' not 'while'\r
47 wholeline = mtrheadcomment.replaceFirst("/** @file$1**/");\r
fed802b1 48 }\r
8c4eeeb6 49 \r
50 // find func comment\r
51 mtrfunccomment = ptnfunccomment.matcher(wholeline);\r
52 while (mtrfunccomment.find()) {\r
53 funccomment = mtrfunccomment.group(2) + "&%";\r
54 mtrcommentstructure = ptncommentstructure.matcher(funccomment);\r
55 wholeline = mtrfunccomment.replaceAll("$2$4$3$1$5");\r
56 }\r
57 \r
58 // edit func comment\r
59 mtrtempcomment = ptntempcomment.matcher(wholeline);\r
60 while (mtrtempcomment.find()) {\r
61 System.out.println("-----------------------------");\r
62 System.out.println(mtrtempcomment.group());\r
63 System.out.println("-----------------------------");\r
64 }\r
65 Common.string2file(wholeline, filepath);\r
fed802b1 66 }\r
67 }\r
68 \r
69 public static void fireAt(String path) throws Exception {\r
8c4eeeb6 70 Critic critic = new Critic();\r
71 Common.toDoAll(Common.dirCopy_(path), critic);\r
fed802b1 72 System.out.println("Critic Done");\r
73 }\r
74}\r
8c4eeeb6 75//analyze func comment\r
76/*if (mtrcommentstructure.find()) {\r
77 newcomment.append("/*++\n\n" + mtrcommentstructure.group(1) + "\n\n");\r
78 \r
79 //System.out.println("-------1-------");\r
80 //System.out.println(mtrcommentstructure.group(1));\r
81 \r
82 // arg\r
83 //System.out.println("-------2-------");\r
84 //System.out.println(mtrcommentstructure.group(2));\r
85 mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(2));\r
86 while (mtrinfequation.find()) {\r
87 newcomment.append("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
88 //System.out.println("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r
89 }\r
90 newcomment.append("\n");\r
91 // return\r
92 //System.out.println("-------3-------");\r
93 //System.out.println(mtrcommentstructure.group(3));\r
94 mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(3));\r
95 while (mtrinfequation.find()) {\r
96 newcomment.append("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
97 //System.out.println("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r
98 }\r
99 System.out.println(newcomment);\r
100} else {\r
101 System.out.println("Error: Comment Style Incorrect");\r
102}*/