KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > AptType


1 package org.apache.beehive.controls.runtime.generator;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import java.io.IOException JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24
25 import com.sun.mirror.apt.Filer;
26 import com.sun.mirror.declaration.TypeDeclaration;
27 import com.sun.mirror.declaration.TypeParameterDeclaration;
28
29 /**
30  * The AptType abstract class defines a base set of methods that are generally available
31  * for template usage on type declaration objects
32  */

33 public class AptType
34 {
35     /**
36      * Sets the TypeDeclaration associated with this AptType.
37      */

38     protected void setDeclaration(TypeDeclaration typeDecl)
39     {
40         _typeDecl = typeDecl;
41     }
42
43     /**
44      * Returns the fully qualified classname of this AptType
45      */

46     public String JavaDoc getClassName()
47     {
48         if ( _typeDecl == null)
49             return "";
50
51         return _typeDecl.getQualifiedName();
52     }
53
54     /**
55      * Returns the base package name associated with the AptType
56      */

57     public String JavaDoc getPackage()
58     {
59         if ( _typeDecl == null)
60             return "";
61
62         return _typeDecl.getPackage().getQualifiedName();
63     }
64
65     /**
66      * Returns the unqualified class name associated with the AptType
67      */

68     public String JavaDoc getShortName()
69     {
70         if ( _typeDecl == null )
71             return "";
72         
73         return _typeDecl.getSimpleName();
74     }
75
76     /**
77      * Helper method to return type parameter information
78      */

79     private String JavaDoc getFormalTypeParameters(boolean namesOnly)
80     {
81         Collection JavaDoc<TypeParameterDeclaration> ftColl = _typeDecl.getFormalTypeParameters();
82         if (ftColl.size() == 0)
83             return "";
84
85         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("<");
86         boolean isFirst = true;
87         for (TypeParameterDeclaration tpDecl : ftColl)
88         {
89             if (!isFirst)
90                 sb.append(",");
91             else
92                 isFirst = false;
93         
94             if (namesOnly)
95                 sb.append(tpDecl.getSimpleName());
96             else
97                 sb.append(tpDecl.toString());
98         }
99         sb.append(">");
100         return sb.toString();
101     }
102
103     /**
104      * Returns the full formal type parameter declaration associated with the type declaration
105      */

106     public String JavaDoc getFormalTypeParameters()
107     {
108         return getFormalTypeParameters(false);
109     }
110
111     /**
112      * Returns the name of any formal type parameter names associated with the type declaration.
113      */

114     public String JavaDoc getFormalTypeParameterNames()
115     {
116         return getFormalTypeParameters(true);
117     }
118
119     /**
120      * Returns the short name and the names of any formal type parameters associated with
121      * the type. The format is suitable for use in location (such as variable declarations
122      * or extends clauses) where you want formal type parameters listed.
123      */

124     public String JavaDoc getFormalShortName()
125     {
126         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(getShortName());
127         sb.append(getFormalTypeParameterNames());
128         return sb.toString();
129     }
130
131     /**
132      * Returns the class name and the names of any formal type parameters associated with
133      * the type. The format is suitable for use in location (such as variable declarations
134      * or extends clauses) where you want formal type parameters listed.
135      */

136     public String JavaDoc getFormalClassName()
137     {
138         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(getClassName());
139         sb.append(getFormalTypeParameterNames());
140         return sb.toString();
141     }
142
143     /**
144      * Returns the underlying type declaration name
145      */

146     public TypeDeclaration getTypeDeclaration()
147     {
148         return _typeDecl;
149     }
150
151     TypeDeclaration _typeDecl;
152 }
153
Popular Tags