1 6 7 package org.netbeans.modules.piaget.analyze; 8 9 import java.util.Hashtable ; 10 import java.util.Enumeration ; 11 import java.io.File ; 12 import java.util.HashSet ; 13 import java.util.Iterator ; 14 import org.netbeans.modules.piagetproject.property.Property; 15 16 20 public class TCRAnalyzer extends TCRParser{ 21 22 boolean editorInUse; 23 int tabSwitch, fields, constructors, methods, beanPatterns, tabCounter, maxTabs; 24 private Hashtable extensions, windows; 25 HashSet openedWin; 26 WindowData editorSum, previousWindow, activeB4LostFocus; 27 28 29 public TCRAnalyzer(File f) { 30 super(f); 31 } 32 33 protected void init(){ 34 editorInUse = false; 35 windows = new Hashtable (); 36 extensions = new Hashtable (); 37 maxTabs = fields = constructors = methods = beanPatterns = tabCounter = tabSwitch = 0; 38 39 editorSum = new WindowData(false, Property.EDITOR); 40 windows.put(Property.EDITOR, editorSum); 41 editorSum.chartColor = java.awt.Color.RED; 42 43 WindowData outNB = new WindowData(false, Property.OUT); 44 windows.put(Property.OUT, outNB); 45 outNB.chartColor = java.awt.Color.RED; 46 } 47 48 protected void analyzeNode(String parent, String node){ 49 matchFieldName(parent); 50 matchFieldName(node); 51 } 52 53 protected void analyzeOpen(String windowId, boolean editor){ 54 WindowData w; 55 if(windows.containsKey((Object )windowId)){ 56 w = (WindowData)windows.get((Object )windowId); 57 } else { 58 w = new WindowData(editor,windowId); 59 windows.put((Object )windowId,w); 60 if(editor){ 61 editorSum.open(timestamp); 62 w.chartColor = java.awt.Color.BLUE; 63 tabCounter++; 64 if(tabCounter>maxTabs)maxTabs = tabCounter; 65 extension(windowId); 66 } 67 } 68 w.open(timestamp); 69 } 70 71 73 protected void analyzeLOST(){ 74 Enumeration e = windows.elements(); 78 openedWin = new HashSet (); 79 while(e.hasMoreElements()){ 80 WindowData w = (WindowData)e.nextElement(); 81 if(w.openB==false) continue; 82 w.close(timestamp); 83 openedWin.add(w); 84 } 85 86 activeB4LostFocus = previousWindow; 87 analyzeActivated(Property.OUT, false); 88 } 89 90 92 protected void analyzeGAINED(){ 93 if(openedWin!=null){ 94 Iterator it = openedWin.iterator(); 95 while(it.hasNext()){ 96 WindowData w = (WindowData)it.next(); 97 w.open(timestamp); 98 } 99 } 100 if(activeB4LostFocus!=null) analyzeActivated(activeB4LostFocus.name,activeB4LostFocus.editor); 101 else if(previousWindow!=null)analyzeActivated(previousWindow.name,previousWindow.editor); 102 } 103 104 105 protected void analyzeClose(String windowId, boolean editor){ 106 WindowData w; 107 if(editor)tabCounter--; 108 if(windows.containsKey((Object )windowId)){ 109 w = (WindowData)windows.get((Object )windowId); 110 w.close(timestamp); 111 } else { 112 myError("close without open:"+windowId); 113 } 114 } 115 116 protected void analyzeActivated(String windowId, boolean editor){ 117 WindowData currentWindow; 118 if(previousWindow!=null){ 119 previousWindow.deactivated(timestamp); 120 editorSum.deactivated(timestamp); 121 } 122 if(!windows.containsKey((Object )windowId)) analyzeOpen(windowId,editor); 123 currentWindow = (WindowData)windows.get((Object )windowId); 124 currentWindow.activated(timestamp); 125 previousWindow = currentWindow; 126 if(editorInUse&&editor)tabSwitch++; 127 if(editor)editorSum.activated(timestamp); 128 editorInUse = editor; 129 } 130 131 protected void eof(){ 132 Enumeration e = windows.elements(); 133 WindowData w; 134 while(e.hasMoreElements()){ 135 w = (WindowData)e.nextElement(); 136 w.end(timestamp); 137 } 139 print(); 140 } 141 142 protected void myError(String msg){ 143 error("ANALYZER:"+msg); 144 } 145 146 private void matchFieldName(String s){ 147 if(s==null) return; 148 if(s.equalsIgnoreCase("Fields")) { 149 fields++; 150 return; 151 } 152 if(s.equalsIgnoreCase("Constructors")) { 153 constructors++; 154 return; 155 } 156 if(s.equalsIgnoreCase("Methods")) { 157 methods++; 158 return; 159 } 160 if(s.equalsIgnoreCase("BeanPatterns")) { 161 beanPatterns++; 162 return; 163 } 164 } 165 166 private void extension(String s){ 167 int index = s.lastIndexOf('.'); 168 if(index>0){ 169 Object ext; 170 ext = (Object )s.substring(index+1); 171 int i = 1; 172 if(extensions.containsKey(ext)){ 173 i = ((Integer )extensions.get(ext)).intValue(); 174 i++; 175 } 176 extensions.put(ext,(Object )new Integer (i)); 177 } 178 } 179 180 private void printWindows(){ 181 Enumeration e = windows.elements(); 182 if(e.hasMoreElements()) Analyzer.writeComment("WINDOWS:"); 183 while(e.hasMoreElements()){ 184 WindowData w = (WindowData)e.nextElement(); 185 Analyzer.writeComment(" * "+w.name+"\topen: "+prettyTime(w.open)+"\tactivated: "+prettyTime(w.activated)); 186 String win = w.name; 187 win = win.replaceAll(":", ""); 190 win = win.replaceAll("=", ""); 191 Analyzer.writeProperty(Property.WINDOW + win, w.open + " " + w.activated); 192 } 193 } 194 195 private void printEditor(){ 196 197 Analyzer.writeComment("Max editor tabs simultaneously opened: "+maxTabs); 198 Analyzer.writeProperty(Property.MAX_TABS, Integer.toString(maxTabs)); 199 200 Analyzer.writeComment("Tab switches: " + tabSwitch); 201 Analyzer.writeProperty(Property.TAB_SWITCH, Integer.toString(tabSwitch)); 202 203 if(tabSwitch>0){ 204 WindowData editor = (WindowData)windows.get(Property.EDITOR); 205 double time = new Long (editor.activated).doubleValue(); 206 long freq = new Double (time/tabSwitch).longValue(); 207 Analyzer.writeComment("tab switch period: "+prettyTime(freq)); 208 Analyzer.writeProperty(Property.TAB_PERIOD, Long.toString(freq)); 209 } 210 } 211 212 private void printExtension(){ 213 Enumeration e = extensions.keys(); 214 String ext, count; 215 while(e.hasMoreElements()){ 216 ext = (String )e.nextElement(); 217 count = ((Integer )extensions.get((Object )ext)).toString(); 218 Analyzer.writeComment("filetype extension: "+ext+"\t# of occurences:"+count); 219 Analyzer.writeProperty(Property.EXTENSION + ext, count); 220 } 221 } 222 223 private void printGal(){ 224 long duration = timestamp-startTime; 225 Analyzer.writeComment("Duration of session:" + prettyTime(duration)); 226 Analyzer.writeProperty(Property.TOTAL_TIME, Long.toString(duration)); 227 } 228 229 private void printFields(){ 230 Analyzer.writeComment("usage of Java class nodes - fields: "+fields+" constructors: "+constructors+" methods: "+methods+" beans: "+beanPatterns); 231 Analyzer.writeProperty(Property.CN_FIELDS, Integer.toString(fields)); 232 Analyzer.writeProperty(Property.CN_METHODS, Integer.toString(methods)); 233 Analyzer.writeProperty(Property.CN_CONS, Integer.toString(constructors)); 234 Analyzer.writeProperty(Property.CN_BEANS, Integer.toString(beanPatterns)); 235 } 236 237 private void print(){ 238 printGal(); 239 printWindows(); 240 printEditor(); 241 printExtension(); 242 printFields(); 243 } 244 245 } 246 | Popular Tags |