KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > generating > javadoc > JavaDoc


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.java.generating.javadoc;
21
22 import java.io.BufferedWriter JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileWriter JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.PrintWriter JavaDoc;
27 import junit.textui.TestRunner;
28 import org.netbeans.api.java.classpath.ClassPath;
29 import org.netbeans.api.java.source.JavaSource;
30 import org.netbeans.junit.NbTestCase;
31 import org.netbeans.junit.NbTestSuite;
32 import org.netbeans.test.java.Common;
33 import org.netbeans.test.java.LogTestCase;
34 import org.netbeans.test.java.Utilities;
35 import org.openide.cookies.EditorCookie;
36 import org.openide.cookies.SaveCookie;
37 import org.openide.filesystems.FileObject;
38 import org.openide.filesystems.FileUtil;
39 import org.openide.loaders.DataObject;
40 import org.openide.loaders.DataObjectNotFoundException;
41
42
43 //import org.openide.src.ClassElement;
44
//import org.openide.src.SourceException;
45

46
47 public class JavaDoc extends LogTestCase {
48     
49     private static final String JavaDoc TEST_FILE = "TestFile";
50     
51     private static final String JavaDoc packageName = "org.netbeans.test.java.generating.javadoc";
52     
53     private DataObject DO;
54     
55     private FileObject fo;
56     
57     
58     File JavaDoc tempFile;
59     
60     /** Need to be defined because of JUnit */
61     public JavaDoc(String JavaDoc name) {
62         super(name);
63     }
64     
65     public static NbTestSuite suite() {
66         NbTestSuite suite = new NbTestSuite("org.netbeans.test.java.generating.javadoc.JavaDoc");
67         suite.addTest(new JavaDoc("testClass"));
68         suite.addTest(new JavaDoc("testMethod"));
69         suite.addTest(new JavaDoc("testField"));
70         //suite.addTest(new JavaDoc("testInitializer"));
71
suite.addTest(new JavaDoc("testConstructor"));
72         return suite;
73     }
74     
75     /** Use for execution inside IDE */
76     public static void main(java.lang.String JavaDoc[] args) {
77         TestRunner.run(suite());
78     }
79     
80     public void setUp() {
81         super.setUp();
82         FileObject artefact=null;
83         try {
84             artefact=FileUtil.toFileObject(classPathWorkDir);
85             fo = artefact.getFileObject((packageName + "." + TEST_FILE).replace(".","/"));
86             DO = DataObject.find(fo);
87         } catch (Exception JavaDoc ex) {
88             ex.printStackTrace(log);
89             assertTrue(ex.toString(), false);
90         }
91     }
92     
93     public void tearDown() {
94         assertTrue(writeResult(DO));
95         try {
96             if (DO.getCookie(SaveCookie.class) != null) {
97                 ((SaveCookie) DO.getCookie(SaveCookie.class)).save();
98             }
99         } catch (Exception JavaDoc e){
100             assertTrue(e.toString(), false);
101         }
102         super.tearDown();
103         
104         
105         //Utilities.delete(tempFile);
106
}
107     
108     public void testClass() throws IOException JavaDoc {
109         JavaSource js = JavaSource.forFileObject(fo);
110         Common.addClassComment(js,"Class comment");
111      }
112     //
113
// public void testMethod() throws SourceException {
114
// clazz.getMethods()[0].getJavaDoc().setRawText("test method");
115
// writeResult();
116
// }
117
//
118
// public void testField() throws SourceException {
119
// clazz.getFields()[0].getJavaDoc().setRawText("test field");
120
// writeResult();
121
// }
122
//
123
// public void testInitializer() throws SourceException {
124
// clazz.getInitializers()[0].getJavaDoc().setRawText("test initializer");
125
// writeResult();
126
// }
127
//
128
// public void testConstructor() throws SourceException {
129
// clazz.getConstructors()[0].getJavaDoc().setRawText("test constructor");
130
// writeResult();
131
// }
132

133     protected boolean writeResult(DataObject DO) {
134         String JavaDoc result="";
135         try {
136             EditorCookie ec=(EditorCookie)(DO.getCookie(EditorCookie.class));
137             javax.swing.text.StyledDocument JavaDoc doc=ec.openDocument();
138             result=doc.getText(0, doc.getLength());
139             result=Common.unify(result);
140         } catch (Exception JavaDoc e){
141             e.printStackTrace(log);
142             return false;
143         }
144         ref(result);
145         return true;
146     }
147 }
148
Popular Tags