KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > grammar > TypeNameType


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.grammar;
19
20 import org.apache.beehive.netui.compiler.AnnotationMemberType;
21 import org.apache.beehive.netui.compiler.CompilerUtils;
22 import org.apache.beehive.netui.compiler.AnnotationGrammar;
23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
24 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
25 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
27 import org.apache.beehive.netui.compiler.typesystem.type.ArrayType;
28 import org.apache.beehive.netui.compiler.typesystem.type.ReferenceType;
29 import org.apache.beehive.netui.compiler.typesystem.type.PrimitiveType;
30 import org.apache.beehive.netui.compiler.typesystem.type.VoidType;
31
32 public class TypeNameType
33         extends AnnotationMemberType
34 {
35     private String JavaDoc _requiredSuperclassName;
36     private boolean _allowArrayType;
37
38
39     public TypeNameType( String JavaDoc requiredSuperclassName, boolean allowArrayType, String JavaDoc requiredRuntimeVersion,
40                          AnnotationGrammar parentGrammar )
41     {
42         super( requiredRuntimeVersion, parentGrammar );
43         _requiredSuperclassName = requiredSuperclassName;
44         _allowArrayType = allowArrayType;
45     }
46
47     /**
48      * @return the fully-qualified type (ClassDeclaration)
49      */

50     
51     public Object JavaDoc onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value,
52                            AnnotationInstance[] parentAnnotations, MemberDeclaration classMember,
53                            int annotationArrayIndex )
54     {
55         Object JavaDoc val = value.getValue();
56         
57         if ( CompilerUtils.isErrorString( val ) )
58         {
59             // This means that there is already an error related to the type itself.
60
return null;
61         }
62         
63         if ( val instanceof PrimitiveType )
64         {
65             addError( value, "error.primitive-type-not-allowed" );
66             return null;
67         }
68         else if ( val instanceof VoidType )
69         {
70             addError( value, "error.void-type-not-allowed" );
71             return null;
72         }
73         
74         if ( val instanceof String JavaDoc )
75         {
76             assert CompilerUtils.isErrorString( val ) : val;
77             return null;
78         }
79         
80         assert val instanceof ReferenceType : val.getClass().getName();
81         ReferenceType type = ( ReferenceType ) val;
82         
83         if ( ! _allowArrayType && type instanceof ArrayType )
84         {
85             addError( value, "error.array-type-not-allowed" );
86             return null;
87         }
88         
89         if ( _requiredSuperclassName != null )
90         {
91             if ( ! CompilerUtils.isAssignableFrom( _requiredSuperclassName, type, getEnv() ) )
92             {
93                 addError( value, "error.does-not-extend-base", new Object JavaDoc[]{ _requiredSuperclassName } );
94                 return null;
95             }
96         }
97         
98         checkType( type, value );
99         return type;
100     }
101
102     /**
103      * Derived classes can plug in here to do further checks on the type.
104      */

105     protected void checkType( ReferenceType type, AnnotationValue member )
106     {
107     }
108 }
109
Popular Tags