KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > genmodel > GenActionOutputModel


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.genmodel;
19
20 import org.apache.beehive.netui.compiler.model.ActionOutputModel;
21 import org.apache.beehive.netui.compiler.JpfLanguageConstants;
22 import org.apache.beehive.netui.compiler.CompilerUtils;
23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
24 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
25 import org.apache.beehive.netui.compiler.typesystem.type.ArrayType;
26 import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance;
27 import org.apache.beehive.netui.compiler.typesystem.type.DeclaredType;
28 import org.apache.beehive.netui.compiler.typesystem.type.PrimitiveType;
29
30
31 public class GenActionOutputModel
32         extends ActionOutputModel
33         implements JpfLanguageConstants
34 {
35     public GenActionOutputModel( AnnotationInstance annotation, ClassDeclaration jclass )
36     {
37         setName( CompilerUtils.getString( annotation, NAME_ATTR, true ) );
38         
39         Boolean JavaDoc required = CompilerUtils.getBoolean( annotation, REQUIRED_ATTR, false );
40         boolean nullable = ! required.booleanValue();
41         setNullable( nullable );
42         
43         //
44
// Get the base type, and add "[]" to it for arrays.
45
//
46
TypeInstance baseType = CompilerUtils.getReferenceType( annotation, TYPE_ATTR, true );
47         StringBuffer JavaDoc arrayDimensions = new StringBuffer JavaDoc();
48         while ( baseType instanceof ArrayType )
49         {
50             arrayDimensions.append( ARRAY_TYPE_SUFFIX );
51             baseType = ( ( ArrayType ) baseType ).getComponentType();
52         }
53         
54         String JavaDoc baseTypeName;
55         if ( baseType instanceof PrimitiveType )
56         {
57             baseTypeName = ( ( PrimitiveType ) baseType ).getKind().toString().toLowerCase();
58         }
59         else
60         {
61             assert baseType instanceof DeclaredType : baseType.getClass().getName(); // checker should enforce this
62
baseTypeName = CompilerUtils.getLoadableName( ( DeclaredType ) baseType );
63         }
64         
65         setType( baseTypeName + arrayDimensions.toString() );
66     }
67 }
68
Popular Tags