KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > xdoclet > typesystem > impl > declaration > TypeDeclarationImpl


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

18 package org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.declaration;
19
20 import org.apache.beehive.netui.compiler.typesystem.declaration.FieldDeclaration;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration;
22 import org.apache.beehive.netui.compiler.typesystem.declaration.PackageDeclaration;
23 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
24 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.WrapperFactory;
25 import org.apache.beehive.netui.compiler.typesystem.type.InterfaceType;
26
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import xjavadoc.XClass;
31 import xjavadoc.XField;
32 import xjavadoc.XMethod;
33
34 public class TypeDeclarationImpl
35         extends MemberDeclarationImpl
36         implements TypeDeclaration
37 {
38     private InterfaceType[] _superInterfaces;
39     private MethodDeclaration[] _methods;
40     private TypeDeclaration[] _nestedTypes;
41     private FieldDeclaration[] _fields;
42     
43     public TypeDeclarationImpl( XClass delegate )
44     {
45         super( delegate );
46     }
47     
48     public PackageDeclaration getPackage()
49     {
50         return WrapperFactory.get().getPackageDeclaration( getDelegateXClass().getContainingPackage() );
51     }
52
53     public String JavaDoc getQualifiedName()
54     {
55         return getDelegateXClass().getQualifiedName();
56     }
57
58     public InterfaceType[] getSuperinterfaces()
59     {
60         if ( _superInterfaces == null )
61         {
62             Collection JavaDoc delegateCollection = getDelegateXClass().getSuperInterfaceElements();
63             InterfaceType[] array = new InterfaceType[delegateCollection.size()];
64             int j = 0;
65             for ( Iterator JavaDoc i = delegateCollection.iterator(); i.hasNext(); )
66             {
67                 array[j++] = WrapperFactory.get().getInterfaceType( ( XClass ) i.next() );
68             }
69             _superInterfaces = array;
70         }
71
72         return _superInterfaces;
73     }
74
75     public FieldDeclaration[] getFields()
76     {
77         if ( _fields == null )
78         {
79             Collection JavaDoc delegateCollection = getDelegateXClass().getFields();
80             FieldDeclaration[] array = new FieldDeclaration[delegateCollection.size()];
81             int j = 0;
82             for ( Iterator JavaDoc i = delegateCollection.iterator(); i.hasNext(); )
83             {
84                 array[j++] = WrapperFactory.get().getFieldDeclaration( ( XField ) i.next() );
85             }
86             _fields = array;
87         }
88
89         return _fields;
90     }
91
92     public MethodDeclaration[] getMethods()
93     {
94         if ( _methods == null )
95         {
96             Collection JavaDoc delegateCollection = getDelegateXClass().getMethods();
97             MethodDeclaration[] array = new MethodDeclaration[delegateCollection.size()];
98             int j = array.length;
99             
100             // Doing this loop in reverse makes the ordering like what we see in apt/Mirror.
101
for ( Iterator JavaDoc i = delegateCollection.iterator(); i.hasNext(); )
102             {
103                 array[--j] = WrapperFactory.get().getMethodDeclaration( ( XMethod ) i.next() );
104             }
105             _methods = array;
106         }
107
108         return _methods;
109     }
110
111     public TypeDeclaration[] getNestedTypes()
112     {
113         if ( _nestedTypes == null )
114         {
115             Collection JavaDoc delegateCollection = getDelegateXClass().getInnerClasses();
116             TypeDeclaration[] array = new TypeDeclaration[delegateCollection.size()];
117             int j = 0;
118             for ( Iterator JavaDoc i = delegateCollection.iterator(); i.hasNext(); )
119             {
120                 array[j++] = WrapperFactory.get().getTypeDeclaration( ( XClass ) i.next() );
121             }
122             _nestedTypes = array;
123         }
124
125         return _nestedTypes;
126     }
127
128     public boolean equals( Object JavaDoc o )
129     {
130         return super.equals( o ) ||
131                ( o instanceof TypeDeclaration && ( ( TypeDeclaration ) o ).getQualifiedName().equals( getQualifiedName() ));
132     }
133
134     protected XClass getDelegateXClass()
135     {
136         return ( XClass ) super.getDelegate();
137     }
138 }
139
Popular Tags