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.AnnotationGrammar; 23 import org.apache.beehive.netui.compiler.FatalCompileTimeException; 24 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 28 29 import java.util.Map ; 30 import java.util.HashMap ; 31 32 33 36 public class EnumType 37 extends AnnotationMemberType 38 { 39 40 private Map _enumRequiredRuntimeVersions = null; 41 42 43 private Map _deprecatedValues; 44 45 46 public EnumType( String [][] enumValues, String [][] deprecatedValues, String requiredRuntimeVersion, 47 AnnotationGrammar parentGrammar ) 48 { 49 super( requiredRuntimeVersion, parentGrammar ); 50 51 if ( deprecatedValues != null ) 52 { 53 _deprecatedValues = new HashMap (); 54 55 for ( int i = 0; i < deprecatedValues.length; ++i ) 56 { 57 String [] valueAndDiagnostic = deprecatedValues[i]; 58 assert valueAndDiagnostic.length == 2; 59 _deprecatedValues.put( valueAndDiagnostic[0], valueAndDiagnostic[1] ); 60 } 61 } 62 63 if ( enumValues != null ) 64 { 65 _enumRequiredRuntimeVersions = new HashMap (); 66 67 for ( int i = 0; i < enumValues.length; i++ ) 68 { 69 String [] valueAndRequiredRuntimeVersion = enumValues[i]; 70 assert valueAndRequiredRuntimeVersion.length == 2; 71 String enumValue = valueAndRequiredRuntimeVersion[0]; 72 String enumValRequiredRuntimeVersion = valueAndRequiredRuntimeVersion[1]; 73 74 if ( enumValRequiredRuntimeVersion != null ) 75 { 76 _enumRequiredRuntimeVersions.put( enumValue, enumValRequiredRuntimeVersion ); 77 } 78 } 79 } 80 } 81 82 83 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue member, 84 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 85 int annotationArrayIndex ) 86 throws FatalCompileTimeException 87 { 88 String val = CompilerUtils.getEnumFieldName( member ); 92 String errorKey = _deprecatedValues != null ? ( String ) _deprecatedValues.get( val ) : null; 93 94 if ( errorKey != null ) 95 { 96 addWarning( member, errorKey, val ); 97 } 98 99 String ver = _enumRequiredRuntimeVersions != null ? ( String ) _enumRequiredRuntimeVersions.get( val ) : null; 103 104 if ( ver != null ) 105 { 106 getParentGrammar().getRuntimeVersionChecker().checkRuntimeVersion( 107 ver, member, getParentGrammar().getDiagnostics(), "error.required-runtime-version-enumval", 108 new Object []{ val, PAGEFLOW_RUNTIME_JAR } ); 109 } 110 111 return super.onCheck( valueDecl, member, parentAnnotations, classMember, annotationArrayIndex ); 112 } 113 114 } 115 | Popular Tags |