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.Diagnostics; 23 import org.apache.beehive.netui.compiler.FlowControllerInfo; 24 import org.apache.beehive.netui.compiler.RuntimeVersionChecker; 25 import org.apache.beehive.netui.compiler.FatalCompileTimeException; 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.MethodDeclaration; 29 import org.apache.beehive.netui.compiler.typesystem.declaration.Modifier; 30 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration; 31 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 32 33 34 public class ExceptionHandlerGrammar 35 extends BaseFlowControllerGrammar 36 { 37 public ExceptionHandlerGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, 38 RuntimeVersionChecker runtimeVersionChecker, FlowControllerInfo fcInfo ) 39 { 40 super( env, diags, null, runtimeVersionChecker, fcInfo ); 41 42 addMemberType( READONLY_ATTR, new AnnotationMemberType( VERSION_8_SP2_STRING, this ) ); 43 addMemberArrayGrammar( FORWARDS_ATTR, new ExceptionHandlerForwardGrammar( fcInfo ) ); 44 } 45 46 protected boolean onBeginCheck( AnnotationInstance annotation, AnnotationInstance[] parentAnnotations, 47 MemberDeclaration classMember ) 48 throws FatalCompileTimeException 49 { 50 if ( classMember.hasModifier( Modifier.ABSTRACT ) ) 51 { 52 addWarning( annotation, "warning.annotated-abstract-method", null ); 53 return false; 54 } 55 56 TypeDeclaration outerType = CompilerUtils.getOuterClass( classMember ); 57 String thisMethodName = classMember.getSimpleName(); 58 MethodDeclaration[] classMethods = CompilerUtils.getClassMethods( outerType, EXCEPTION_HANDLER_TAG_NAME ); 59 60 for ( int i = 0; i < classMethods.length; i++ ) 61 { 62 MethodDeclaration method = classMethods[i]; 63 64 if ( ! method.equals( classMember ) && method.getSimpleName().equals( thisMethodName ) ) 65 { 66 addError( annotation, "error.duplicate-exception-handler" ); 67 } 68 } 69 70 return super.onBeginCheck( annotation, parentAnnotations, classMember ); 71 } 72 73 private class ExceptionHandlerForwardGrammar 74 extends ForwardGrammar 75 { 76 public ExceptionHandlerForwardGrammar( FlowControllerInfo fcInfo ) 77 { 78 super( ExceptionHandlerGrammar.this.getEnv(), ExceptionHandlerGrammar.this.getDiagnostics(), 79 ExceptionHandlerGrammar.this.getRequiredRuntimeVersion(), 80 ExceptionHandlerGrammar.this.getRuntimeVersionChecker(), fcInfo ); 81 ExternalPathOrActionType baseType = new ExternalPathOrActionType( false, null, this, fcInfo ); 82 addMemberType( PATH_ATTR, new ForwardToExternalPathType( baseType, null, ExceptionHandlerGrammar.this ) ); 83 } 84 85 protected AnnotationMemberType getNameType() 86 { 87 return new UniqueValueType( FORWARDS_ATTR, false, false, null, this ); 88 } 89 } 90 91 } 92 | Popular Tags |