Source Code Cross Referenced for JUnitPlugin.java in  » IDE-Netbeans » junit » org » netbeans » modules » junit » plugin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » junit » org.netbeans.modules.junit.plugin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 2006-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.junit.plugin;
043:
044:        //import java.util.Collections;
045:        //import java.util.EnumSet;
046:        import java.awt.EventQueue;
047:        import java.util.Map; //import java.util.Set;
048:        //import javax.lang.model.element.Element;
049:        //import javax.lang.model.element.ElementKind;
050:        //import org.netbeans.api.java.source.ElementHandle;
051:        import org.netbeans.modules.junit.JUnitPluginTrampoline;
052:        import org.openide.filesystems.FileObject;
053:
054:        /**
055:         * SPI for custom implementations of support for JUnit.
056:         * It declares methods for:
057:         * <ul>
058:         *     <li>navigation between source classes and corresponding test classes
059:         *         ({@link #getTestLocation getTestLocation},
060:         *          {@link #getTestedLocation getTestedLocation})</li>
061:         *     <li>creation of test class skeletons
062:         *         ({@link #createTests createTests})</li>
063:         * </ul>
064:         *
065:         * @author  Marian Petras
066:         */
067:        public abstract class JUnitPlugin {
068:
069:            static {
070:                JUnitPluginTrampoline.DEFAULT = new JUnitPluginTrampoline() {
071:                    public boolean createTestActionCalled(JUnitPlugin plugin,
072:                            FileObject[] filesToTest) {
073:                        return plugin.createTestActionCalled(filesToTest);
074:                    }
075:
076:                    public FileObject[] createTests(JUnitPlugin plugin,
077:                            FileObject[] filesToTest, FileObject targetRoot,
078:                            Map<CreateTestParam, Object> params) {
079:                        return plugin.createTests(filesToTest, targetRoot,
080:                                params);
081:                    }
082:
083:                    public Location getTestLocation(JUnitPlugin plugin,
084:                            Location sourceLocation) {
085:                        return plugin.getTestLocation(sourceLocation);
086:                    }
087:
088:                    public Location getTestedLocation(JUnitPlugin plugin,
089:                            Location testLocation) {
090:                        return plugin.getTestedLocation(testLocation);
091:                    }
092:
093:                    public boolean canCreateTests(JUnitPlugin plugin,
094:                            FileObject... fileObjects) {
095:                        return plugin.canCreateTests(fileObjects);
096:                    }
097:                };
098:            }
099:
100:            /**
101:             * Default constructor for use by subclasses.
102:             */
103:            protected JUnitPlugin() {
104:            }
105:
106:            /**
107:             * Enumeration of test creation parameters.
108:             */
109:            public enum CreateTestParam {
110:
111:                /**
112:                 * key for the map of test creation parameters
113:                 * - name of the test class
114:                 */
115:                CLASS_NAME(99310),
116:                /**
117:                 * key for the map of test creation parameters
118:                 * - include tests for public methods?
119:                 */
120:                INC_PUBLIC(99311),
121:                /**
122:                 * key for the map of test creation parameters
123:                 * - include tests for protected methods?
124:                 */
125:                INC_PROTECTED(99312),
126:                /**
127:                 * key for the map of test creation parameters
128:                 * - include tests for package-private methods?
129:                 */
130:                INC_PKG_PRIVATE(99313),
131:                /**
132:                 * key for the map of test creation parameters
133:                 * - generate test initializer method ({@code setup()}/{@code @Before})?
134:                 */
135:                INC_SETUP(99314),
136:                /**
137:                 * key for the map of test creation parameters
138:                 * - generate test finalizer method ({@code tearDown()}/{@code @After})?
139:                 */
140:                INC_TEAR_DOWN(99315),
141:                /**
142:                 * key for the map of test creation parameters
143:                 * - generate test class initializer method ({@code @BeforeClass})?
144:                 */
145:                INC_CLASS_SETUP(99323),
146:                /**
147:                 * key for the map of test creation parameters
148:                 * - generate test class finalizer method ({@code @AfterClass})?
149:                 */
150:                INC_CLASS_TEAR_DOWN(99324),
151:                /**
152:                 * key for the map of test creation parameters
153:                 * - generate default test method bodies?
154:                 */
155:                INC_METHOD_BODIES(99316),
156:                /**
157:                 * key for the map of test creation parameters
158:                 * - generate Javadoc comments for test methods?
159:                 */
160:                INC_JAVADOC(99317),
161:                /**
162:                 * key for the map of test creation parameters
163:                 * - generate source code hints?
164:                 */
165:                INC_CODE_HINT(99318),
166:                /**
167:                 * key for the map of test creation parameters
168:                 * - generate test classes for package-private classes?
169:                 */
170:                INC_PKG_PRIVATE_CLASS(99319),
171:                /**
172:                 * key for the map of test creation parameters
173:                 * - generate test classes for abstract classes?
174:                 */
175:                INC_ABSTRACT_CLASS(99320),
176:                /**
177:                 * key for the map of test creation parameters
178:                 * - generate test classes for exception classes?
179:                 */
180:                INC_EXCEPTION_CLASS(99321),
181:                /**
182:                 * key for the map of test creation parameters
183:                 * - generate test suites for packages?
184:                 */
185:                INC_GENERATE_SUITE(99322);
186:
187:                private final int idNumber;
188:
189:                CreateTestParam(int idNumber) {
190:                    this .idNumber = idNumber;
191:                }
192:
193:                /**
194:                 * Return a unique number of this enum element.
195:                 *
196:                 * @return  unique number of this enum element
197:                 */
198:                public int getIdNumber() {
199:                    return idNumber;
200:                }
201:
202:            }
203:
204:            /**
205:             * Data structure for storage of specification of a Java element or
206:             * a Java file.
207:             */
208:            public static final class Location {
209:                //** */
210:                //public static final Set<ElementKind> CLASS_LIKE_ELEM_TYPES;
211:                //** */
212:                //public static final Set<ElementKind> SUPPORTED_ELEM_TYPES;
213:                /**
214:                 * holds specification of a Java file
215:                 */
216:                private final FileObject fileObject;
217:
218:                //        /**
219:                //         */
220:                //        private final ElementHandle<Element> elementHandle;
221:                //        
222:                //        static {
223:                //            CLASS_LIKE_ELEM_TYPES = EnumSet.of(ElementKind.CLASS,
224:                //                                               ElementKind.INTERFACE,
225:                //                                               ElementKind.ENUM);
226:                //            EnumSet<ElementKind> elemTypes;
227:                //            elemTypes = EnumSet.copyOf(CLASS_LIKE_ELEM_TYPES);
228:                //            elemTypes.addAll(EnumSet.of(ElementKind.METHOD,
229:                //                                        ElementKind.CONSTRUCTOR,
230:                //                                        ElementKind.STATIC_INIT));
231:                //            SUPPORTED_ELEM_TYPES = Collections.unmodifiableSet(elemTypes);
232:                //        }
233:
234:                /**
235:                 * Creates a new instance.
236:                 *
237:                 * @param  fileObject  the {@code FileObject}
238:                 * 
239:                 * 
240:                 * 
241:                 */
242:                public Location(FileObject fileObject/*,
243:                                        Element element*/) {
244:                    if (fileObject == null) {
245:                        throw new IllegalArgumentException("fileObject is null");//NOI18N
246:                    }
247:
248:                    //            while ((element != null)
249:                    //                    && !SUPPORTED_ELEM_TYPES.contains(element.getKind())) {
250:                    //                element = element.getEnclosingElement();
251:                    //            }
252:
253:                    this .fileObject = fileObject;
254:                    //this.elementHandle = (element != null)
255:                    //                     ? ElementHandle.create(element)
256:                    //                     : null;
257:                }
258:
259:                /**
260:                 * Returns the {@code FileObject}.
261:                 *
262:                 * @return  the {@code FileObject} held in this instance
263:                 */
264:                public FileObject getFileObject() {
265:                    return fileObject;
266:                }
267:
268:                //        /**
269:                //         */
270:                //        public ElementHandle<Element> getElementHandle() {
271:                //            return elementHandle;
272:                //        }
273:
274:            }
275:
276:            /**
277:             * Returns a specification of a Java element or file representing test
278:             * for the given source Java element or file.
279:             *
280:             * @param  sourceLocation  specification of a Java element or file
281:             * @return  specification of a corresponding test Java element or file,
282:             *          or {@code null} if no corresponding test Java file is available
283:             */
284:            protected abstract Location getTestLocation(Location sourceLocation);
285:
286:            /**
287:             * Returns a specification of a Java element or file that is tested
288:             * by the given test Java element or test file.
289:             *
290:             * @param  testLocation  specification of a Java element or file
291:             * @return  specification of a Java element or file that is tested
292:             *          by the given Java element or file.
293:             */
294:            protected abstract Location getTestedLocation(Location testLocation);
295:
296:            /**
297:             * Informs whether the plugin is capable of creating tests at the moment.
298:             * The default implementation returns {@code true}.
299:             *
300:             * @return  {@code true} if the plugin is able of creating tests
301:             *          for the given {@code FileObject}s, {@code false} otherwise
302:             * @see  #createTests
303:             */
304:            protected boolean canCreateTests(FileObject... fileObjects) {
305:                return true;
306:            }
307:
308:            /**
309:             * Creates test classes for given source classes.
310:             * If the plugin does not support creating tests, implementation of this
311:             * method should return {@code null}.
312:             *
313:             * @param  filesToTest  source files for which test classes should be
314:             *                      created
315:             * @param  targetRoot   root folder of the target source root
316:             * @param  params  parameters of creating test class
317:             *                 - each key is an {@code Integer} whose value is equal
318:             *                 to some of the constants defined in the class;
319:             *                 the value is either
320:             *                 a {@code String} (for key with value {@code CLASS_NAME})
321:             *                 or a {@code Boolean} (for other keys)
322:             * @return  created test files, or {@code null} if no test classes were
323:             *          created and/or updated
324:             * @see  #canCreateTests
325:             */
326:            protected abstract FileObject[] createTests(
327:                    FileObject[] filesToTest, FileObject targetRoot,
328:                    Map<CreateTestParam, Object> params);
329:
330:            //    /**
331:            //     * Determines whether the &quot;create JUnit tests&quot; functionality
332:            //     * should be enabled.
333:            //     * Before this method is called, other common pre-requisites are checked
334:            //     * (only Java classes or folders selected, all of them from the same source
335:            //     * of a Java project, all of them being valid {@code DataObject}s).
336:            //     * If some of the pre-requisites are not met, the functionality is disabled
337:            //     * and this method is not called.
338:            //     *
339:            //     * @return  {@code true} if this action should be enabled,
340:            //     *          {@code false} otherwise;
341:            //     *          the default implementation returns always {@code true}
342:            //     */
343:            //    protected boolean canCreateTests() {
344:            //        return true;
345:            //    }
346:
347:            /**
348:             * Called immediately after the <em>Create Test</em> action was called.
349:             * It can be used as a trigger for additional checks and/or for displaying
350:             * user dialogs etc. It is always called from the event-dispatching thread.
351:             *
352:             * @param  selectedFiles  files and folders/packages that were selected
353:             *                        when the action was called
354:             * @return  {@code true} if the action can continue,
355:             *          {@code false} if the action should not continue;
356:             *          the default implementation returns always {@code true}
357:             */
358:            protected boolean createTestActionCalled(FileObject[] selectedFiles) {
359:                assert EventQueue.isDispatchThread();
360:
361:                return true;
362:            }
363:
364:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.