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.AnnotationGrammar;
24: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
25: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
26: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
27: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
28: import org.apache.beehive.netui.compiler.typesystem.type.ArrayType;
29: import org.apache.beehive.netui.compiler.typesystem.type.ReferenceType;
30: import org.apache.beehive.netui.compiler.typesystem.type.PrimitiveType;
31: import org.apache.beehive.netui.compiler.typesystem.type.VoidType;
32:
33: public class TypeNameType extends AnnotationMemberType {
34: private String _requiredSuperclassName;
35: private boolean _allowArrayType;
36:
37: public TypeNameType(String requiredSuperclassName,
38: boolean allowArrayType, String requiredRuntimeVersion,
39: AnnotationGrammar parentGrammar) {
40: super (requiredRuntimeVersion, parentGrammar);
41: _requiredSuperclassName = requiredSuperclassName;
42: _allowArrayType = allowArrayType;
43: }
44:
45: /**
46: * @return the fully-qualified type (ClassDeclaration)
47: */
48:
49: public Object onCheck(AnnotationTypeElementDeclaration valueDecl,
50: AnnotationValue value,
51: AnnotationInstance[] parentAnnotations,
52: MemberDeclaration classMember, int annotationArrayIndex) {
53: Object val = value.getValue();
54:
55: if (CompilerUtils.isErrorString(val)) {
56: // This means that there is already an error related to the type itself.
57: return null;
58: }
59:
60: if (val instanceof PrimitiveType) {
61: addError(value, "error.primitive-type-not-allowed");
62: return null;
63: } else if (val instanceof VoidType) {
64: addError(value, "error.void-type-not-allowed");
65: return null;
66: }
67:
68: assert val instanceof ReferenceType : val.getClass().getName();
69: ReferenceType type = (ReferenceType) val;
70:
71: if (!_allowArrayType && type instanceof ArrayType) {
72: addError(value, "error.array-type-not-allowed");
73: return null;
74: }
75:
76: if (_requiredSuperclassName != null) {
77: if (!CompilerUtils.isAssignableFrom(
78: _requiredSuperclassName, type, getEnv())) {
79: addError(value, "error.does-not-extend-base",
80: new Object[] { _requiredSuperclassName });
81: return null;
82: }
83: }
84:
85: checkType(type, value);
86: return type;
87: }
88:
89: /**
90: * Derived classes can plug in here to do further checks on the type.
91: */
92: protected void checkType(ReferenceType type, AnnotationValue member) {
93: }
94: }
|