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.AnnotationGrammar; 22 import org.apache.beehive.netui.compiler.CompilerUtils; 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.ClassDeclaration; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 28 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration; 29 30 31 public class BundleNameType 32 extends AnnotationMemberType 33 { 34 public BundleNameType( String requiredRuntimeVersion, AnnotationGrammar parentGrammar ) 35 { 36 super( requiredRuntimeVersion, parentGrammar ); 37 } 38 39 40 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value, 41 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 42 int annotationArrayIndex ) 43 { 44 String bundle = ( String ) value.getValue(); 48 49 if ( bundle != null && !bundlesSupported( parentAnnotations, classMember ) ) 50 { 51 AnnotationInstance annotation = parentAnnotations[ parentAnnotations.length - 1 ]; 52 addError( value, "error.validation-bundle-support", BUNDLE_NAME_ATTR, annotation ); 53 } 54 55 return null; 56 } 57 58 protected static boolean bundlesSupported( AnnotationInstance[] parentAnnotations, MemberDeclaration classMember ) 59 { 60 AnnotationInstance ann = parentAnnotations[0]; 69 String validatorVersion = null; 70 71 if ( CompilerUtils.isJpfAnnotation( ann, CONTROLLER_TAG_NAME ) ) 72 { 73 validatorVersion = CompilerUtils.getEnumFieldName( ann, VALIDATOR_VERSION_ATTR, true ); 74 } 75 else 76 { 77 TypeDeclaration outerType = null; 78 79 if ( CompilerUtils.isJpfAnnotation( ann, ACTION_TAG_NAME ) ) 80 { 81 outerType = CompilerUtils.getOuterClass( classMember ); 82 } 83 else if ( CompilerUtils.isJpfAnnotation( ann, VALIDATABLE_PROPERTY_TAG_NAME ) ) 84 { 85 outerType = CompilerUtils.getOutermostClass( classMember ); 86 } 87 else 88 { 89 assert false; 91 } 92 93 if ( outerType instanceof ClassDeclaration ) 94 { 95 ann = CompilerUtils.getAnnotation( outerType, CONTROLLER_TAG_NAME ); 96 97 if ( ann != null ) 98 { 99 validatorVersion = CompilerUtils.getEnumFieldName( ann, VALIDATOR_VERSION_ATTR, true ); 100 } 101 } 102 } 103 104 if ( validatorVersion == null || validatorVersion.equals( VALIDATOR_VERSION_ONE_ZERO_STR ) ) 108 { 109 return false; 110 } 111 112 return true; 113 } 114 } 115 | Popular Tags |