01: /*******************************************************************************
02:
03: * Copyright (c) 2005, 2007 BEA Systems, Inc.
04: * All rights reserved. This program and the accompanying materials
05: * are made available under the terms of the Eclipse Public License v1.0
06: * which accompanies this distribution, and is available at
07: * http://www.eclipse.org/legal/epl-v10.html
08: *
09: * Contributors:
10: * jgarms@bea.com - initial API and implementation
11: *
12: *******************************************************************************/package org.eclipse.jdt.apt.tests.annotations;
13:
14: import com.sun.mirror.apt.AnnotationProcessor;
15: import com.sun.mirror.apt.AnnotationProcessorEnvironment;
16: import com.sun.mirror.apt.Messager;
17:
18: public abstract class BaseProcessor implements AnnotationProcessor {
19:
20: public static final String SUCCESS = "succeeded";
21:
22: public static String getPropertyName(
23: Class<? extends AnnotationProcessor> processor) {
24: return processor.getName() + ".result";
25: }
26:
27: protected void reportSuccess(
28: Class<? extends AnnotationProcessor> processor) {
29: System.setProperty(getPropertyName(processor), SUCCESS);
30: }
31:
32: protected void reportError(
33: Class<? extends AnnotationProcessor> processor, String msg) {
34: System.setProperty(getPropertyName(processor), msg);
35: }
36:
37: protected final AnnotationProcessorEnvironment _env;
38:
39: public BaseProcessor(final AnnotationProcessorEnvironment env) {
40: _env = env;
41: }
42:
43: protected void assertEqual(final int expected, final int actual,
44: final String message) {
45: if (expected != actual) {
46: final Messager msgr = _env.getMessager();
47: msgr.printError(message + " expected: " + expected
48: + " actual: " + actual);
49: }
50: }
51:
52: protected void assertEqual(final Object expected,
53: final Object actual, final String message) {
54: if (expected == null) {
55: final Messager msgr = _env.getMessager();
56: msgr.printError(message + " actual: " + actual);
57: } else if (actual == null) {
58: final Messager msgr = _env.getMessager();
59: msgr.printError(message + "expected " + expected);
60: } else if (!expected.equals(actual)) {
61: final Messager msgr = _env.getMessager();
62: msgr.printError(message + " expected: " + expected
63: + " actual: " + actual);
64: }
65: }
66:
67: protected void assertEqual(final String expected,
68: final String actual, final String message) {
69: if (expected == null) {
70: final Messager msgr = _env.getMessager();
71: msgr.printError(message + " actual: " + actual);
72: } else if (actual == null) {
73: final Messager msgr = _env.getMessager();
74: msgr.printError(message + "expected " + expected);
75: } else if (!expected.equals(actual)) {
76: final Messager msgr = _env.getMessager();
77: msgr.printError(message + " expected: " + expected
78: + " actual: " + actual);
79: }
80: }
81:
82: protected void assertNonNull(final Object obj, final String message) {
83: if (obj == null) {
84: final Messager msgr = _env.getMessager();
85: msgr.printError(message);
86: }
87: }
88: }
|