01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.compiler.grammar;
20:
21: import org.apache.beehive.netui.compiler.AnnotationMemberType;
22: import org.apache.beehive.netui.compiler.CompilerUtils;
23: import org.apache.beehive.netui.compiler.Diagnostics;
24: import org.apache.beehive.netui.compiler.FlowControllerInfo;
25: import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
26: import org.apache.beehive.netui.compiler.FatalCompileTimeException;
27: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
28: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
29: import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration;
30: import org.apache.beehive.netui.compiler.typesystem.declaration.Modifier;
31: import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
32: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
33:
34: public class ExceptionHandlerGrammar extends BaseFlowControllerGrammar {
35: public ExceptionHandlerGrammar(CoreAnnotationProcessorEnv env,
36: Diagnostics diags,
37: RuntimeVersionChecker runtimeVersionChecker,
38: FlowControllerInfo fcInfo) {
39: super (env, diags, null, runtimeVersionChecker, fcInfo);
40:
41: addMemberType(READONLY_ATTR, new AnnotationMemberType(
42: VERSION_8_SP2_STRING, this ));
43: addMemberArrayGrammar(FORWARDS_ATTR,
44: new ExceptionHandlerForwardGrammar(fcInfo));
45: }
46:
47: protected boolean onBeginCheck(AnnotationInstance annotation,
48: AnnotationInstance[] parentAnnotations,
49: MemberDeclaration classMember)
50: throws FatalCompileTimeException {
51: if (classMember.hasModifier(Modifier.ABSTRACT)) {
52: addWarning(annotation, "warning.annotated-abstract-method",
53: null);
54: return false;
55: }
56:
57: TypeDeclaration outerType = CompilerUtils
58: .getOuterClass(classMember);
59: String this MethodName = classMember.getSimpleName();
60: MethodDeclaration[] classMethods = CompilerUtils
61: .getClassMethods(outerType, EXCEPTION_HANDLER_TAG_NAME);
62:
63: for (int i = 0; i < classMethods.length; i++) {
64: MethodDeclaration method = classMethods[i];
65:
66: if (!method.equals(classMember)
67: && method.getSimpleName().equals(this MethodName)) {
68: addError(annotation,
69: "error.duplicate-exception-handler");
70: }
71: }
72:
73: return super .onBeginCheck(annotation, parentAnnotations,
74: classMember);
75: }
76:
77: private class ExceptionHandlerForwardGrammar extends ForwardGrammar {
78: public ExceptionHandlerForwardGrammar(FlowControllerInfo fcInfo) {
79: super (ExceptionHandlerGrammar.this .getEnv(),
80: ExceptionHandlerGrammar.this .getDiagnostics(),
81: ExceptionHandlerGrammar.this
82: .getRequiredRuntimeVersion(),
83: ExceptionHandlerGrammar.this
84: .getRuntimeVersionChecker(), fcInfo);
85: ExternalPathOrActionType baseType = new ExternalPathOrActionType(
86: false, null, this , fcInfo);
87: addMemberType(PATH_ATTR, new ForwardToExternalPathType(
88: baseType, null, ExceptionHandlerGrammar.this ));
89: }
90:
91: protected AnnotationMemberType getNameType() {
92: return new UniqueValueType(FORWARDS_ATTR, false, false,
93: null, this);
94: }
95: }
96:
97: }
|