KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > typesystem > impl > WrapperFactory


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.typesystem.impl;
19
20 import org.apache.beehive.netui.compiler.typesystem.declaration.*;
21 import org.apache.beehive.netui.compiler.typesystem.impl.declaration.*;
22 import org.apache.beehive.netui.compiler.typesystem.impl.type.AnnotationTypeImpl;
23 import org.apache.beehive.netui.compiler.typesystem.impl.type.ArrayTypeImpl;
24 import org.apache.beehive.netui.compiler.typesystem.impl.type.ClassTypeImpl;
25 import org.apache.beehive.netui.compiler.typesystem.impl.type.InterfaceTypeImpl;
26 import org.apache.beehive.netui.compiler.typesystem.impl.type.PrimitiveTypeImpl;
27 import org.apache.beehive.netui.compiler.typesystem.impl.type.TypeVariableImpl;
28 import org.apache.beehive.netui.compiler.typesystem.impl.type.VoidTypeImpl;
29 import org.apache.beehive.netui.compiler.typesystem.impl.type.ErrorTypeImpl;
30 import org.apache.beehive.netui.compiler.typesystem.type.AnnotationType;
31 import org.apache.beehive.netui.compiler.typesystem.type.ClassType;
32 import org.apache.beehive.netui.compiler.typesystem.type.DeclaredType;
33 import org.apache.beehive.netui.compiler.typesystem.type.InterfaceType;
34 import org.apache.beehive.netui.compiler.typesystem.type.PrimitiveType;
35 import org.apache.beehive.netui.compiler.typesystem.type.ReferenceType;
36 import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance;
37 import org.apache.beehive.netui.compiler.typesystem.type.TypeVariable;
38 import org.apache.beehive.netui.compiler.typesystem.type.VoidType;
39
40 import java.util.ArrayList JavaDoc;
41 import java.util.List JavaDoc;
42
43 public class WrapperFactory
44 {
45     private static final WrapperFactory INSTANCE = new WrapperFactory();
46     
47     private WrapperFactory()
48     {
49     }
50     
51     public static WrapperFactory get()
52     {
53         return INSTANCE;
54     }
55     
56     public TypeInstance getTypeInstance( com.sun.mirror.type.TypeMirror delegate )
57     {
58         if ( delegate == null ) return null;
59         
60         if ( delegate instanceof com.sun.mirror.type.ReferenceType )
61         {
62             return getReferenceType( ( com.sun.mirror.type.ReferenceType ) delegate );
63         }
64         else if ( delegate instanceof com.sun.mirror.type.VoidType )
65         {
66             return getVoidType( ( com.sun.mirror.type.VoidType ) delegate );
67         }
68         else
69         {
70             assert delegate instanceof com.sun.mirror.type.PrimitiveType : delegate.getClass().getName();
71             return getPrimitiveType( ( com.sun.mirror.type.PrimitiveType ) delegate );
72         }
73     }
74     
75     public VoidType getVoidType( com.sun.mirror.type.VoidType delegate )
76     {
77         if ( delegate == null ) return null;
78         return new VoidTypeImpl( delegate );
79     }
80     
81     public ReferenceType getReferenceType( com.sun.mirror.type.ReferenceType delegate )
82     {
83         if ( delegate == null ) return null;
84         
85         if ( delegate instanceof com.sun.mirror.type.DeclaredType )
86         {
87             return getDeclaredType( ( com.sun.mirror.type.DeclaredType ) delegate );
88         }
89         else if ( delegate instanceof com.sun.mirror.type.ArrayType )
90         {
91             return new ArrayTypeImpl( ( com.sun.mirror.type.ArrayType ) delegate );
92         }
93         else
94         {
95             assert delegate instanceof com.sun.mirror.type.TypeVariable : delegate.getClass().getName();
96             return getTypeVariable( ( com.sun.mirror.type.TypeVariable ) delegate );
97         }
98     }
99     
100     
101     public PrimitiveType getPrimitiveType( com.sun.mirror.type.PrimitiveType delegate )
102     {
103         if ( delegate == null ) return null;
104         
105         return new PrimitiveTypeImpl( delegate );
106     }
107     
108     public TypeVariable getTypeVariable( com.sun.mirror.type.TypeVariable delegate )
109     {
110         if ( delegate == null ) return null;
111         
112         return new TypeVariableImpl( delegate );
113     }
114     
115     public DeclaredType getDeclaredType( com.sun.mirror.type.DeclaredType delegate )
116     {
117         if ( delegate == null ) return null;
118         
119         if ( delegate instanceof com.sun.mirror.type.ClassType )
120         {
121             return getClassType( ( com.sun.mirror.type.ClassType ) delegate );
122         }
123         else if ( delegate instanceof com.sun.mirror.type.InterfaceType )
124         {
125             return getInterfaceType( ( com.sun.mirror.type.InterfaceType ) delegate );
126         }
127
128         //
129
// This must be an error type, which is indicated by a DeclaredType with no type declaration.
130
//
131
assert delegate.getDeclaration() == null :
132                 "expected error type, got " + delegate.toString() + " with declaration " + delegate.getDeclaration();
133         return getErrorType( delegate );
134     }
135
136     public DeclaredType getErrorType( com.sun.mirror.type.DeclaredType delegate )
137     {
138         if ( delegate == null ) return null;
139         return new ErrorTypeImpl( delegate );
140     }
141
142     
143     public ClassType getClassType( com.sun.mirror.type.ClassType delegate )
144     {
145         if ( delegate == null ) return null;
146         
147         return new ClassTypeImpl( delegate );
148     }
149     
150     public InterfaceType getInterfaceType( com.sun.mirror.type.InterfaceType delegate )
151     {
152         if ( delegate == null ) return null;
153         
154         if ( delegate instanceof com.sun.mirror.type.AnnotationType )
155         {
156             return getAnnotationType( ( com.sun.mirror.type.AnnotationType ) delegate );
157         }
158         
159         return new InterfaceTypeImpl( delegate );
160     }
161     
162     public AnnotationType getAnnotationType( com.sun.mirror.type.AnnotationType delegate )
163     {
164         if ( delegate == null ) return null;
165         
166         return new AnnotationTypeImpl( delegate );
167     }
168     
169     public AnnotationInstance getAnnotationInstance( com.sun.mirror.declaration.AnnotationMirror delegate )
170     {
171         if ( delegate == null ) return null;
172         
173         return new AnnotationInstanceImpl( delegate );
174     }
175     
176     public AnnotationValue getAnnotationValue( com.sun.mirror.declaration.AnnotationValue delegate )
177     {
178         if ( delegate == null ) return null;
179         
180         return new AnnotationValueImpl( delegate );
181     }
182     
183     public Declaration getDeclaration( com.sun.mirror.declaration.Declaration delegate )
184     {
185         if ( delegate == null ) return null;
186         
187         if ( delegate instanceof com.sun.mirror.declaration.MemberDeclaration )
188         {
189             return getMemberDeclaration( ( com.sun.mirror.declaration.MemberDeclaration ) delegate );
190         }
191         else if ( delegate instanceof com.sun.mirror.declaration.ParameterDeclaration )
192         {
193             return getParameterDeclaration( ( com.sun.mirror.declaration.ParameterDeclaration ) delegate );
194         }
195         else
196         {
197             assert delegate instanceof com.sun.mirror.declaration.TypeParameterDeclaration : delegate.getClass().getName();
198             return getTypeParameterDeclaration( ( com.sun.mirror.declaration.TypeParameterDeclaration ) delegate );
199         }
200     }
201     
202     public MemberDeclaration getMemberDeclaration( com.sun.mirror.declaration.MemberDeclaration delegate )
203     {
204         if ( delegate == null ) return null;
205         
206         if ( delegate instanceof com.sun.mirror.declaration.TypeDeclaration )
207         {
208             return getTypeDeclaration( ( com.sun.mirror.declaration.TypeDeclaration ) delegate );
209         }
210         else if ( delegate instanceof com.sun.mirror.declaration.ExecutableDeclaration )
211         {
212             return getExecutableDeclaration( ( com.sun.mirror.declaration.ExecutableDeclaration ) delegate );
213         }
214         else
215         {
216             assert delegate instanceof com.sun.mirror.declaration.FieldDeclaration : delegate.getClass().getName();
217             return getFieldDeclaration( ( com.sun.mirror.declaration.FieldDeclaration ) delegate );
218         }
219     }
220     
221     public TypeDeclaration getTypeDeclaration( com.sun.mirror.declaration.TypeDeclaration delegate )
222     {
223         if ( delegate == null ) return null;
224         
225         if ( delegate instanceof com.sun.mirror.declaration.ClassDeclaration )
226         {
227             return getClassDeclaration( ( com.sun.mirror.declaration.ClassDeclaration ) delegate );
228         }
229         else
230         {
231             assert delegate instanceof com.sun.mirror.declaration.InterfaceDeclaration : delegate.getClass().getName();
232             return getInterfaceDeclaration( ( com.sun.mirror.declaration.InterfaceDeclaration ) delegate );
233         }
234     }
235     
236     public ClassDeclaration getClassDeclaration( com.sun.mirror.declaration.ClassDeclaration delegate )
237     {
238         if ( delegate == null ) return null;
239         
240         return new ClassDeclarationImpl( delegate );
241     }
242     
243     public InterfaceDeclaration getInterfaceDeclaration( com.sun.mirror.declaration.InterfaceDeclaration delegate )
244     {
245         if ( delegate == null ) return null;
246         
247         if ( delegate instanceof com.sun.mirror.declaration.AnnotationTypeDeclaration )
248         {
249             return getAnnotationTypeDeclaration( ( com.sun.mirror.declaration.AnnotationTypeDeclaration ) delegate );
250         }
251         
252         return new InterfaceDeclarationImpl( delegate );
253     }
254     
255     public ExecutableDeclaration getExecutableDeclaration( com.sun.mirror.declaration.ExecutableDeclaration delegate )
256     {
257         if ( delegate == null ) return null;
258         
259         if ( delegate instanceof com.sun.mirror.declaration.MethodDeclaration )
260         {
261             return getMethodDeclaration( ( com.sun.mirror.declaration.MethodDeclaration ) delegate );
262         }
263         
264         assert delegate instanceof com.sun.mirror.declaration.ConstructorDeclaration : delegate.getClass().getName();
265         return getConstructorDeclaration( ( com.sun.mirror.declaration.ConstructorDeclaration ) delegate );
266     }
267     
268     public ParameterDeclaration getParameterDeclaration( com.sun.mirror.declaration.ParameterDeclaration delegate )
269     {
270         if ( delegate == null ) return null;
271         
272         return new ParameterDeclarationImpl( delegate );
273     }
274     
275     public PackageDeclaration getPackageDeclaration( com.sun.mirror.declaration.PackageDeclaration delegate )
276     {
277         if ( delegate == null ) return null;
278         
279         return new PackageDeclarationImpl( delegate );
280     }
281     
282     public ConstructorDeclaration getConstructorDeclaration( com.sun.mirror.declaration.ConstructorDeclaration delegate )
283     {
284         if ( delegate == null ) return null;
285         
286         return new ConstructorDeclarationImpl( delegate );
287     }
288     
289     public MethodDeclaration getMethodDeclaration( com.sun.mirror.declaration.MethodDeclaration delegate )
290     {
291         if ( delegate == null ) return null;
292         
293         if ( delegate instanceof com.sun.mirror.declaration.AnnotationTypeElementDeclaration )
294         {
295             return getAnnotationTypeElementDeclaration( ( com.sun.mirror.declaration.AnnotationTypeElementDeclaration ) delegate );
296         }
297         
298         return new MethodDeclarationImpl( delegate );
299     }
300     
301     public AnnotationTypeDeclaration getAnnotationTypeDeclaration( com.sun.mirror.declaration.AnnotationTypeDeclaration delegate )
302     {
303         if ( delegate == null ) return null;
304         
305         return new AnnotationTypeDeclarationImpl( delegate );
306     }
307     
308     public AnnotationTypeElementDeclaration getAnnotationTypeElementDeclaration( com.sun.mirror.declaration.AnnotationTypeElementDeclaration delegate )
309     {
310         if ( delegate == null ) return null;
311         
312         return new AnnotationTypeElementDeclarationImpl( delegate );
313     }
314     
315     public FieldDeclaration getFieldDeclaration( com.sun.mirror.declaration.FieldDeclaration delegate )
316     {
317         if ( delegate == null ) return null;
318         
319         return new FieldDeclarationImpl( delegate );
320     }
321     
322     public TypeParameterDeclaration getTypeParameterDeclaration( com.sun.mirror.declaration.TypeParameterDeclaration delegate )
323     {
324         if ( delegate == null ) return null;
325         
326         return new TypeParameterDeclarationImpl( delegate );
327     }
328     
329     public Object JavaDoc getWrapper( Object JavaDoc o )
330     {
331         if ( o == null ) return null;
332         
333         if ( o instanceof com.sun.mirror.type.TypeMirror )
334         {
335             return getTypeInstance( ( com.sun.mirror.type.TypeMirror ) o );
336         }
337         else if ( o instanceof com.sun.mirror.declaration.Declaration )
338         {
339             return getDeclaration( ( com.sun.mirror.declaration.Declaration ) o );
340         }
341         else if ( o instanceof com.sun.mirror.declaration.AnnotationMirror )
342         {
343             return getAnnotationInstance( ( com.sun.mirror.declaration.AnnotationMirror ) o );
344         }
345         else if ( o instanceof com.sun.mirror.declaration.AnnotationValue )
346         {
347             return getAnnotationValue( ( com.sun.mirror.declaration.AnnotationValue ) o );
348         }
349         else if ( o instanceof com.sun.mirror.declaration.PackageDeclaration )
350         {
351             return getPackageDeclaration( ( com.sun.mirror.declaration.PackageDeclaration ) o );
352         }
353         else if ( o instanceof List JavaDoc )
354         {
355             List JavaDoc list = ( List JavaDoc ) o;
356             ArrayList JavaDoc ret = new ArrayList JavaDoc( list.size() );
357             
358             for ( Object JavaDoc i : list )
359             {
360                 ret.add( getWrapper( i ) );
361             }
362             
363             return ret;
364         }
365         
366         return o;
367     }
368 }
369
Popular Tags