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.controls.runtime.generator.apt;
20:
21: import com.sun.mirror.apt.AnnotationProcessorEnvironment;
22: import com.sun.mirror.declaration.Declaration;
23: import com.sun.mirror.declaration.AnnotationValue;
24: import com.sun.mirror.declaration.AnnotationMirror;
25:
26: /**
27: * Wrapper class that allows the Control annotation processors to report diagnostics
28: * without calling directly against the {@link AnnotationProcessorEnvironment}. This
29: * class keeps track of whether errors have been reported during annotation processing.
30: */
31: public abstract class Diagnostics {
32: private AnnotationProcessorEnvironment _env;
33: private boolean _hasErrors = false;
34:
35: protected Diagnostics(AnnotationProcessorEnvironment env) {
36: _env = env;
37: }
38:
39: public void addError(Declaration decl, String messageKey,
40: Object... args) {
41: _env.getMessager().printError(decl.getPosition(),
42: getResourceString(messageKey, args));
43: _hasErrors = true;
44: }
45:
46: public void addError(AnnotationMirror ann, String messageKey,
47: Object... args) {
48: _env.getMessager().printError(ann.getPosition(),
49: getResourceString(messageKey, args));
50: _hasErrors = true;
51: }
52:
53: public void addErrorArrayArgs(AnnotationMirror ann,
54: String messageKey, Object[] args) {
55: _env.getMessager().printError(ann.getPosition(),
56: getResourceString(messageKey, args));
57: _hasErrors = true;
58: }
59:
60: public void addError(AnnotationValue annVal, String messageKey,
61: Object... args) {
62: _env.getMessager().printError(annVal.getPosition(),
63: getResourceString(messageKey, args));
64: _hasErrors = true;
65: }
66:
67: public void addWarning(Declaration decl, String messageKey,
68: Object... args) {
69: _env.getMessager().printWarning(decl.getPosition(),
70: getResourceString(messageKey, args));
71: }
72:
73: public void addWarning(AnnotationMirror ann, String messageKey,
74: Object... args) {
75: _env.getMessager().printWarning(ann.getPosition(),
76: getResourceString(messageKey, args));
77: }
78:
79: public void addWarning(AnnotationValue annVal, String messageKey,
80: Object... args) {
81: _env.getMessager().printWarning(annVal.getPosition(),
82: getResourceString(messageKey, args));
83: }
84:
85: public AnnotationProcessorEnvironment getAnnotationProcessorEnvironment() {
86: return _env;
87: }
88:
89: protected abstract String getResourceString(String key,
90: Object... args);
91:
92: public boolean hasErrors() {
93: return _hasErrors;
94: }
95:
96: protected void setHasErrors(boolean hadErrors) {
97: _hasErrors = hadErrors;
98: }
99: }
|