KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > comments > JMIUtils


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 package org.netbeans.modules.javadoc.comments;
20
21 import org.netbeans.jmi.javamodel.Resource;
22 import org.netbeans.jmi.javamodel.JavaClass;
23 import org.netbeans.jmi.javamodel.MultipartId;
24
25 import javax.jmi.reflect.JmiException;
26 import java.util.List JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * helpers over jmi api
32  */

33 public final class JMIUtils {
34     /**
35      * Gets all classes recursively, both top-level and inner.
36      * @param res java resource
37      * @return all classes
38      * @throws javax.jmi.reflect.JmiException
39      */

40     public static List JavaDoc/*<JavaClass>*/ getAllClasses(Resource res) throws JmiException {
41         List JavaDoc/*<JavaClass>*/ l = new LinkedList JavaDoc/*<JavaClass>*/();
42         Iterator JavaDoc/*<JavaClass>*/ it = res.getClassifiers().iterator();
43         while (it.hasNext()) {
44             addAllClasses((JavaClass) it.next(), l);
45         }
46         return l;
47     }
48
49     public static String JavaDoc multipartIdToName(MultipartId id) {
50         LinkedList JavaDoc list = new LinkedList JavaDoc();
51         while (id != null) {
52             
53             if (id.getTypeArguments().size() > 0) {
54                 return "java.lang.Object"; // NOI18N
55
}
56             
57             list.addFirst(id.getName());
58             id = id.getParent();
59         }
60         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
61         for (Iterator JavaDoc iter = list.iterator(); iter.hasNext();) {
62             buf.append((String JavaDoc)iter.next());
63             if (iter.hasNext())
64                 buf.append('.');
65         }
66         return buf.toString();
67     }
68     
69     private static void addAllClasses(JavaClass jc, List JavaDoc/*<JavaClass>*/ container) throws JmiException {
70         container.add(jc);
71         Iterator JavaDoc it = jc.getFeatures().iterator();
72         while (it.hasNext()) {
73             Object JavaDoc feature = it.next();
74             if (feature instanceof JavaClass) {
75                 addAllClasses((JavaClass) feature, container);
76             }
77         }
78     }
79     
80 }
81
Popular Tags