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.CompilerUtils; 23 import org.apache.beehive.netui.compiler.FlowControllerInfo; 24 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 27 28 import java.util.Map ; 29 import java.util.List ; 30 import java.util.Iterator ; 31 32 33 public class MessageBundleGrammar 34 extends BaseFlowControllerGrammar 35 { 36 private static final String [][] REQUIRED_ATTRS = { { BUNDLE_PATH_ATTR } }; 37 38 39 public MessageBundleGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, 40 String requiredRuntimeVersion, RuntimeVersionChecker runtimeVersionChecker, 41 FlowControllerInfo fcInfo ) 42 { 43 super( env, diags, requiredRuntimeVersion, runtimeVersionChecker, fcInfo ); 44 45 addMemberType( BUNDLE_PATH_ATTR, 46 new UniqueValueType( MESSAGE_BUNDLES_ATTR, false, false, null, this ) ); 47 addMemberType( BUNDLE_NAME_ATTR, new UniqueValueType( MESSAGE_BUNDLES_ATTR, true, true, null, this ) ); 48 } 49 50 public String [][] getRequiredAttrs() 51 { 52 return REQUIRED_ATTRS; 53 } 54 55 protected Object onEndCheck( AnnotationInstance annotation, AnnotationInstance[] parentAnnotations, 56 MemberDeclaration classMember, Map checkResults ) 57 { 58 String bundlePath = CompilerUtils.getString( annotation, BUNDLE_PATH_ATTR, false ); 59 String bundleName = CompilerUtils.getString( annotation, BUNDLE_NAME_ATTR, false ); 60 61 if ( bundleName.length() == 0 ) 62 { 63 AnnotationInstance immediateParent = parentAnnotations[parentAnnotations.length - 1]; 64 List peerAnnotations = 65 CompilerUtils.getAnnotationArray( immediateParent, MESSAGE_BUNDLES_ATTR, false ); 66 67 for ( Iterator ii = peerAnnotations.iterator(); ii.hasNext(); ) 68 { 69 AnnotationInstance peerAnnotation = ( AnnotationInstance ) ii.next(); 70 if ( ! CompilerUtils.annotationsAreEqual( annotation, peerAnnotation, false, getEnv() ) 71 && CompilerUtils.getString( peerAnnotation, BUNDLE_NAME_ATTR, false ).length() == 0 ) 72 { 73 addError( annotation, "error.multiple-default-message-resources", BUNDLE_NAME_ATTR ); 74 } 75 } 76 } 77 78 getFlowControllerInfo().addMessageBundle( bundleName, bundlePath ); 79 80 return null; 81 } 82 } 83 | Popular Tags |