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.Diagnostics; 22 import org.apache.beehive.netui.compiler.RuntimeVersionChecker; 23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 24 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration; 28 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 29 import org.apache.beehive.netui.compiler.typesystem.type.PrimitiveType; 30 import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance; 31 32 33 public class ValidateTypeGrammar 34 extends BaseValidationRuleGrammar 35 { 36 public ValidateTypeGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, 37 RuntimeVersionChecker runtimeVersionChecker ) 38 { 39 super( env, diags, runtimeVersionChecker ); 40 41 addMemberType( TYPE_ATTR, new PrimitiveTypeType() ); 42 } 43 44 private class PrimitiveTypeType 45 extends AnnotationMemberType 46 { 47 public PrimitiveTypeType() 48 { 49 super( ValidateTypeGrammar.this.getRequiredRuntimeVersion(), ValidateTypeGrammar.this ); 50 } 51 52 53 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value, 54 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 55 int annotationArrayIndex ) 56 { 57 Object val = value.getValue(); 58 59 if ( ! ( val instanceof PrimitiveType ) ) 63 { 64 addError( value, "error.must-be-primitive-type" ); 65 } 66 else 67 { 68 PrimitiveType.Kind kind = ( ( PrimitiveType ) val ).getKind(); 69 70 if ( kind.equals( PrimitiveType.Kind.BOOLEAN ) ) 71 { 72 addError( value, "error.invalid-type" ); 73 } 74 else if ( classMember instanceof MethodDeclaration ) 75 { 76 TypeInstance returnType = ( ( MethodDeclaration ) classMember ).getReturnType(); 81 82 if ( returnType instanceof PrimitiveType ) 83 { 84 if ( ( ( PrimitiveType ) returnType ).getKind().equals( kind ) ) 85 { 86 addWarning( value, "warning.validate-type-on-same-type", 87 ANNOTATION_INTERFACE_PREFIX + VALIDATE_TYPE_TAG_NAME, 88 kind.toString().toLowerCase() ); 89 } 90 } 91 } 92 } 93 94 return null; 95 } 96 } 97 } 98 | Popular Tags |