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.JpfLanguageConstants;
25: import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
26: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
27: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
28: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
29: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
30: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
31:
32: public class LocaleRulesGrammar extends ValidationRulesContainerGrammar
33: implements JpfLanguageConstants {
34: private static final String[][] REQUIRED_ATTRS = { {
35: APPLY_TO_UNHANDLED_LOCALES_ATTR, LANGUAGE_ATTR }, };
36:
37: private static final String[][] ATTR_DEPENDENCIES = {
38: { COUNTRY_ATTR, LANGUAGE_ATTR },
39: { VARIANT_ATTR, LANGUAGE_ATTR } };
40:
41: public LocaleRulesGrammar(CoreAnnotationProcessorEnv env,
42: Diagnostics diags, RuntimeVersionChecker rvc) {
43: super (env, diags, rvc);
44:
45: addMemberType(LANGUAGE_ATTR, new AnnotationMemberType(null,
46: this ));
47: addMemberType(COUNTRY_ATTR,
48: new AnnotationMemberType(null, this ));
49: addMemberType(VARIANT_ATTR,
50: new AnnotationMemberType(null, this ));
51: addMemberType(APPLY_TO_UNHANDLED_LOCALES_ATTR,
52: new ApplyToUnhandledLocalesType());
53: }
54:
55: public String[][] getRequiredAttrs() {
56: return REQUIRED_ATTRS;
57: }
58:
59: public String[][] getAttrDependencies() {
60: return ATTR_DEPENDENCIES;
61: }
62:
63: private class ApplyToUnhandledLocalesType extends
64: AnnotationMemberType {
65: public ApplyToUnhandledLocalesType() {
66: super (null, LocaleRulesGrammar.this );
67: }
68:
69: public Object onCheck(
70: AnnotationTypeElementDeclaration valueDecl,
71: AnnotationValue member,
72: AnnotationInstance[] parentAnnotations,
73: MemberDeclaration classMember, int annotationArrayIndex) {
74: AnnotationInstance parentAnnotation = parentAnnotations[parentAnnotations.length - 1];
75: String language = CompilerUtils.getString(parentAnnotation,
76: LANGUAGE_ATTR, true);
77:
78: if (((Boolean) member.getValue()).booleanValue()) {
79: if (language != null) {
80: addError(member,
81: "error.incompatible-locale-annotations",
82: LANGUAGE_ATTR,
83: APPLY_TO_UNHANDLED_LOCALES_ATTR);
84: }
85: } else {
86: if (language == null || language.length() == 0) {
87: addError(member,
88: "error.missing-locale-annotations",
89: LANGUAGE_ATTR,
90: APPLY_TO_UNHANDLED_LOCALES_ATTR);
91: }
92: }
93:
94: return null;
95: }
96: }
97: }
|