1 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 ; 31 import java.util.Iterator ; 32 33 34 public class MemberFieldType 35 extends AnnotationMemberType 36 { 37 private String _requiredSuperclassName; 38 39 40 public MemberFieldType( String requiredSuperclassName, String requiredRuntimeVersion, 41 AnnotationGrammar parentGrammar ) 42 { 43 super( requiredRuntimeVersion, parentGrammar ); 44 _requiredSuperclassName = requiredSuperclassName; 45 } 46 47 48 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue member, 49 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 50 int annotationArrayIndex ) 51 { 52 String fieldName = ( String ) member.getValue(); 53 Collection fields = 54 CompilerUtils.getClassFields( CompilerUtils.getOuterClass( classMember ) ); 55 56 for ( Iterator 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 []{ 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 |