1 16 package com.google.gwt.dev.jdt; 17 18 import com.google.gwt.core.ext.TreeLogger; 19 import com.google.gwt.core.ext.UnableToCompleteException; 20 import com.google.gwt.core.ext.typeinfo.CompilationUnitProvider; 21 import com.google.gwt.core.ext.typeinfo.JClassType; 22 import com.google.gwt.core.ext.typeinfo.TypeOracle; 23 import com.google.gwt.dev.util.Util; 24 25 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; 26 27 import java.util.HashMap ; 28 import java.util.HashSet ; 29 import java.util.Map ; 30 import java.util.Set ; 31 32 38 public class StandardSourceOracle implements SourceOracle { 39 40 private final Map cupsByTypeName = new HashMap (); 41 42 private final Set knownPackages = new HashSet (); 43 44 private final TypeOracle typeOracle; 45 46 53 public StandardSourceOracle(TypeOracle typeOracle) { 54 this.typeOracle = typeOracle; 55 } 56 57 63 public final CompilationUnitProvider findCompilationUnit(TreeLogger logger, 64 String typeName) throws UnableToCompleteException { 65 66 CompilationUnitProvider cup = (CompilationUnitProvider) cupsByTypeName.get(typeName); 69 70 if (cup != null) { 71 return cup; 74 } 75 76 JClassType type = typeOracle.findType(typeName); 79 if (type != null) { 80 cup = type.getCompilationUnit(); 83 assert (cup != null); 84 } 85 86 if (cup != null) { 90 try { 91 CompilationUnitProvider specialCup = doFilterCompilationUnit(logger, 92 typeName, cup); 93 94 if (specialCup != null) { 95 cup = specialCup; 101 } 102 } catch (UnableToCompleteException e) { 103 String location = cup.getLocation(); 104 char[] source = cup.getSource(); 105 Util.maybeDumpSource(logger, location, source, typeName); 106 throw e; 107 } 108 } 109 110 if (cup == null) { 111 return null; 115 } 116 117 cupsByTypeName.put(typeName, cup); 120 return cup; 121 } 122 123 public TypeOracle getTypeOracle() { 124 return typeOracle; 125 } 126 127 130 public final boolean isPackage(String possiblePackageName) { 131 if (knownPackages.contains(possiblePackageName)) { 132 return true; 135 } 136 137 if (typeOracle.findPackage(possiblePackageName) != null) { 138 rememberPackage(possiblePackageName); 141 return true; 142 } else { 143 return false; 146 } 147 } 148 149 162 protected CompilationUnitProvider doFilterCompilationUnit(TreeLogger logger, 163 String typeName, CompilationUnitProvider existing) 164 throws UnableToCompleteException { 165 return null; 166 } 167 168 179 protected String [] doFindAdditionalTypesUsingMagic(TreeLogger logger, 180 CompilationUnitDeclaration unit) throws UnableToCompleteException { 181 return null; 182 } 183 184 void invalidateCups(Set typeNames) { 185 cupsByTypeName.keySet().removeAll(typeNames); 186 } 187 188 191 private void rememberPackage(String packageName) { 192 int i = packageName.lastIndexOf('.'); 193 if (i != -1) { 194 rememberPackage(packageName.substring(0, i)); 197 } 198 knownPackages.add(packageName); 199 } 200 } 201 | Popular Tags |