1 18 package org.apache.beehive.netui.compiler; 19 20 import org.apache.beehive.netui.compiler.grammar.ValidatablePropertyGrammar; 21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 22 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 24 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.Modifier; 28 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 29 30 import java.util.Map ; 31 32 33 public class FormBeanChecker 34 extends BaseChecker 35 implements JpfLanguageConstants 36 { 37 public FormBeanChecker( AnnotationProcessorEnvironment env, Diagnostics diags ) 38 { 39 super( env, null, diags ); 40 } 41 42 public Map onCheck( ClassDeclaration jclass ) 43 throws FatalCompileTimeException 44 { 45 GetterValidatablePropertyGrammar validatablePropertyGrammar = new GetterValidatablePropertyGrammar(); 46 boolean isFormBeanClass = CompilerUtils.getAnnotation( jclass, FORM_BEAN_TAG_NAME ) != null; 47 48 MethodDeclaration[] methods = CompilerUtils.getClassMethods( jclass, null ); 53 54 for ( int i = 0; i < methods.length; i++ ) 55 { 56 MethodDeclaration method = methods[i]; 57 isFormBeanClass |= 58 checkValidationAnnotation( method, VALIDATABLE_PROPERTY_TAG_NAME, validatablePropertyGrammar ); 59 72 } 73 74 if ( isFormBeanClass || CompilerUtils.isAssignableFrom( STRUTS_FORM_CLASS_NAME, jclass, getEnv() ) ) 79 { 80 if ( jclass.getDeclaringType() != null && ! jclass.hasModifier( Modifier.STATIC ) ) 81 { 82 getDiagnostics().addError( jclass, "error.form-not-static" ); 83 } 84 85 if ( ! jclass.hasModifier( Modifier.PUBLIC ) ) 86 { 87 getDiagnostics().addError( jclass, "error.form-not-public" ); 88 } 89 90 if ( ! CompilerUtils.hasDefaultConstructor( jclass ) ) 91 { 92 getDiagnostics().addError( jclass, "error.form-no-default-constructor" ); 93 } 94 } 95 96 return null; 97 } 98 99 private boolean checkValidationAnnotation( MethodDeclaration method, String annotationTagName, 100 AnnotationGrammar grammar ) 101 throws FatalCompileTimeException 102 { 103 AnnotationInstance annotation = CompilerUtils.getAnnotation( method, annotationTagName ); 104 105 if ( annotation != null ) 106 { 107 if ( CompilerUtils.getBeanProperty( method ) == null ) 108 { 109 getDiagnostics().addError( annotation, "error.validation-field-on-non-getter" ); 110 } 111 112 grammar.check( annotation, null, method ); 113 114 return true; 115 } 116 117 return false; 118 } 119 120 private class GetterValidatablePropertyGrammar 121 extends ValidatablePropertyGrammar 122 { 123 public GetterValidatablePropertyGrammar() 124 { 125 super( FormBeanChecker.this.getEnv(), FormBeanChecker.this.getDiagnostics(), 126 FormBeanChecker.this.getRuntimeVersionChecker() ); 127 } 128 129 public String [][] getRequiredAttrs() 130 { 131 return null; } 133 134 protected void onCheckMember( AnnotationTypeElementDeclaration memberDecl, AnnotationValue member, 135 AnnotationInstance annotation, AnnotationInstance[] parentAnnotations, 136 MemberDeclaration classMember ) 137 { 138 if ( memberDecl.getSimpleName().equals( PROPERTY_NAME_ATTR ) ) 139 { 140 addError( member, "error.validatable-field-property-name-not-allowed", PROPERTY_NAME_ATTR ); 141 } 142 } 143 } 144 } 145 | Popular Tags |