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.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 _requiredSuperclassName; 36 private boolean _allowArrayType; 37 38 39 public TypeNameType( String requiredSuperclassName, boolean allowArrayType, String requiredRuntimeVersion, 40 AnnotationGrammar parentGrammar ) 41 { 42 super( requiredRuntimeVersion, parentGrammar ); 43 _requiredSuperclassName = requiredSuperclassName; 44 _allowArrayType = allowArrayType; 45 } 46 47 50 51 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value, 52 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 53 int annotationArrayIndex ) 54 { 55 Object val = value.getValue(); 56 57 if ( CompilerUtils.isErrorString( val ) ) 58 { 59 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 ) 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 []{ _requiredSuperclassName } ); 94 return null; 95 } 96 } 97 98 checkType( type, value ); 99 return type; 100 } 101 102 105 protected void checkType( ReferenceType type, AnnotationValue member ) 106 { 107 } 108 } 109 | Popular Tags |