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.Diagnostics;
23: import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
24: import org.apache.beehive.netui.compiler.CompilerUtils;
25: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
26: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
27: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
28: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
29: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
30: import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
31: import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance;
32:
33: public class ActionOutputGrammar extends AnnotationGrammar {
34: private static final String[][] REQUIRED_ATTRS = { { NAME_ATTR },
35: { TYPE_ATTR } };
36:
37: public ActionOutputGrammar(CoreAnnotationProcessorEnv env,
38: Diagnostics diags, RuntimeVersionChecker rvc) {
39: super (env, diags, null, rvc);
40:
41: addMemberType(NAME_ATTR, new UniqueValueType(
42: ACTION_OUTPUTS_ATTR, false, false, null, this ));
43: addMemberType(TYPE_ATTR, new TypeNameType(null, true, null,
44: this ));
45: }
46:
47: protected void onCheckMember(
48: AnnotationTypeElementDeclaration memberDecl,
49: AnnotationValue member, AnnotationInstance annotation,
50: AnnotationInstance[] parentAnnotations,
51: MemberDeclaration classMember) {
52: if (memberDecl.getSimpleName().equals(TYPE_HINT_ATTR)) {
53: // Strip off any template args, and compare the typeHint to the actual type.
54: String typeHintStr = member.getValue().toString();
55: int angleBracket = typeHintStr.indexOf('<');
56: String strippedTypeHintStr = angleBracket != -1 ? typeHintStr
57: .substring(0, angleBracket)
58: : typeHintStr;
59: TypeDeclaration typeHint = getEnv().getTypeDeclaration(
60: strippedTypeHintStr);
61:
62: // Add a warning if the typeHint type can't be resolved.
63: if (typeHint == null) {
64: addWarning(member, "warning.type-hint-unresolvable",
65: TYPE_HINT_ATTR, typeHintStr);
66: } else {
67: // Add a warning if the typeHint type can't be assigned to the actual type.
68: TypeInstance actualType = CompilerUtils
69: .getTypeInstance(annotation, TYPE_ATTR, true);
70: if (!CompilerUtils.isAssignableFrom(actualType,
71: typeHint)) {
72: addWarning(member, "warning.type-hint-mismatch",
73: new Object[] { TYPE_HINT_ATTR, typeHintStr,
74: TYPE_ATTR, actualType.toString() });
75: }
76: }
77: }
78: }
79:
80: public String[][] getRequiredAttrs() {
81: return REQUIRED_ATTRS;
82: }
83: }
|