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