01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.cfg;
17:
18: import com.google.gwt.core.ext.GeneratorContext;
19: import com.google.gwt.core.ext.TreeLogger;
20: import com.google.gwt.core.ext.UnableToCompleteException;
21:
22: /**
23: * Abstract base class for various kinds of deferred binding conditions.
24: */
25: public abstract class Condition {
26: public final boolean isTrue(TreeLogger logger,
27: GeneratorContext context, String testType)
28: throws UnableToCompleteException {
29:
30: boolean logDebug = logger.isLoggable(TreeLogger.DEBUG);
31:
32: if (logDebug) {
33: String startMsg = getEvalBeforeMessage(testType);
34: logger = logger.branch(TreeLogger.DEBUG, startMsg, null);
35: }
36:
37: boolean result = doEval(logger, context, testType);
38:
39: if (logDebug) {
40: String afterMsg = getEvalAfterMessage(testType, result);
41: logger.log(TreeLogger.DEBUG, afterMsg, null);
42: }
43:
44: return result;
45: }
46:
47: protected abstract boolean doEval(TreeLogger logger,
48: GeneratorContext context, String testType)
49: throws UnableToCompleteException;
50:
51: protected abstract String getEvalAfterMessage(String testType,
52: boolean result);
53:
54: protected abstract String getEvalBeforeMessage(String testType);
55: }
|