1 18 package org.apache.beehive.netui.compiler.grammar; 19 20 import org.apache.beehive.netui.compiler.RuntimeVersionChecker; 21 import org.apache.beehive.netui.compiler.Diagnostics; 22 import org.apache.beehive.netui.compiler.AnnotationMemberType; 23 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 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.AnnotationInstance; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 28 29 30 public class ValidateRangeGrammar 31 extends BaseValidationRuleGrammar 32 { 33 private static String [][] MUTUALLY_EXCLUSIVE_ATTRS = 34 { { MIN_INT_ATTR, MIN_FLOAT_ATTR }, { MAX_INT_ATTR, MAX_FLOAT_ATTR } }; 35 36 private static String [][] ATTR_DEPENDENCIES = 37 { 38 { MIN_INT_ATTR, MAX_INT_ATTR }, 39 { MIN_FLOAT_ATTR, MAX_FLOAT_ATTR }, 40 { MAX_INT_ATTR, MIN_INT_ATTR }, 41 { MAX_FLOAT_ATTR, MIN_FLOAT_ATTR } 42 }; 43 44 public ValidateRangeGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, 45 RuntimeVersionChecker runtimeVersionChecker ) 46 { 47 super( env, diags, runtimeVersionChecker ); 48 49 addMemberType( MIN_FLOAT_ATTR, new FloatType() ); 51 addMemberType( MAX_FLOAT_ATTR, new FloatType() ); 52 53 } 55 56 public String [][] getMutuallyExclusiveAttrs() 57 { 58 return MUTUALLY_EXCLUSIVE_ATTRS; 59 } 60 61 public String [][] getRequiredAttrs() 62 { 63 return null; 64 } 65 66 public String [][] getAttrDependencies() 67 { 68 return ATTR_DEPENDENCIES; 69 } 70 71 private class FloatType 72 extends AnnotationMemberType 73 { 74 public FloatType() 75 { 76 super( ValidateRangeGrammar.this.getRequiredRuntimeVersion(), ValidateRangeGrammar.this ); 77 } 78 79 80 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue member, 81 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 82 int annotationArrayIndex ) 83 { 84 double d = ( ( Double ) member.getValue() ).doubleValue(); 85 86 if ( d < -Float.MAX_VALUE ) addError( member, "error.min-float", new Double ( -Float.MAX_VALUE ) ); 87 else if ( d > Float.MAX_VALUE ) addError( member, "error.max-float", new Double ( Float.MAX_VALUE ) ); 88 89 return null; 90 } 91 } 92 } 93 | Popular Tags |