1 20 21 package net.innig.macker.structure; 22 23 import java.util.*; 24 import net.innig.collect.*; 25 26 public abstract class AbstractClassInfo 27 implements ClassInfo 28 { 29 public AbstractClassInfo(ClassManager classManager) 30 { this.classManager = classManager; } 31 32 public String getClassName() 33 { 34 String className = getFullName(); 35 return className.substring(className.lastIndexOf('.') + 1); 36 } 37 38 public String getPackageName() 39 { 40 String className = getFullName(); 41 int lastDotPos = className.lastIndexOf('.'); 42 return (lastDotPos > 0) ? className.substring(0, lastDotPos) : ""; 43 } 44 45 public Set getDirectSupertypes() 46 { 47 if(cachedAllDirectSuper == null) 48 { 49 Set newAllDirectSuper = new HashSet(getImplements()); 50 newAllDirectSuper.add(getExtends()); 51 cachedAllDirectSuper = newAllDirectSuper; } 53 return cachedAllDirectSuper; 54 } 55 56 public Set getSupertypes() 57 { 58 if(cachedAllSuper == null) 59 cachedAllSuper = Graphs.reachableNodes( 60 this, 61 new GraphWalker() 62 { 63 public Collection getEdgesFrom(Object node) 64 { return ((ClassInfo) node).getDirectSupertypes(); } 65 } ); 66 return cachedAllSuper; 67 } 68 69 public final ClassManager getClassManager() 70 { return classManager; } 71 72 public abstract boolean isComplete(); 73 public abstract String getFullName(); 74 public abstract boolean isInterface(); 75 public abstract boolean isAbstract(); 76 public abstract boolean isFinal(); 77 public abstract AccessModifier getAccessModifier(); 78 public abstract ClassInfo getExtends(); 79 public abstract Set getImplements(); 80 public abstract MultiMap getReferences(); 81 82 public int compareTo(Object that) 83 { return getFullName().compareTo(((ClassInfo) that).getFullName()); } 84 85 public final boolean equals(Object that) 86 { 87 if(this == that) 88 return true; 89 if(that == null) 90 return false; 91 if(!(that instanceof ClassInfo)) 92 return false; 93 return getFullName().equals(((ClassInfo) that).getFullName()); 94 } 95 96 public final int hashCode() 97 { return getFullName().hashCode(); } 98 99 public String toString() 100 { return getFullName(); } 101 102 private ClassManager classManager; 103 private Set cachedAllSuper, cachedAllDirectSuper; 104 } 105 106 | Popular Tags |