1 24 25 package org.aspectj.compiler.base.ast; 26 27 import java.util.*; 28 import org.aspectj.compiler.base.*; 29 30 public class SemanticMap extends CompilerObject { 31 protected final Map map = new HashMap(); 32 protected final Type type; 33 34 protected String kind; 35 36 public SemanticMap(Type type, String kind) { 37 super(type.getCompiler()); 38 this.type = type; 39 this.kind = kind; 40 } 41 42 public SemanticObject get(String id, ASTObject fromWhere, Exprs params, boolean showError) { 43 45 SemanticGroup semanticGroup = (SemanticGroup)map.get(id); 46 if (semanticGroup == null) { 47 if (showError) { 49 showNotFoundError(id, fromWhere); 50 } 51 return getNotFoundSemanticObject(); 52 } 53 return semanticGroup.resolve(fromWhere, params, showError); 54 } 55 56 public void addDeclared(SemanticObject objects) { 57 String id = objects.getId(); 58 SemanticGroup semanticGroup = (SemanticGroup)map.get(id); 60 if (semanticGroup == null) { 61 map.put(id, makeSemanticGroup(objects)); 62 } else { 63 semanticGroup.addDeclaredSO(objects); 64 } 65 } 67 68 public SemanticObject addIntroduced(SemanticObject objects) { 69 String id = objects.getId(); 70 SemanticGroup semanticGroup = (SemanticGroup)map.get(id); 72 if (semanticGroup == null) { 73 map.put(id, makeSemanticGroup(objects)); 74 return null; 75 } else { 76 return semanticGroup.addIntroducedSO(objects); 77 } 78 } 80 81 public boolean hasName(String id) { 82 85 return map.get(id) != null; 86 } 87 88 public void addInherited(SemanticMap other) { 89 for (Iterator i = other.map.values().iterator(); i.hasNext(); ) { 90 SemanticGroup superGroup = (SemanticGroup)i.next(); 91 String name = superGroup.getName(); 92 SemanticGroup myGroup = (SemanticGroup)map.get(name); 93 if (myGroup == null) { 94 myGroup = superGroup.makeInheritedCopy(this); 95 } else { 96 myGroup.inheritFrom(superGroup); 97 } 98 99 if (!myGroup.isEmpty()) map.put(name, myGroup); 100 } 101 } 102 103 public Collection getAllSemanticObjects() { 104 List ret = new LinkedList(); 105 for (Iterator i = map.values().iterator(); i.hasNext(); ) { 106 SemanticGroup group = (SemanticGroup)i.next(); 107 ret.addAll(group.members); 108 } 109 return ret; 110 } 111 112 public void ensureNoAbstracts() { 113 for (Iterator i = getAllSemanticObjects().iterator(); i.hasNext(); ) { 114 SemanticObject object = (SemanticObject)i.next(); 115 if (object.isAbstract()) { 116 if (object.getDeclaringType() == getType()) { 117 object.getCorrespondingDec().showError("abstract " + 118 getSemanticObjectTypeName() + 119 " not allowed in concrete type " + getType().toShortString()); 120 } else { 121 getType().getTypeDec().showError("concrete type " + 122 getType().toShortString() + " must implement " + 123 getSemanticObjectTypeName() + " " + object.toShortString()); 124 } 125 } 126 } 127 } 128 129 public SemanticObject findMatchingSemanticObject(SemanticObject matchSemanticObject) { 131 for (Iterator i = getAllSemanticObjects().iterator(); i.hasNext(); ) { 132 SemanticObject object = (SemanticObject)i.next(); 133 if (object.conflictsWith(matchSemanticObject)) return object; 135 } 136 return null; 137 } 138 139 140 protected SemanticObject getNotFoundSemanticObject() { return null; } 141 protected String getSemanticObjectTypeName() { return kind; } 142 143 public Type getType() { return type; } 144 145 protected SemanticGroup makeSemanticGroup(SemanticObject object) { 146 return new SemanticGroup(this, object); 147 } 148 149 protected void showNotFoundError(String id, ASTObject fromWhere) { 150 getCompiler().showError(fromWhere, "no " + getSemanticObjectTypeName() + " named " 152 + id + " defined in " + type.toShortString()); 153 } 154 } 155 | Popular Tags |