KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > grammar > ExceptionHandlerGrammar


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

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 JavaDoc 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