1 16 package com.google.gwt.core.ext.typeinfo; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 24 public class JPackage { 25 26 private final String name; 27 28 private final Map types = new HashMap (); 29 30 JPackage(String name) { 31 this.name = name; 32 } 33 34 public JClassType findType(String typeName) { 35 String [] parts = typeName.split("\\."); 36 return findType(parts); 37 } 38 39 public JClassType findType(String [] typeName) { 40 return findTypeImpl(typeName, 0); 41 } 42 43 public String getName() { 44 return name; 45 } 46 47 public JClassType getType(String typeName) throws NotFoundException { 48 JClassType result = findType(typeName); 49 if (result == null) { 50 throw new NotFoundException(); 51 } 52 return result; 53 } 54 55 public JClassType[] getTypes() { 56 return (JClassType[]) types.values().toArray(TypeOracle.NO_JCLASSES); 57 } 58 59 public boolean isDefault() { 60 return "".equals(name); 61 } 62 63 public String toString() { 64 return "package " + name; 65 } 66 67 void addType(JClassType type) { 68 types.put(type.getSimpleSourceName(), type); 69 } 70 71 JClassType findTypeImpl(String [] typeName, int index) { 72 JClassType found = (JClassType) types.get(typeName[index]); 73 if (found == null) { 74 return null; 75 } else if (index < typeName.length - 1) { 76 return found.findNestedTypeImpl(typeName, index + 1); 77 } else { 78 return found; 79 } 80 } 81 82 void remove(JClassType type) { 83 Object removed = types.remove(type.getSimpleSourceName()); 84 } 86 } 87 | Popular Tags |