1 18 package org.apache.beehive.netui.compiler.grammar; 19 20 import org.apache.beehive.netui.compiler.CompilerUtils; 21 import org.apache.beehive.netui.compiler.FlowControllerInfo; 22 import org.apache.beehive.netui.compiler.AnnotationGrammar; 23 import org.apache.beehive.netui.compiler.MergedControllerAnnotation; 24 import org.apache.beehive.netui.compiler.FatalCompileTimeException; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 27 import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration; 28 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration; 29 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration; 30 import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration; 31 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration; 32 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 33 import org.apache.beehive.netui.compiler.typesystem.type.ClassType; 34 35 import java.util.Collection ; 36 import java.util.Iterator ; 37 38 public class WebappPathOrActionType 39 extends WebappPathType 40 { 41 public WebappPathOrActionType( boolean pathMustBeRelative, String requiredRuntimeVersion, 42 AnnotationGrammar parentGrammar, FlowControllerInfo fcInfo ) 43 { 44 super( pathMustBeRelative, requiredRuntimeVersion, parentGrammar, fcInfo ); 45 } 46 47 48 public Object onCheck( AnnotationTypeElementDeclaration valueDecl, AnnotationValue value, 49 AnnotationInstance[] parentAnnotations, MemberDeclaration classMember, 50 int annotationArrayIndex ) 51 throws FatalCompileTimeException 52 { 53 String stringValue = ( String ) value.getValue(); 54 checkAction( stringValue, value, classMember ); 55 return super.onCheck( valueDecl, value, parentAnnotations, classMember, annotationArrayIndex ); 56 } 57 58 protected void checkAction( String stringValue, AnnotationValue annValue, MemberDeclaration classMember ) 59 { 60 if ( stringValue.endsWith( ACTION_EXTENSION_DOT ) && stringValue.indexOf( '/' ) == -1 ) 61 { 62 TypeDeclaration outerType = CompilerUtils.getOuterClass( classMember ); 63 64 if ( outerType != null ) { 66 int extensionPos = stringValue.lastIndexOf( ACTION_EXTENSION_DOT ); 67 String actionMethodName = stringValue.substring( 0, extensionPos ); 68 FlowControllerInfo fcInfo = getFlowControllerInfo(); 69 boolean foundIt = actionExists( actionMethodName, outerType, null, getEnv(), fcInfo, false ); 70 71 if ( ! foundIt && actionMethodName.length() > 0 ) 72 { 73 int dot = actionMethodName.indexOf( '.' ); 77 78 if ( dot != -1 && dot < actionMethodName.length() - 1 ) 79 { 80 String sharedFlowName = actionMethodName.substring( 0, dot ); 81 TypeDeclaration sfTypeDecl = ( TypeDeclaration ) getFlowControllerInfo().getSharedFlowTypes().get( sharedFlowName ); 82 83 if ( sfTypeDecl != null ) 84 { 85 actionMethodName = actionMethodName.substring( dot + 1 ); 86 foundIt = actionExists( actionMethodName, sfTypeDecl, null, getEnv(), fcInfo, false ); 87 } 88 } 89 } 90 91 if ( ! foundIt && 96 ! CompilerUtils.isAssignableFrom( SHARED_FLOW_BASE_CLASS, 97 CompilerUtils.getOutermostClass( classMember ), getEnv() ) ) 98 { 99 TypeDeclaration globalAppDecl = getEnv().getTypeDeclaration( GLOBALAPP_FULL_CLASSNAME ); 100 if ( globalAppDecl != null ) 101 { 102 foundIt = actionExists( actionMethodName, globalAppDecl, null, getEnv(), fcInfo, false ); 103 } 104 } 105 106 if ( ! foundIt ) 107 { 108 if ( doFatalError() ) 109 { 110 addError( annValue, "error.action-not-found", actionMethodName ); 111 } 112 else 113 { 114 addWarning( annValue, "warning.action-not-found", actionMethodName ); 115 } 116 } 117 } 118 } 119 } 120 121 public static boolean actionExists( String actionName, TypeDeclaration type, AnnotationInstance annotationToIgnore, 122 AnnotationProcessorEnvironment env, FlowControllerInfo fcInfo, 123 boolean checkInheritedActions ) 124 { 125 if ( ! ( type instanceof ClassDeclaration ) ) 126 { 127 return false; 128 } 129 130 ClassDeclaration classDecl = ( ClassDeclaration ) type; 131 132 do 133 { 134 MethodDeclaration[] methods = classDecl.getMethods(); 138 139 for ( int i = 0; i < methods.length; i++ ) 140 { 141 MethodDeclaration method = methods[i]; 142 if ( method.getSimpleName().equals( actionName ) 143 && CompilerUtils.getAnnotation( method, ACTION_TAG_NAME ) != null ) 144 { 145 return true; 146 } 147 } 148 149 ClassType superType = classDecl.getSuperclass(); 150 classDecl = superType != null ? superType.getClassTypeDeclaration() : null; 151 } while ( classDecl != null ); 152 153 MergedControllerAnnotation mca = fcInfo.getMergedControllerAnnotation(); 157 Collection simpleActionAnnotations = 158 checkInheritedActions 159 ? mca.getSimpleActions() 160 : CompilerUtils.getAnnotationArrayValue( type, CONTROLLER_TAG_NAME, SIMPLE_ACTIONS_ATTR, true ); 161 162 if ( simpleActionAnnotations != null ) 163 { 164 for ( Iterator ii = simpleActionAnnotations.iterator(); ii.hasNext(); ) 165 { 166 AnnotationInstance ann = ( AnnotationInstance ) ii.next(); 167 String name = CompilerUtils.getString( ann, NAME_ATTR, false ); 168 169 if ( actionName.equals( name ) 170 && ! CompilerUtils.annotationsAreEqual( ann, annotationToIgnore, false, env ) ) 171 { 172 return true; 173 } 174 } 175 } 176 177 return false; 178 } 179 } 180 | Popular Tags |