KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > reader > bytecode > AbstractByteCodeSnippetFactory


1
2 package net.firstpartners.nounit.reader.bytecode;
3
4 /**
5  * Title: NoUnit - Identify Classes that are not being unit Tested
6  *
7  * Copyright (C) 2001 Paul Browne , FirstPartners.net
8  *
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  *
24  * @author Paul Browne
25  * @version 0.7
26  */

27
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import net.firstpartners.nounit.reader.ISnippetFactory;
32 import net.firstpartners.nounit.snippet.Snippets;
33 import net.firstpartners.nounit.utility.NoUnitException;
34 import net.firstpartners.nounit.utility.TextUtil;
35
36
37
38 /**
39  * Implements ISnippetFactory for Convience of Subclasses
40  */

41 abstract public class AbstractByteCodeSnippetFactory implements ISnippetFactory{
42
43     
44     /**
45      * Get the Collection of Snippets (as read from the source)
46      * @return Snippets
47      */

48     abstract public Snippets getSnippets()
49         throws NoUnitException;
50     
51     /**
52      * Clean the Hashset of values to get useful names
53      * @param dirtyValues to be cleaned
54      * @return cleanValues - i.e. proper class names
55      */

56     protected HashMap JavaDoc cleanValues(HashMap JavaDoc dirtyValues){
57         
58         //Local Variables
59
String JavaDoc tmpKey;
60         String JavaDoc tmpValue;
61         Iterator JavaDoc keys = dirtyValues.keySet().iterator();
62         HashMap JavaDoc cleanValues = new HashMap JavaDoc();
63         
64         while (keys.hasNext()) {
65          
66             //Get
67
tmpKey=(String JavaDoc)keys.next();
68             tmpValue=(String JavaDoc)dirtyValues.get(tmpKey);
69             
70             //Clean
71
tmpValue = cleanValues(tmpValue);
72             
73             // put into output
74
cleanValues.put(tmpKey,tmpValue);
75         }
76         
77         return cleanValues;
78         
79     }
80     
81     /**
82      * Clean the Hashset of values to get useful names
83      * @param valueToClean to be cleaned
84      * @return valueToClean now with proper class names
85      */

86     public String JavaDoc cleanValues(String JavaDoc valueToClean){
87         
88         //check for null
89
if (valueToClean==null) return"";
90         
91         
92         //Get rid of .
93
valueToClean=TextUtil.removeAll(valueToClean,".");
94
95         //Change / to .
96
valueToClean=TextUtil.replaceAll(valueToClean,"/",".");
97
98         //Get rid of (
99
valueToClean=TextUtil.removeAll(valueToClean,"(");
100
101         //get rid of )
102
valueToClean=TextUtil.removeAll(valueToClean,")");
103
104         //remove L at start
105
if (valueToClean.startsWith("L")) {
106
107             valueToClean=valueToClean.substring(1,valueToClean.length());
108
109         }
110
111         //remove . at start
112
if (valueToClean.startsWith(".")) {
113
114            valueToClean=valueToClean.substring(1,valueToClean.length());
115
116         }
117             
118         return valueToClean;
119     }
120     
121    /**
122      * Tidy the Method and Class names
123      * @param inString to be tidied
124      * @return String , tidied up
125      */

126     protected String JavaDoc tidyNames(String JavaDoc inString) {
127         
128         
129         String JavaDoc returnString = TextUtil.removeAll(inString," ");
130         returnString=TextUtil.removeAll(inString,"<");
131         returnString=TextUtil.removeAll(inString,">");
132         
133         //remove space at start
134
if (returnString.startsWith(" ")) {
135
136            returnString=returnString.substring(1,returnString.length());
137
138         }
139         
140         //remove . at start
141
if (returnString.startsWith(".")) {
142
143            returnString=returnString.substring(1,returnString.length());
144
145         }
146         
147         //remove < at start
148
if (returnString.startsWith("<")) {
149
150            returnString=returnString.substring(1,returnString.length());
151
152         }
153         
154         //Now replace / with .
155
returnString = TextUtil.replaceAll(returnString,"/",".");
156      
157         
158         return returnString;
159         
160     }
161 }
162
Popular Tags