KickJava   Java API By Example, From Geeks To Geeks.

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


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.FieldDeclaration;
27 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
28 import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance;
29
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33
34 public class MemberFieldType
35         extends AnnotationMemberType
36 {
37     private String JavaDoc _requiredSuperclassName;
38
39
40     public MemberFieldType( String JavaDoc requiredSuperclassName, String JavaDoc requiredRuntimeVersion,
41                             AnnotationGrammar parentGrammar )
42     {
43         super( requiredRuntimeVersion, parentGrammar );
44         _requiredSuperclassName = requiredSuperclassName;
45     }
46
47     
48     public Object JavaDoc onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue member,
49                            AnnotationInstance[] parentAnnotations, MemberDeclaration classMember,
50                            int annotationArrayIndex )
51     {
52         String JavaDoc fieldName = ( String JavaDoc ) member.getValue();
53         Collection JavaDoc fields =
54                 CompilerUtils.getClassFields( CompilerUtils.getOuterClass( classMember ) );
55         
56         for ( Iterator JavaDoc ii = fields.iterator(); ii.hasNext(); )
57         {
58             FieldDeclaration field = ( FieldDeclaration ) ii.next();
59             if ( field.getSimpleName().equals( fieldName ) )
60             {
61                 TypeInstance fieldType = CompilerUtils.getGenericBoundsType( field.getType() );
62                 
63                 if ( _requiredSuperclassName != null
64                      && ! CompilerUtils.isAssignableFrom( _requiredSuperclassName, fieldType, getEnv() ) )
65                 {
66                     addError( member, "error.wrong-field-type", new Object JavaDoc[]{ fieldName, _requiredSuperclassName } );
67                     return null;
68                 }
69                 
70                 return field;
71             }
72         }
73         
74         addError( member, "error.unresolved-field", fieldName );
75         return null;
76     }
77 }
78
Popular Tags