1 18 19 package org.objectweb.jac.ide; 20 21 import java.util.Set ; 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 25 28 29 public class TypeRepository { 30 31 35 36 public Type resolveType(String name) { 37 return resolveType(name,""); 38 } 39 40 45 46 public Type resolveType(String name,String path) { 47 Iterator it = primitiveTypes.iterator(); 48 while(it.hasNext()) { 49 Type type = (Type)it.next(); 50 if (type.getName().equals(name)) { 51 return type; 52 } 53 } 54 55 it = extendedTypes.iterator(); 56 while(it.hasNext()) { 57 Type type = (Type)it.next(); 58 if (type.getName().equals(name)) { 59 return type; 60 } 61 } 62 63 it = externalClasses.iterator(); 64 while(it.hasNext()) { 65 Type type = (Type)it.next(); 66 if (path.equals("") && type.getName().equals(name)) { 67 return type; 68 } else if (path.equals(type.getPackagePath()) && 69 type.getName().equals(name)) { 70 return type; 71 } 72 } 73 return null; 74 } 75 76 HashSet primitiveTypes = new HashSet (); 77 78 82 public Set getPrimitiveTypes() { 83 return primitiveTypes; 84 } 85 86 91 public void addPrimitiveType(Type type) { 92 if (!containsType(type)) 93 primitiveTypes.add(type); 94 } 95 public void removePrimitievType(Type type) { 96 primitiveTypes.remove(type); 97 } 98 99 public Type getVoid() { 100 return resolveType("void"); 101 } 102 103 public Type getInt() { 104 return resolveType("int"); 105 } 106 107 public Type getLong() { 108 return resolveType("long"); 109 } 110 111 public Type getBoolean() { 112 return resolveType("boolean"); 113 } 114 115 public Type getDouble() { 116 return resolveType("double"); 117 } 118 119 public Type getFloat() { 120 return resolveType("float"); 121 } 122 123 HashSet externalClasses = new HashSet (); 124 125 129 public Set getExternalClasses() { 130 return externalClasses; 131 } 132 133 138 public void addExternalClass(Type type) { 139 if (!containsType(type)) 140 externalClasses.add(type); 141 } 142 143 148 public void removeExternalClass(Type type) { 149 externalClasses.remove(type); 150 } 151 152 HashSet extendedTypes = new HashSet (); 153 public Set getExtendedTypes() { 154 return extendedTypes; 155 } 156 public void addExtendedType(ExtendedType type) { 157 if (!containsType(type)) 158 extendedTypes.add(type); 159 } 160 public void removeExtendedType(ExtendedType type) { 161 extendedTypes.remove(type); 162 } 163 164 HashSet enumeratedTypes = new HashSet (); 165 public Set getEnumeratedTypes() { 166 return enumeratedTypes; 167 } 168 public void addEnumeratedType(EnumeratedType type) { 169 if (!containsType(type)) 170 enumeratedTypes.add(type); 171 } 172 public void removeEnumeratedType(EnumeratedType type) { 173 enumeratedTypes.remove(type); 174 } 175 176 179 public boolean containsType(Type type) { 180 return resolveType(type.getName(),type.getPackagePath())!=null; 181 } 182 } 183 | Popular Tags |