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.CompilerUtils; 23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 24 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration; 28 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration; 29 30 public class MemberMethodType 31 extends AnnotationMemberType 32 { 33 private String _requiredMethodAnnotation; 34 private String _errorCode; 35 36 public MemberMethodType( String requiredMethodAnnotation, String errorCode, String requiredRuntimeVersion, 37 AnnotationGrammar parentGrammar ) 38 { 39 super( requiredRuntimeVersion, parentGrammar ); 40 _requiredMethodAnnotation = requiredMethodAnnotation; 41 _errorCode = errorCode; 42 } 43 44 45 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value, 46 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 47 int annotationArrayIndex ) 48 { 49 TypeDeclaration outerType = CompilerUtils.getOuterClass( classMember ); 53 MethodDeclaration[] methods = CompilerUtils.getClassMethods( outerType, null ); 54 String methodName = ( String ) value.getValue(); 55 56 for ( int i = 0; i < methods.length; i++ ) 57 { 58 MethodDeclaration method = methods[i]; 59 60 if ( method.getSimpleName().equals( methodName ) ) 61 { 62 if ( _requiredMethodAnnotation == null 63 || CompilerUtils.getAnnotation( method, _requiredMethodAnnotation ) != null ) 64 { 65 checkMethod( method, value, parentAnnotations, classMember ); 66 return method; 67 } 68 } 69 } 70 71 addError( value, _errorCode, methodName ); 72 return null; 73 } 74 75 protected MethodDeclaration findMethod( String methodName, TypeDeclaration outerType ) 76 { 77 MethodDeclaration[] methods = CompilerUtils.getClassMethods( outerType, null ); 78 79 for ( int i = 0; i < methods.length; i++ ) 80 { 81 MethodDeclaration method = methods[i]; 82 83 if ( method.getSimpleName().equals( methodName ) ) 84 { 85 if ( _requiredMethodAnnotation == null 86 || CompilerUtils.getAnnotation( method, _requiredMethodAnnotation ) != null ) 87 { 88 return method; 89 } 90 } 91 } 92 93 return null; 94 } 95 96 99 protected void checkMethod( MethodDeclaration method, AnnotationValue member, AnnotationInstance[] parentAnnotations, 100 MemberDeclaration classMember ) 101 { 102 } 103 } 104 | Popular Tags |