| 1 2 25 26 package org.aspectj.asm.associations; 27 28 import java.util.*; 29 import org.aspectj.compiler.base.*; 30 import org.aspectj.compiler.base.ast.*; 31 import org.aspectj.compiler.base.cst.*; 32 import org.aspectj.compiler.crosscuts.*; 33 import org.aspectj.compiler.crosscuts.ast.*; 34 import org.aspectj.asm.*; 35 import org.aspectj.asm.internal.*; 36 37 40 public class Inheritance implements Association { 41 public static final String NAME = "Inheritance"; 42 public static final Relation INHERITS_RELATION = new Relation("inherits", "is inherited by", NAME, true, true); 43 public static final Relation IMPLEMENTS_RELATION = new Relation("implements", "is implemented by", NAME, true, true); 44 public static final Relation INHERITS_MEMBERS_RELATION = new Relation("inherits members", NAME, false); 45 private List relations = new ArrayList(); 46 47 public Inheritance() { 48 relations.add(INHERITS_RELATION); 49 relations.add(IMPLEMENTS_RELATION); 50 relations.add(INHERITS_MEMBERS_RELATION); 51 } 52 53 public List getRelations() { 54 return relations; 55 } 56 57 public List getRelationNodes(ASTObject astObject) { 58 List relations = new ArrayList(); 59 if (astObject instanceof TypeDec) { 60 TypeDec typeDec = (TypeDec)astObject; 61 boolean isInterface = (astObject instanceof InterfaceDec); 62 List superTypes = getTypeLinks(typeDec.getType().getDirectSuperTypes(), true, isInterface); 63 List subTypes = getTypeLinks(typeDec.getType().getDirectSubTypes(), true, isInterface); 64 if (!superTypes.isEmpty()) relations.add(new RelationNode(INHERITS_RELATION, INHERITS_RELATION.getForwardNavigationName(), superTypes)); 65 if (!subTypes.isEmpty()) relations.add(new RelationNode(INHERITS_RELATION, INHERITS_RELATION.getBackNavigationName(), subTypes)); 66 67 List implementedInterfaces = getTypeLinks(typeDec.getType().getDirectSuperTypes(), false, isInterface); 68 List implementors = getTypeLinks(typeDec.getType().getDirectSubTypes(), false, isInterface); 69 if (!implementedInterfaces.isEmpty()) relations.add(new RelationNode(IMPLEMENTS_RELATION, IMPLEMENTS_RELATION.getForwardNavigationName(), implementedInterfaces)); 70 if (!implementors.isEmpty()) relations.add(new RelationNode(IMPLEMENTS_RELATION, IMPLEMENTS_RELATION.getBackNavigationName(), implementors)); 71 72 List inheritedMembers = new ArrayList(getMemberLinks(typeDec.getType().getInheritedMethods())); 73 if (!inheritedMembers.isEmpty()) relations.add(new RelationNode(INHERITS_MEMBERS_RELATION, INHERITS_MEMBERS_RELATION.getForwardNavigationName(), inheritedMembers)); 76 } 77 return relations; 78 } 79 80 private List getTypeLinks(Collection types, boolean isInheritance, boolean isInterface) { 81 List links = new ArrayList(); 82 if (types != null) { 83 for (Iterator it = types.iterator(); it.hasNext(); ) { 84 NameType nameType = (NameType)it.next(); 85 if (!nameType.getId().equals("Object")) { 86 if (isInheritance && ((isInterface && nameType.isInterface()) || (!isInterface && !nameType.isInterface())) 87 || !isInheritance && (!isInterface && nameType.isInterface())) { 88 Dec dec = nameType.getCorrespondingDec(); 89 links.add(StructureNodeFactory.makeLink(dec, false)); 90 } 91 } 92 } 93 } 94 return links; 95 } 96 97 private List getMemberLinks(Collection members) { 98 List links = new ArrayList(); 99 if (members != null) { 100 for (Iterator it = members.iterator(); it.hasNext(); ) { 101 Object object = it.next(); 102 if (object instanceof Method) { 103 Method method = (Method)object; 104 if (!method.getDeclaringType().getId().equals("Object")) { 105 links.add(StructureNodeFactory.makeLink(method.getCorrespondingDec(), false)); 106 } 107 } else if (object instanceof Field) { 108 Field field = (Field)object; 109 if (!field.getDeclaringType().getId().equals("Object")) { 110 links.add(StructureNodeFactory.makeLink(field.getCorrespondingDec(), false)); 111 } 112 } 113 } 114 } 115 return links; 116 } 117 118 public String getName() { 119 return NAME; 120 } 121 } 122 | Popular Tags |