1 16 package com.google.gwt.dev.cfg; 17 18 import com.google.gwt.core.ext.TreeLogger; 19 import com.google.gwt.core.ext.UnableToCompleteException; 20 import com.google.gwt.dev.jdt.RebindOracle; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 32 public class Compilations { 33 34 private final List list = new ArrayList (); 35 36 public void add(Compilation compilation) { 37 list.add(compilation); 38 } 39 40 44 public Compilation find(TreeLogger logger, RebindOracle rebindOracle, 45 String [] entryPts) throws UnableToCompleteException { 46 49 List candidates = new ArrayList (list); 52 53 for (int i = 0; !candidates.isEmpty() && i < entryPts.length; i++) { 57 String in = entryPts[i]; 58 String out = rebindOracle.rebind(logger, in); 59 removeMismatches(candidates, in, out); 60 } 61 62 for (Iterator iter = candidates.iterator(); iter.hasNext();) { 65 Compilation c = (Compilation) iter.next(); 66 String [] cachedIns = c.getRebindInputs(); 67 for (int i = 0; i < cachedIns.length; i++) { 68 String cachedIn = cachedIns[i]; 69 String cachedOut = c.getRebindOutput(cachedIn); 70 String out = rebindOracle.rebind(logger, cachedIn); 71 if (!cachedOut.equals(out)) { 72 iter.remove(); 75 break; 76 } 77 } 78 } 79 80 if (candidates.isEmpty()) { 81 return null; 84 } else if (candidates.size() == 1) { 85 return (Compilation) candidates.get(0); 88 } else { 89 String msg = "Cannot decided between multiple existing compilations; cannot continue"; 92 logger.log(TreeLogger.ERROR, msg, null); 93 throw new UnableToCompleteException(); 94 } 95 } 96 97 public Iterator iterator() { 98 return list.iterator(); 99 } 100 101 private void removeMismatches(List candidates, String in, String out) { 102 for (Iterator iter = candidates.iterator(); iter.hasNext();) { 103 Compilation c = (Compilation) iter.next(); 104 String cachedOut = c.getRebindOutput(in); 105 if (!out.equals(cachedOut)) { 106 iter.remove(); 107 } 108 } 109 } 110 } 111 | Popular Tags |