Add Critic.java
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 16 Aug 2006 05:49:09 +0000 (05:49 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 16 Aug 2006 05:49:09 +0000 (05:49 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1290 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/Common.java
Tools/Source/MigrationTools/org/tianocore/migration/Critic.java [new file with mode: 0644]
Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java
Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java
Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java
Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java

index 10bc2836d945b8199a3d9ee32dfc11fd6881721b..83b4e869b6e54b1aeb9e684305575244ce36abcb 100644 (file)
@@ -1,13 +1,11 @@
 package org.tianocore.migration;\r
 \r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
+import java.io.*;\r
+import java.util.regex.*;\r
+import java.util.*;\r
 \r
 public class Common {\r
-       public static String sourcefiletostring(String filename) throws Exception {\r
+       public static String file2string(String filename) throws Exception {\r
                BufferedReader rd = new BufferedReader(new FileReader(filename));\r
                StringBuffer wholefile = new StringBuffer();\r
                String line;\r
@@ -27,6 +25,48 @@ public class Common {
                        tempdir = new File(mtrseparate.group(1));\r
                        if (!tempdir.exists()) tempdir.mkdirs();\r
                }\r
+       }\r
+       \r
+       public static void string2file(String content, String filename) throws Exception {\r
+               ensureDir(filename);\r
+               PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));\r
+               outfile.append(content);\r
+               outfile.flush();\r
+               outfile.close();\r
+       }\r
+       \r
+       public static HashSet<String> dirScan(String path) {                    // use HashSet, persue speed rather than space\r
+               HashSet<String> filelist = new HashSet<String>();\r
+               String[] list = new File(path).list();\r
+               File test;\r
+\r
+               for (int i = 0 ; i < list.length ; i++) {\r
+                       test = new File(path + File.separator + list[i]);\r
+                       if (test.isDirectory()) {\r
+                               dirScan(path + File.separator + list[i]);\r
+                       } else {\r
+                               filelist.add(path + File.separator + list[i]);\r
+                       }\r
+               }\r
                \r
+               return filelist;\r
+       }\r
+       \r
+       public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo\r
+               String[] list = new File(path).list();\r
+               File test;\r
+\r
+               for (int i = 0 ; i < list.length ; i++) {\r
+                       test = new File(path + File.separator + list[i]);\r
+                       if (test.isDirectory()) {\r
+                               toDoAll(path + File.separator + list[i], fda);\r
+                       } else {\r
+                               fda.toDo(path + File.separator + list[i]);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public static interface ForDoAll {\r
+               public void toDo(String filepath) throws Exception;\r
        }\r
 }\r
diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java b/Tools/Source/MigrationTools/org/tianocore/migration/Critic.java
new file mode 100644 (file)
index 0000000..a3dbc4b
--- /dev/null
@@ -0,0 +1,33 @@
+package org.tianocore.migration;\r
+\r
+import java.util.regex.*;\r
+\r
+public class Critic implements Common.ForDoAll {\r
+       Critic() {\r
+               filepath = null;\r
+       }\r
+       Critic(String path) {\r
+               filepath = path;\r
+       }\r
+       \r
+       private String filepath = null;\r
+       \r
+       private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
+       private static Matcher mtrheadcomment;\r
+       \r
+       public void toDo(String filepath) throws Exception {\r
+               if (filepath.contains(".c") || filepath.contains(".h")) {\r
+                       String wholeline = Common.file2string(filepath);\r
+                       mtrheadcomment = ptnheadcomment.matcher(wholeline);\r
+                       if (mtrheadcomment.find()) {                    //as we find only the head comment here, use 'if' not 'while'\r
+                               wholeline = mtrheadcomment.replaceFirst("/** @file$1**/");\r
+                               Common.string2file(wholeline, filepath + "_");\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public static void fireAt(String path) throws Exception {\r
+               Common.toDoAll(path, new Critic());\r
+               System.out.println("Critic Done");\r
+       }\r
+}\r
index 9f853e42f2e53cea900fa9a2b358d4cd1467db36..d0a2fc2dd5f8e45ac9db398e20d87920eb880530 100644 (file)
@@ -27,7 +27,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
        private String modulepath;\r
        private ModuleInfo mi;\r
        \r
-       private JButton moduleButton, goButton, msaEditorButton;\r
+       private JButton moduleButton, goButton, msaEditorButton, criticButton;\r
        private JTextField moduletext;\r
        private JTextArea log;\r
        private JFileChooser fc;\r
@@ -47,6 +47,9 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
                msaEditorButton = new JButton("MsaEditor");\r
                msaEditorButton.addActionListener(this);\r
                \r
+               criticButton = new JButton("Critic");\r
+               criticButton.addActionListener(this);\r
+               \r
                moduletext = new JTextField(30);\r
                \r
                filebox = new JCheckBox("Output to logfile", true);\r
@@ -59,6 +62,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
         modulePanel.add(screenbox);\r
         modulePanel.add(goButton);\r
         modulePanel.add(msaEditorButton);\r
+        modulePanel.add(criticButton);\r
         add(modulePanel);\r
 \r
         log = new JTextArea(20,25);\r
@@ -138,6 +142,13 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
                        println(en.getMessage());\r
                }\r
         }\r
+        if ( e.getSource() == criticButton) {\r
+               try {\r
+                       Critic.fireAt(modulepath);\r
+               } catch (Exception en) {\r
+                       println(en.getMessage());\r
+               }\r
+        }\r
     }\r
     \r
     public void itemStateChanged(ItemEvent e) {\r
index 5e3bbb50d02878f0ae17f47918d825942ebcb21c..13d3436d959ed2c99c22a64b4fd58b21814f3633 100644 (file)
@@ -113,7 +113,7 @@ public class ModuleInfo {
                        show(hashr8only, "hashr8only : ");\r
                }\r
                \r
-               new MsaWriter(modulepath, this, db).flush();\r
+               new MsaWriter(modulepath, this, db, ui).flush();\r
                \r
                // remove temp directory\r
                //File tempdir = new File(modulepath + File.separator + "temp");\r
index 46fb4994bb39c8362308f4d70c1246ca27b912fd..4eb32463311b1f94b16e347644684c6170be2e47 100644 (file)
@@ -54,17 +54,13 @@ public class ModuleReader {
        }\r
        \r
        public void readInf(String name) throws Exception {\r
-               System.out.println("Parsing INF file: " + name);\r
-               BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));\r
-               String line;\r
+               System.out.println("\nParsing INF file: " + name);\r
                String wholeline;\r
-               String[] linecontext;\r
-               boolean inSrc = false;\r
                Matcher mtrinfequation;\r
                Matcher mtrsection;\r
                Matcher mtrfilename;\r
 \r
-               wholeline = Common.sourcefiletostring(modulepath + File.separator + name);\r
+               wholeline = Common.file2string(modulepath + File.separator + name);\r
                mtrsection = ptnsection.matcher(wholeline);\r
                while (mtrsection.find()) {\r
                        if (mtrsection.group(1).matches("defines")) {\r
index 35c1160aafff01e22a8289b1df97cc346f785dfa..19c3dcd984a50f0338ef6495af707507dc643a75 100644 (file)
@@ -5,12 +5,44 @@ import java.awt.event.*;
 import javax.swing.*;\r
 import javax.swing.tree.*;\r
 \r
+import org.tianocore.ModuleSurfaceAreaDocument;\r
+\r
 public class MsaTreeEditor extends JPanel {\r
        /**\r
         *  Define class Serial Version UID\r
         */\r
        private static final long serialVersionUID = 3169905938472150649L;\r
+/*\r
+       MsaTreeEditor(ModuleInfo m, UI u, ModuleSurfaceAreaDocument md) {\r
+               mi = m;\r
+               ui = u;\r
+               msadoc = md;\r
+               \r
+               //rootNode = msadoc.getDomNode();\r
+        rootNode = new DefaultMutableTreeNode("Root Node");\r
+        treeModel = new DefaultTreeModel(rootNode);\r
 \r
+        tree = new JTree(treeModel);\r
+        tree.setEditable(true);\r
+        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);\r
+        tree.setShowsRootHandles(false);\r
+        tree.addMouseListener(mouseadapter);\r
+\r
+        JScrollPane scrollPane = new JScrollPane(tree);\r
+        add(scrollPane);\r
+        \r
+        popupmenu = new JPopupMenu();\r
+        menuitemadd = new JMenuItem("addNode");\r
+        menuitemdel = new JMenuItem("deleteNode");\r
+        popupmenu.add(menuitemadd);\r
+        popupmenu.add(menuitemdel);\r
+        menuitemadd.addActionListener(actionListener);\r
+        menuitemdel.addActionListener(actionListener);\r
+        \r
+        addNode(rootNode, "1st");\r
+        addNode(rootNode, "2nd");\r
+       }\r
+*/\r
        MsaTreeEditor(ModuleInfo m, UI u) {\r
                mi = m;\r
                ui = u;\r
@@ -28,8 +60,8 @@ public class MsaTreeEditor extends JPanel {
         add(scrollPane);\r
         \r
         popupmenu = new JPopupMenu();\r
-        JMenuItem menuitemadd = new JMenuItem("addNode");\r
-        JMenuItem menuitemdel = new JMenuItem("deleteNode");\r
+        menuitemadd = new JMenuItem("addNode");\r
+        menuitemdel = new JMenuItem("deleteNode");\r
         popupmenu.add(menuitemadd);\r
         popupmenu.add(menuitemdel);\r
         menuitemadd.addActionListener(actionListener);\r
@@ -41,10 +73,12 @@ public class MsaTreeEditor extends JPanel {
        \r
        private ModuleInfo mi;\r
        private UI ui;\r
+       //private ModuleSurfaceAreaDocument msadoc;\r
        \r
        private JTree tree;\r
        private DefaultMutableTreeNode rootNode;\r
        private DefaultTreeModel treeModel;\r
+       private JMenuItem menuitemadd, menuitemdel;\r
        \r
        private JPopupMenu popupmenu;\r
        private MouseAdapter mouseadapter = new MouseAdapter() {\r
@@ -57,21 +91,32 @@ public class MsaTreeEditor extends JPanel {
        };\r
        private ActionListener actionListener = new ActionListener() {\r
                public void actionPerformed(ActionEvent ae) {\r
-                       addNode();\r
+                       if (ae.getSource() == menuitemadd) {\r
+                               addNode();\r
+                       } else if (ae.getSource() == menuitemdel) {\r
+                               delNode();\r
+                       }\r
                }\r
        };\r
        \r
-       public void addNode() {\r
+       private void delNode() {\r
+               treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));\r
+       }\r
+       \r
+       private void addNode() {\r
                addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name"));\r
-               System.out.println();\r
        }\r
        \r
-       public void addNode(DefaultMutableTreeNode parentNode, Object child) {\r
+       private void addNode(DefaultMutableTreeNode parentNode, Object child) {\r
         DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);\r
         treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());\r
         tree.scrollPathToVisible(new TreePath(childNode.getPath()));\r
        }\r
-\r
+       /*\r
+       public static void init(ModuleInfo mi, UI ui, ModuleSurfaceAreaDocument msadoc) throws Exception {\r
+               init(mi, ui);\r
+       }\r
+       */\r
        public static void init(ModuleInfo mi, UI ui) throws Exception {\r
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
 \r
index cf9c2a27190a4027f69f7f28ea0a62d20591bc98..06e18686f5a96a4947135bce8489ea558c11042d 100644 (file)
@@ -20,15 +20,17 @@ import org.tianocore.SupportedArchitectures.Enum;
 import org.apache.xmlbeans.*;\r
 \r
 public class MsaWriter {\r
-       MsaWriter(String path, ModuleInfo moduleinfo, Database database) {\r
+       MsaWriter(String path, ModuleInfo moduleinfo, Database database, UI u) {\r
                modulepath = path;\r
                mi = moduleinfo;\r
                db = database;\r
+               ui = u;\r
        }\r
 \r
        private String modulepath;\r
        private ModuleInfo mi;\r
        private Database db;\r
+       private UI ui;\r
        \r
        private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
        \r
@@ -187,6 +189,7 @@ public class MsaWriter {
         \r
                BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r
                fulfillMsadoc().save(bw, options);\r
+               //MsaTreeEditor.init(mi, ui, msadoc);\r
                bw.flush();\r
                bw.close();\r
        }\r
index 03617ab7167cc61e51d0031b20be09fced2b994a..d213693c24a7dc7b6a3e4678e0c2270d4e759bc7 100644 (file)
@@ -85,11 +85,14 @@ public class SourceFileReplacer {
                                        outname = inname;\r
                                }\r
                                ui.println("\nModifying file: " + inname);\r
+                               Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);\r
+                               /*\r
                                Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
                                outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
                                outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));\r
                                outfile.flush();\r
                                outfile.close();\r
+                               */\r
                        } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {\r
                                if (inname.contains(".H")) {\r
                                        outname = inname.replaceFirst(".H", ".h");\r
@@ -97,11 +100,14 @@ public class SourceFileReplacer {
                                        outname = inname;\r
                                }\r
                                ui.println("\nCopying file: " + inname);\r
+                               Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);\r
+                               /*\r
                                Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
                                outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
-                               outfile.append(Common.sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));\r
+                               outfile.append(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname));\r
                                outfile.flush();\r
                                outfile.close();\r
+                               */\r
                        }\r
                }\r
 \r
@@ -112,7 +118,7 @@ public class SourceFileReplacer {
        \r
        private void addr8only() throws Exception {\r
                String paragraph = null;\r
-               String line = Common.sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
+               String line = Common.file2string(Database.defaultpath + File.separator + "R8Lib.c");\r
                Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");\r
                PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));\r
                PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));\r