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.AnnotationMemberType; 22 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 24 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 26 27 public class JavaIdentifierType 28 extends AnnotationMemberType 29 { 30 private char[] _validChars; 31 32 public JavaIdentifierType( String requiredRuntimeVersion, AnnotationGrammar parentGrammar, char[] validChars ) 33 { 34 super( requiredRuntimeVersion, parentGrammar ); 35 _validChars = validChars; 36 } 37 38 39 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value, 40 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 41 int annotationArrayIndex ) 42 { 43 String val = ( String ) value.getValue(); 44 45 if ( val.length() > 0 ) 46 { 47 char firstChar = val.charAt( 0 ); 48 49 if ( ! Character.isJavaIdentifierStart( firstChar ) ) 50 { 51 Object [] args = new Object []{ new Character ( firstChar ) }; 52 addError( value, "error.invalid-java-identifier-start", args ); 53 } 54 55 for ( int i = 1; i < val.length(); i++ ) 56 { 57 char c = val.charAt( i ); 58 59 if ( ! Character.isJavaIdentifierPart( val.charAt( i ) ) && ! isValid( c ) ) 60 { 61 Object [] args = new Object []{ new Character ( c ) }; 62 addError( value, "error.invalid-java-identifier-part", args ); 63 } 64 } 65 } 66 67 return null; 68 } 69 70 private boolean isValid( char c ) 71 { 72 if ( _validChars != null ) 73 { 74 for ( int i = 0; i < _validChars.length; i++ ) 75 { 76 if ( c == _validChars[i] ) return true; 77 } 78 } 79 80 return false; 81 } 82 } 83 | Popular Tags |