From cd123ff75a28937d49d19cdbdcb57ad9f4328b75 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 22 Jan 2010 22:53:08 +0000 Subject: improved assert --- asm/src/org/aspectj/asm/AsmManager.java | 349 ++++++++++++-------------------- 1 file changed, 135 insertions(+), 214 deletions(-) (limited to 'asm/src') diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java index 0423fa1f7..5d4cc1dcd 100644 --- a/asm/src/org/aspectj/asm/AsmManager.java +++ b/asm/src/org/aspectj/asm/AsmManager.java @@ -144,8 +144,9 @@ public class AsmManager implements IStructureModel { */ public HashMap getInlineAnnotations(String sourceFile, boolean showSubMember, boolean showMemberAndType) { - if (!hierarchy.isValid()) + if (!hierarchy.isValid()) { return null; + } HashMap annotations = new HashMap(); IProgramElement node = hierarchy.findElementForSourceFile(sourceFile); @@ -175,8 +176,9 @@ public class AsmManager implements IStructureModel { private void getAllStructureChildren(IProgramElement node, List result, boolean showSubMember, boolean showMemberAndType) { List children = node.getChildren(); - if (node.getChildren() == null) + if (node.getChildren() == null) { return; + } for (Iterator it = children.iterator(); it.hasNext();) { IProgramElement next = (IProgramElement) it.next(); List rels = mapper.get(next); @@ -384,8 +386,9 @@ public class AsmManager implements IStructureModel { ret = f.getPath(); } pathMap.put(f.getPath(), ret); - if (pathMap.size() > MAX_SIZE) + if (pathMap.size() > MAX_SIZE) { pathMap.clear(); + } } return ret; } @@ -426,8 +429,9 @@ public class AsmManager implements IStructureModel { // and relationship map are reported and as a consequence single // testcases test that both the model and relationship map are correct. public void reportModelInfo(String reasonForReport) { - if (!dumpModel && !dumpRelationships) + if (!dumpModel && !dumpRelationships) { return; + } try { FileWriter fw = new FileWriter(dumpFilename, true); BufferedWriter bw = new BufferedWriter(fw); @@ -458,36 +462,42 @@ public class AsmManager implements IStructureModel { } public static void dumptree(Writer w, IProgramElement node, int indent) throws IOException { - for (int i = 0; i < indent; i++) + for (int i = 0; i < indent; i++) { w.write(" "); + } String loc = ""; if (node != null) { if (node.getSourceLocation() != null) { loc = node.getSourceLocation().toString(); - if (modelFilter != null) + if (modelFilter != null) { loc = modelFilter.processFilelocation(loc); + } } } w.write(node + " [" + (node == null ? "null" : node.getKind().toString()) + "] " + loc + "\n"); - if (node != null) + if (node != null) { for (Iterator i = node.getChildren().iterator(); i.hasNext();) { dumptree(w, (IProgramElement) i.next(), indent + 2); } + } } public static void dumptree(IProgramElement node, int indent) throws IOException { - for (int i = 0; i < indent; i++) + for (int i = 0; i < indent; i++) { System.out.print(" "); + } String loc = ""; if (node != null) { - if (node.getSourceLocation() != null) + if (node.getSourceLocation() != null) { loc = node.getSourceLocation().toString(); + } } System.out.println(node + " [" + (node == null ? "null" : node.getKind().toString()) + "] " + loc); - if (node != null) + if (node != null) { for (Iterator i = node.getChildren().iterator(); i.hasNext();) { dumptree((IProgramElement) i.next(), indent + 2); } + } } public void dumprels(Writer w) throws IOException { @@ -502,8 +512,9 @@ public class AsmManager implements IStructureModel { for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) { String thid = (String) iterator2.next(); StringBuffer sb = new StringBuffer(); - if (modelFilter == null || modelFilter.wantsHandleIds()) + if (modelFilter == null || modelFilter.wantsHandleIds()) { sb.append("Hid:" + (ctr++) + ":"); + } sb.append("(targets=" + targets.size() + ") " + hid + " (" + ir.getName() + ") " + thid + "\n"); w.write(sb.toString()); } @@ -554,9 +565,10 @@ public class AsmManager implements IStructureModel { removeNode(progElem); lastBuildChanges.add(fileForCompilation); deletedNodes.add(getCanonicalFilePath(progElem.getSourceLocation().getSourceFile())); - if (!hierarchy.removeFromFileMap(correctedPath)) + if (!hierarchy.removeFromFileMap(correctedPath)) { throw new RuntimeException("Whilst repairing model, couldn't remove entry for file: " + correctedPath + " from the filemap"); + } modelModified = true; } } @@ -595,9 +607,10 @@ public class AsmManager implements IStructureModel { } removeNode(progElem); deletedNodes.add(getCanonicalFilePath(progElem.getSourceLocation().getSourceFile())); - if (!hierarchy.removeFromFileMap(correctedPath)) + if (!hierarchy.removeFromFileMap(correctedPath)) { throw new RuntimeException("Whilst repairing model, couldn't remove entry for file: " + correctedPath + " from the filemap"); + } modelModified = true; } } @@ -697,8 +710,9 @@ public class AsmManager implements IStructureModel { */ public void removeRelationshipsTargettingThisType(String typename) { boolean debug = false; - if (debug) + if (debug) { System.err.println(">>removeRelationshipsTargettingThisType " + typename); + } String pkg = null; String type = typename; int lastSep = typename.lastIndexOf('.'); @@ -712,8 +726,9 @@ public class AsmManager implements IStructureModel { // Reasons for that being null: // 1. the file has fundamental errors and so doesn't exist in the model // (-proceedOnError probably forced us to weave) - if (typeNode == null) + if (typeNode == null) { return; + } Set sourcesToRemove = new HashSet(); Map handleToTypenameCache = new HashMap(); @@ -740,11 +755,13 @@ public class AsmManager implements IStructureModel { List relationships = mapper.get(hid); for (Iterator reliter = relationships.iterator(); reliter.hasNext();) { IRelationship rel = (IRelationship) reliter.next(); - if (rel.getKind() == IRelationship.Kind.USES_POINTCUT) + if (rel.getKind() == IRelationship.Kind.USES_POINTCUT) { continue; // these relationships are added at compile + } // time, argh - if (rel.isAffects()) + if (rel.isAffects()) { continue; // we want 'affected by' relationships - (e.g. + } // advised by) relationshipsToRemove.add(rel); // all the relationships can // be removed, regardless of @@ -754,11 +771,12 @@ public class AsmManager implements IStructureModel { // and so need removing for this source handle if (relationshipsToRemove.size() > 0) { didsomething = true; - if (relationshipsToRemove.size() == relationships.size()) + if (relationshipsToRemove.size() == relationships.size()) { sourcesToRemove.add(hid); - else { - for (int i = 0; i < relationshipsToRemove.size(); i++) + } else { + for (int i = 0; i < relationshipsToRemove.size(); i++) { relationships.remove(relationshipsToRemove.get(i)); + } } } } @@ -773,21 +791,24 @@ public class AsmManager implements IStructureModel { if (ipe != null) { // If the relationship was hanging off a 'code' node, delete it. if (ipe.getKind().equals(IProgramElement.Kind.CODE)) { - if (debug) + if (debug) { System.err.println(" source handle: it was code node, removing that as well... code=" + ipe + " parent=" + ipe.getParent()); + } removeSingleNode(ipe); } } } - if (debug) + if (debug) { dumprelsStderr("after processing 'affectedby'"); + } if (didsomething) { // did we do anything? sourcesToRemove.clear(); // removing 'affects' relationships - if (debug) + if (debug) { dumprelsStderr("before processing 'affects'"); + } // Iterate over the source handles in the relationships map sourcehandlesSet = mapper.getEntries(); for (Iterator keyiter = sourcehandlesSet.iterator(); keyiter.hasNext();) { @@ -796,11 +817,13 @@ public class AsmManager implements IStructureModel { List relationships = mapper.get(hid); for (Iterator reliter = relationships.iterator(); reliter.hasNext();) { IRelationship rel = (IRelationship) reliter.next(); - if (rel.getKind() == IRelationship.Kind.USES_POINTCUT) + if (rel.getKind() == IRelationship.Kind.USES_POINTCUT) { continue; // these relationships are added at compile + } // time, argh - if (!rel.isAffects()) + if (!rel.isAffects()) { continue; + } List targets = rel.getTargets(); List targetsToRemove = new ArrayList(); @@ -813,14 +836,15 @@ public class AsmManager implements IStructureModel { } // Does this point to the same type? IProgramElement existingTarget = hierarchy.getElement(targethid); - if (existingTarget == null || sameType(targethid, existingTarget, typeNode)) + if (existingTarget == null || sameType(targethid, existingTarget, typeNode)) { targetsToRemove.add(targethid); + } } if (targetsToRemove.size() != 0) { - if (targetsToRemove.size() == targets.size()) + if (targetsToRemove.size() == targets.size()) { relationshipsToRemove.add(rel); - else { + } else { // Remove all the targets that are no longer valid for (Iterator targsIter = targetsToRemove.iterator(); targsIter.hasNext();) { String togo = (String) targsIter.next(); @@ -834,11 +858,12 @@ public class AsmManager implements IStructureModel { if (relationshipsToRemove.size() > 0) { // Are we removing *all* of the relationships for this // source handle? - if (relationshipsToRemove.size() == relationships.size()) + if (relationshipsToRemove.size() == relationships.size()) { sourcesToRemove.add(hid); - else { - for (int i = 0; i < relationshipsToRemove.size(); i++) + } else { + for (int i = 0; i < relationshipsToRemove.size(); i++) { relationships.remove(relationshipsToRemove.get(i)); + } } } } @@ -853,19 +878,22 @@ public class AsmManager implements IStructureModel { // If the relationship was hanging off a 'code' node, delete // it. if (ipe.getKind().equals(IProgramElement.Kind.CODE)) { - if (debug) + if (debug) { System.err.println(" source handle: it was code node, removing that as well... code=" + ipe + " parent=" + ipe.getParent()); + } removeSingleNode(ipe); } } } - if (debug) + if (debug) { dumprelsStderr("after processing 'affects'"); + } } - if (debug) + if (debug) { System.err.println("<