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 Reference implements Association { 41 public static final String NAME = "Reference"; 42 public static final Relation USES_POINTCUT_RELATION = new Relation("uses pointcut", "pointcut used by", NAME, true, true); 43 public static final Relation IMPORTS_RELATION = new Relation("imports", NAME, false); 44 47 private List relations = new ArrayList(); 48 49 public Reference() { 50 relations.add(USES_POINTCUT_RELATION); 51 relations.add(IMPORTS_RELATION); 52 } 55 56 public List getRelations() { 57 return relations; 58 } 59 60 public List getRelationNodes(ASTObject astObject) { 61 List relations = new ArrayList(); 62 List pointcutsUsed = new ArrayList(); 63 List pointcutUsedBy = new ArrayList(); 64 List throwsTypes = new ArrayList(); 65 List imports = new ArrayList(); 66 List usesType = new ArrayList(); 67 Set forwardCorrs = StructureModelManager.correspondences.getAffects(astObject); 68 Set backCorrs = StructureModelManager.correspondences.getAffectedBy(astObject); 69 70 if (astObject instanceof AdviceDec) { 71 for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) { 72 ASTObject node = (ASTObject)it.next(); 73 if (node instanceof PointcutDec) { 74 pointcutsUsed.add(StructureNodeFactory.makeLink(node, false)); 75 } 76 } 77 } else if (astObject instanceof PointcutDec) { 78 for (Iterator it = backCorrs.iterator(); it.hasNext(); ) { 79 ASTObject node = (ASTObject)it.next(); 80 if (node instanceof PointcutDec || node instanceof AdviceDec) { 81 pointcutUsedBy.add(StructureNodeFactory.makeLink(node, false)); 82 } 83 } 84 for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) { 85 ASTObject node = (ASTObject)it.next(); 86 if (node instanceof PointcutDec) { 87 pointcutsUsed.add(StructureNodeFactory.makeLink(node, false)); 88 } 89 } 90 } else if (astObject instanceof MethodDec) { 91 Method method = ((MethodDec)astObject).getMethod(); 92 TypeDs throwsDs = method.getThrows(); 93 if (throwsDs != null) { 94 for (Iterator it = throwsDs.iterator(); it.hasNext(); ) { 95 Object o = it.next(); 96 if (o instanceof ResolvedTypeD) { 97 ResolvedTypeD resolved = (ResolvedTypeD)o; 98 if (resolved.getType().getCorrespondingDec() != null) { 99 throwsTypes.add(StructureNodeFactory.makeLink(resolved.getType().getCorrespondingDec(), false)); 100 } 101 } 102 } 103 } 104 if (!(method.getReturnType() instanceof PrimitiveType) && method.getReturnType().getCorrespondingDec() != null) { 105 usesType.add(StructureNodeFactory.makeLink(method.getReturnType().getCorrespondingDec(), false)); 106 } 107 } else if (astObject instanceof FieldDec) { 108 Field field = ((FieldDec)astObject).getField(); 109 if (!(field.getFieldType() instanceof PrimitiveType) && field.getFieldType().getCorrespondingDec() != null) { 110 usesType.add(StructureNodeFactory.makeLink(field.getFieldType().getCorrespondingDec(), false)); 111 } 112 } 113 else if (astObject instanceof CompilationUnit) { 114 CompilationUnit cu = (CompilationUnit)astObject; 115 org.aspectj.compiler.base.ast.Imports cuImports = cu.getImports(); 116 for (int i = 0; cuImports != null && i < cuImports.getChildCount(); i++) { 117 Import imp = cuImports.get(i); 118 if (!imp.getStar() && imp != null && imp.getType() != null) { 119 Type type = imp.getType(); 120 Dec dec = type.getCorrespondingDec(); 121 if (dec != null) imports.add(StructureNodeFactory.makeLink(dec, true)); 122 } 123 } 124 } 125 126 if (!pointcutsUsed.isEmpty()) relations.add(new RelationNode(USES_POINTCUT_RELATION, USES_POINTCUT_RELATION.getForwardNavigationName(), pointcutsUsed)); 127 if (!pointcutUsedBy.isEmpty()) relations.add(new RelationNode(USES_POINTCUT_RELATION, USES_POINTCUT_RELATION.getBackNavigationName(), pointcutUsedBy)); 128 if (!imports.isEmpty()) relations.add(new RelationNode(IMPORTS_RELATION, IMPORTS_RELATION.getForwardNavigationName(), imports)); 130 return relations; 132 } 133 134 public String getName() { 135 return NAME; 136 } 137 } 138 139 140 172 173 | Popular Tags |