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.AnnotationGrammar;
22: import org.apache.beehive.netui.compiler.CompilerUtils;
23: import org.apache.beehive.netui.compiler.Diagnostics;
24: import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
25: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
26: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
27: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
28:
29: import java.util.Map;
30:
31: public class ValidationMessageArgsGrammar extends AnnotationGrammar {
32: private static final String[][] MUTUALLY_EXCLUSIVE_ATTRS = { {
33: ARG_KEY_ATTR, ARG_ATTR } };
34:
35: private static final String[][] REQUIRED_ATTRS = { { ARG_KEY_ATTR,
36: ARG_ATTR }, };
37:
38: private static final String[][] ATTR_DEPENDENCIES = { {
39: BUNDLE_NAME_ATTR, ARG_KEY_ATTR } };
40:
41: public ValidationMessageArgsGrammar(CoreAnnotationProcessorEnv env,
42: Diagnostics diags, RuntimeVersionChecker rvc) {
43: super (env, diags, VERSION_9_0_STRING, rvc);
44:
45: // ARG_KEY_ATTR, ARG_ATTR do not need a custom type.
46: addMemberType(POSITION_ATTR, new UniqueValueType(
47: MESSAGE_ARGS_ATTR, false, true, null, this ));
48: addMemberType(BUNDLE_NAME_ATTR, new BundleNameType(null, this ));
49: }
50:
51: public String[][] getMutuallyExclusiveAttrs() {
52: return MUTUALLY_EXCLUSIVE_ATTRS;
53: }
54:
55: public String[][] getRequiredAttrs() {
56: return REQUIRED_ATTRS;
57: }
58:
59: public String[][] getAttrDependencies() {
60: return ATTR_DEPENDENCIES;
61: }
62:
63: protected Object onEndCheck(AnnotationInstance annotation,
64: AnnotationInstance[] parentAnnotations,
65: MemberDeclaration classMember, Map checkResults) {
66: Integer position = CompilerUtils.getInteger(annotation,
67: POSITION_ATTR, true);
68:
69: if (position == null) {
70: //
71: // Note, GenValidationModel.addMessageArgs() infers the position for
72: // a null position attribute from the postion of the arg in the array.
73: //
74: } else if (position.intValue() < 0 || position.intValue() > 3) {
75: addError(annotation,
76: "error.integer-attribute-not-in-range",
77: POSITION_ATTR, new Integer(0), new Integer(3));
78: }
79:
80: return null;
81: }
82: }
|