001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.dev.cfg;
017:
018: import com.google.gwt.core.ext.UnableToCompleteException;
019: import com.google.gwt.dev.util.Util;
020:
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: /**
025: * Represents a single completed compilation.
026: *
027: * @see Compilations
028: */
029: public class Compilation {
030:
031: private Map rebindDecisions = new HashMap();
032:
033: private Map sourceHashByGeneratedTypeName = new HashMap();
034:
035: private String strongName;
036:
037: public Compilation() {
038: }
039:
040: public String[] getGeneratedTypeNames() {
041: return Util.toStringArray(sourceHashByGeneratedTypeName
042: .keySet());
043: }
044:
045: public String[] getRebindInputs() {
046: return Util.toStringArray(rebindDecisions.keySet());
047: }
048:
049: /**
050: * @return <code>null</code> if there is no answer for this cached
051: * compilation
052: */
053: public String getRebindOutput(String inputTypeName) {
054: String out = (String) rebindDecisions.get(inputTypeName);
055: return out;
056: }
057:
058: public String getStrongName() {
059: return strongName;
060: }
061:
062: public String getTypeHash(String generatedTypeName)
063: throws UnableToCompleteException {
064: String hash = (String) sourceHashByGeneratedTypeName
065: .get(generatedTypeName);
066: if (hash != null) {
067: return hash;
068: } else {
069: throw new UnableToCompleteException();
070: }
071: }
072:
073: public boolean recordDecision(String inputTypeName,
074: String outputTypeName) {
075: // see if we've already recorded this one
076: String recodedOutputName = (String) rebindDecisions
077: .get(inputTypeName);
078: if (recodedOutputName != null) {
079: // Error to try to change the existing mapping
080: if (!recodedOutputName.equals(outputTypeName)) {
081: String msg = "Decision '" + recodedOutputName
082: + "' already recorded for '" + inputTypeName
083: + "'";
084: throw new IllegalStateException(msg);
085: }
086: // already recorded this one
087: return false;
088: }
089: rebindDecisions.put(inputTypeName, outputTypeName);
090: // this was a new entry
091: return true;
092: }
093:
094: public void recordGeneratedTypeHash(String generatedTypeName,
095: String sourceHash) {
096: sourceHashByGeneratedTypeName
097: .put(generatedTypeName, sourceHash);
098: }
099:
100: public void setStrongName(String strongName) {
101: this.strongName = strongName;
102: }
103: }
|