1 18 package org.apache.beehive.netui.compiler.grammar; 19 20 import org.apache.beehive.netui.compiler.AnnotationGrammar; 21 import org.apache.beehive.netui.compiler.CompilerUtils; 22 import org.apache.beehive.netui.compiler.Diagnostics; 23 import org.apache.beehive.netui.compiler.RuntimeVersionChecker; 24 import org.apache.beehive.netui.compiler.FatalCompileTimeException; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 27 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 28 29 import java.util.List ; 30 import java.util.Iterator ; 31 32 33 public class BaseValidationRuleGrammar 34 extends AnnotationGrammar 35 { 36 private static final String [][] MUTUALLY_EXCLUSIVE_ATTRS = 37 { 38 { MESSAGE_KEY_ATTR, MESSAGE_ATTR } 39 }; 40 41 private static final String [][] ATTR_DEPENDENCIES = 42 { 43 { BUNDLE_NAME_ATTR, MESSAGE_KEY_ATTR } 44 }; 45 46 47 public BaseValidationRuleGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, 48 RuntimeVersionChecker rvc ) 49 { 50 super( env, diags, VERSION_9_0_STRING, rvc ); 51 52 addMemberType( MESSAGE_KEY_ATTR, new MessageKeyType( null, this ) ); 53 addMemberArrayGrammar( MESSAGE_ARGS_ATTR, new ValidationMessageArgsGrammar( env, diags, rvc ) ); 54 addMemberType( BUNDLE_NAME_ATTR, new BundleNameType( null, this ) ); 55 } 56 57 58 public String [][] getMutuallyExclusiveAttrs() 59 { 60 return MUTUALLY_EXCLUSIVE_ATTRS; 61 } 62 63 64 public String [][] getAttrDependencies() 65 { 66 return ATTR_DEPENDENCIES; 67 } 68 69 70 protected boolean onBeginCheck( AnnotationInstance annotation, AnnotationInstance[] parentAnnotations, 71 MemberDeclaration classMember ) 72 throws FatalCompileTimeException 73 { 74 assert parentAnnotations.length > 0; 80 AnnotationInstance immediateParent = parentAnnotations[parentAnnotations.length - 1]; 81 82 if ( CompilerUtils.getString( immediateParent, DISPLAY_NAME_ATTR, true ) == null 83 && CompilerUtils.getString( immediateParent, DISPLAY_NAME_KEY_ATTR, true ) == null 84 && CompilerUtils.getString( annotation, MESSAGE_KEY_ATTR, true ) == null 85 && CompilerUtils.getString( annotation, MESSAGE_ATTR, true ) == null ) 86 { 87 boolean useDefaultDisplayName = true; 88 List messageArgs = 89 CompilerUtils.getAnnotationArray( annotation, MESSAGE_ARGS_ATTR, true ); 90 91 if ( messageArgs != null ) 92 { 93 boolean firstArg = true; 94 95 for ( Iterator ii = messageArgs.iterator(); ii.hasNext(); ) 96 { 97 AnnotationInstance messageArg = ( AnnotationInstance ) ii.next(); 98 Integer position = CompilerUtils.getInteger( messageArg, POSITION_ATTR, true ); 99 100 if ( ( position == null && firstArg ) || ( position != null && position.intValue() == 0 ) ) 101 { 102 useDefaultDisplayName = false; 103 break; 104 } 105 106 firstArg = false; 107 } 108 } 109 110 if ( useDefaultDisplayName ) 111 { 112 addWarning( annotation, "warning.using-default-display-name", 113 CompilerUtils.getDeclaration( immediateParent.getAnnotationType() ).getSimpleName() ); 114 } 115 } 116 117 return super.onBeginCheck( annotation, parentAnnotations, classMember ); 118 } 119 } 120 | Popular Tags |