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.Diagnostics; 23 import org.apache.beehive.netui.compiler.JpfLanguageConstants; 24 import org.apache.beehive.netui.compiler.RuntimeVersionChecker; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 28 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 29 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 30 31 32 public class LocaleRulesGrammar 33 extends ValidationRulesContainerGrammar 34 implements JpfLanguageConstants 35 { 36 private static final String [][] REQUIRED_ATTRS = 37 { 38 { APPLY_TO_UNHANDLED_LOCALES_ATTR, LANGUAGE_ATTR }, 39 }; 40 41 private static final String [][] ATTR_DEPENDENCIES = 42 { 43 { COUNTRY_ATTR, LANGUAGE_ATTR }, 44 { VARIANT_ATTR, LANGUAGE_ATTR } 45 }; 46 47 public LocaleRulesGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, 48 RuntimeVersionChecker rvc ) 49 { 50 super( env, diags, rvc ); 51 52 addMemberType( LANGUAGE_ATTR, new AnnotationMemberType( null, this ) ); 53 addMemberType( COUNTRY_ATTR, new AnnotationMemberType( null, this ) ); 54 addMemberType( VARIANT_ATTR, new AnnotationMemberType( null, this ) ); 55 addMemberType( APPLY_TO_UNHANDLED_LOCALES_ATTR, new ApplyToUnhandledLocalesType() ); 56 } 57 58 public String [][] getRequiredAttrs() 59 { 60 return REQUIRED_ATTRS; 61 } 62 63 public String [][] getAttrDependencies() 64 { 65 return ATTR_DEPENDENCIES; 66 } 67 68 private class ApplyToUnhandledLocalesType 69 extends AnnotationMemberType 70 { 71 public ApplyToUnhandledLocalesType() 72 { 73 super( null, LocaleRulesGrammar.this ); 74 } 75 76 77 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue member, 78 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 79 int annotationArrayIndex ) 80 { 81 AnnotationInstance parentAnnotation = parentAnnotations[ parentAnnotations.length - 1 ]; 82 String language = CompilerUtils.getString( parentAnnotation, LANGUAGE_ATTR, true ); 83 84 if ( ( ( Boolean ) member.getValue() ).booleanValue() ) 85 { 86 if ( language != null ) 87 { 88 addError( member, "error.incompatible-locale-annotations", LANGUAGE_ATTR, 89 APPLY_TO_UNHANDLED_LOCALES_ATTR ); 90 } 91 } 92 else 93 { 94 if ( language == null || language.length() == 0 ) 95 { 96 addError( member, "error.missing-locale-annotations", LANGUAGE_ATTR, 97 APPLY_TO_UNHANDLED_LOCALES_ATTR ); 98 } 99 } 100 101 return null; 102 } 103 } 104 } 105 | Popular Tags |