Browse Source

generics

tags/V1_6_10RC1
aclement 14 years ago
parent
commit
2bcdbacf5f

+ 62
- 164
asm/src/org/aspectj/asm/AsmManager.java View File

@@ -88,7 +88,7 @@ public class AsmManager implements IStructureModel {
* Map from String > String - it maps absolute paths for inpath dirs/jars to workspace relative paths suitable for handle
* inclusion
*/
protected Map inpathMap;
protected Map<File, String> inpathMap;
private IRelationshipMap mapper;
private IElementHandleProvider handleProvider;

@@ -98,7 +98,7 @@ public class AsmManager implements IStructureModel {
private final Set<File> lastBuildChanges = new HashSet<File>();

// Record the Set<File> of aspects that wove the files listed in lastBuildChanges
final Set aspectsWeavingInLastBuild = new HashSet();
final Set<File> aspectsWeavingInLastBuild = new HashSet<File>();

// static {
// setReporting("c:/model.nfo",true,true,true,true);
@@ -107,14 +107,14 @@ public class AsmManager implements IStructureModel {
private AsmManager() {
}

public static AsmManager createNewStructureModel(Map inpathMap) {
public static AsmManager createNewStructureModel(Map<File, String> inpathMap) {
if (forceSingletonBehaviour && lastActiveStructureModel != null) {
return lastActiveStructureModel;
}
AsmManager asm = new AsmManager();
asm.inpathMap = inpathMap;
asm.hierarchy = new AspectJElementHierarchy(asm);
asm.mapper = new RelationshipMap(asm.hierarchy);
asm.mapper = new RelationshipMap();
asm.handleProvider = new JDTLikeHandleProvider(asm);
// call initialize on the handleProvider when we create a new ASM
// to give handleProviders the chance to reset any state
@@ -255,7 +255,6 @@ public class AsmManager implements IStructureModel {
((AspectJElementHierarchy) hierarchy).setAsmManager(this);
hierarchyReadOK = true;
mapper = (RelationshipMap) s.readObject();
((RelationshipMap) mapper).setHierarchy(hierarchy);
}
} catch (FileNotFoundException fnfe) {
// That is OK
@@ -494,23 +493,20 @@ public class AsmManager implements IStructureModel {
}
System.out.println(node + " [" + (node == null ? "null" : node.getKind().toString()) + "] " + loc);
if (node != null) {
for (Iterator i = node.getChildren().iterator(); i.hasNext();) {
dumptree((IProgramElement) i.next(), indent + 2);
for (IProgramElement child : node.getChildren()) {
dumptree(child, indent + 2);
}
}
}

public void dumprels(Writer w) throws IOException {
int ctr = 1;
Set entries = mapper.getEntries();
for (Iterator iter = entries.iterator(); iter.hasNext();) {
String hid = (String) iter.next();
List rels = mapper.get(hid);
for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
IRelationship ir = (IRelationship) iterator.next();
List targets = ir.getTargets();
for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) {
String thid = (String) iterator2.next();
Set<String> entries = mapper.getEntries();
for (String hid : entries) {
List<IRelationship> rels = mapper.get(hid);
for (IRelationship ir : rels) {
List<String> targets = ir.getTargets();
for (String thid : targets) {
StringBuffer sb = new StringBuffer();
if (modelFilter == null || modelFilter.wantsHandleIds()) {
sb.append("Hid:" + (ctr++) + ":");
@@ -525,15 +521,11 @@ public class AsmManager implements IStructureModel {
private void dumprelsStderr(String key) {
System.err.println("Relationships dump follows: " + key);
int ctr = 1;
Set entries = mapper.getEntries();
for (Iterator iter = entries.iterator(); iter.hasNext();) {
String hid = (String) iter.next();
List rels = mapper.get(hid);
for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
IRelationship ir = (IRelationship) iterator.next();
List targets = ir.getTargets();
for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) {
String thid = (String) iterator2.next();
Set<String> entries = mapper.getEntries();
for (String hid : entries) {
for (IRelationship ir : mapper.get(hid)) {
List<String> targets = ir.getTargets();
for (String thid : targets) {
System.err.println("Hid:" + (ctr++) + ":(targets=" + targets.size() + ") " + hid + " (" + ir.getName() + ") "
+ thid);
}
@@ -548,13 +540,12 @@ public class AsmManager implements IStructureModel {
/**
* Removes the hierarchy structure for the specified files from the structure model. Returns true if it deleted anything
*/
public boolean removeStructureModelForFiles(Writer fw, Collection files) throws IOException {
public boolean removeStructureModelForFiles(Writer fw, Collection<File> files) throws IOException {

boolean modelModified = false;

Set<String> deletedNodes = new HashSet<String>();
for (Iterator iter = files.iterator(); iter.hasNext();) {
File fileForCompilation = (File) iter.next();
for (File fileForCompilation : files) {
String correctedPath = getCanonicalFilePath(fileForCompilation);
IProgramElement progElem = (IProgramElement) hierarchy.findInFileMap(correctedPath);
if (progElem != null) {
@@ -593,11 +584,11 @@ public class AsmManager implements IStructureModel {
// Files to delete are: those to be compiled + those that have been
// deleted

Set filesToRemoveFromStructureModel = new HashSet(filesToBeCompiled);
Set<File> filesToRemoveFromStructureModel = new HashSet(filesToBeCompiled);
filesToRemoveFromStructureModel.addAll(files_deleted);
Set<String> deletedNodes = new HashSet<String>();
for (Iterator iter = filesToRemoveFromStructureModel.iterator(); iter.hasNext();) {
File fileForCompilation = (File) iter.next();
for (Iterator<File> iter = filesToRemoveFromStructureModel.iterator(); iter.hasNext();) {
File fileForCompilation = iter.next();
String correctedPath = getCanonicalFilePath(fileForCompilation);
IProgramElement progElem = (IProgramElement) hierarchy.findInFileMap(correctedPath);
if (progElem != null) {
@@ -620,7 +611,7 @@ public class AsmManager implements IStructureModel {
}
}

public void processDelta(Collection files_tobecompiled, Set files_added, Set files_deleted) {
public void processDelta(Collection<File> files_tobecompiled, Set<File> files_added, Set<File> files_deleted) {

try {
Writer fw = null;
@@ -730,17 +721,16 @@ public class AsmManager implements IStructureModel {
return;
}

Set sourcesToRemove = new HashSet();
Set<String> sourcesToRemove = new HashSet<String>();
Map handleToTypenameCache = new HashMap();
// Iterate over the source handles in the relationships map, the aim
// here is to remove any 'affected by'
// relationships where the source of the relationship is the specified
// type (since it will be readded
// when the type is woven)
Set sourcehandlesSet = mapper.getEntries();
Set<String> sourcehandlesSet = mapper.getEntries();
List<IRelationship> relationshipsToRemove = new ArrayList<IRelationship>();
for (Iterator keyiter = sourcehandlesSet.iterator(); keyiter.hasNext();) {
String hid = (String) keyiter.next();
for (String hid : sourcehandlesSet) {
if (isPhantomHandle(hid)) {
// inpath handle - but for which type?
// TODO promote cache for reuse during one whole model update
@@ -810,12 +800,10 @@ public class AsmManager implements IStructureModel {
}
// Iterate over the source handles in the relationships map
sourcehandlesSet = mapper.getEntries();
for (Iterator keyiter = sourcehandlesSet.iterator(); keyiter.hasNext();) {
String hid = (String) keyiter.next();
for (String hid : sourcehandlesSet) {
relationshipsToRemove.clear();
List relationships = mapper.get(hid);
for (Iterator reliter = relationships.iterator(); reliter.hasNext();) {
IRelationship rel = (IRelationship) reliter.next();
List<IRelationship> relationships = mapper.get(hid);
for (IRelationship rel : relationships) {
if (rel.getKind() == IRelationship.Kind.USES_POINTCUT) {
continue; // these relationships are added at compile
}
@@ -823,13 +811,12 @@ public class AsmManager implements IStructureModel {
if (!rel.isAffects()) {
continue;
}
List targets = rel.getTargets();
List targetsToRemove = new ArrayList();
List<String> targets = rel.getTargets();
List<String> targetsToRemove = new ArrayList<String>();

// find targets that target the type we are interested in,
// they need removing
for (Iterator targetsIter = targets.iterator(); targetsIter.hasNext();) {
String targethid = (String) targetsIter.next();
for (String targethid : targets) {
if (isPhantomHandle(hid) && !getTypeNameFromHandle(hid, handleToTypenameCache).equals(typename)) {
continue;
}
@@ -845,8 +832,7 @@ public class AsmManager implements IStructureModel {
relationshipsToRemove.add(rel);
} else {
// Remove all the targets that are no longer valid
for (Iterator targsIter = targetsToRemove.iterator(); targsIter.hasNext();) {
String togo = (String) targsIter.next();
for (String togo : targetsToRemove) {
targets.remove(togo);
}
}
@@ -867,8 +853,7 @@ public class AsmManager implements IStructureModel {
}
}
// Remove sources that have no valid relationships any more
for (Iterator srciter = sourcesToRemove.iterator(); srciter.hasNext();) {
String hid = (String) srciter.next();
for (String hid : sourcesToRemove) {
// System.err.println(
// " source handle: all relationships have gone for "+hid);
mapper.removeAll(hid);
@@ -973,16 +958,15 @@ public class AsmManager implements IStructureModel {

// Now sort out the relationships map
// IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
Set sourcesToRemove = new HashSet();
Set nonExistingHandles = new HashSet(); // Cache of handles that we
Set<String> sourcesToRemove = new HashSet<String>();
Set<String> nonExistingHandles = new HashSet<String>(); // Cache of handles that we
// *know* are invalid
int srchandlecounter = 0;
int tgthandlecounter = 0;

// Iterate over the source handles in the relationships map
Set keyset = mapper.getEntries(); // These are source handles
for (Iterator keyiter = keyset.iterator(); keyiter.hasNext();) {
String hid = (String) keyiter.next();
Set<String> keyset = mapper.getEntries(); // These are source handles
for (String hid : keyset) {
srchandlecounter++;

// Do we already know this handle points to nowhere?
@@ -1007,12 +991,12 @@ public class AsmManager implements IStructureModel {
// handle
for (Iterator<IRelationship> reliter = relationships.iterator(); reliter.hasNext();) {
IRelationship rel = reliter.next();
List targets = rel.getTargets();
List targetsToRemove = new ArrayList();
List<String> targets = rel.getTargets();
List<String> targetsToRemove = new ArrayList<String>();

// Iterate through the targets for this relationship
for (Iterator targetIter = targets.iterator(); targetIter.hasNext();) {
String targethid = (String) targetIter.next();
for (Iterator<String> targetIter = targets.iterator(); targetIter.hasNext();) {
String targethid = targetIter.next();
tgthandlecounter++;
// Do we already know it doesn't exist?
if (nonExistingHandles.contains(targethid)) {
@@ -1048,8 +1032,7 @@ public class AsmManager implements IStructureModel {
} else {
// Remove all the targets that are no longer
// valid
for (Iterator targsIter = targetsToRemove.iterator(); targsIter.hasNext();) {
String togo = (String) targsIter.next();
for (String togo : targetsToRemove) {
targets.remove(togo);
}
// Should have already been caught above,
@@ -1087,11 +1070,11 @@ public class AsmManager implements IStructureModel {
// MEMORY LEAK - we don't remove the
// relationships !!
for (int i = 0; i < relationshipsToRemove.size(); i++) {
IRelationship irel = (IRelationship) relationshipsToRemove.get(i);
IRelationship irel = relationshipsToRemove.get(i);
verifyAssumption(mapper.remove(hid, irel), "Failed to remove relationship " + irel.getName()
+ " for shid " + hid);
}
List rels = mapper.get(hid);
List<IRelationship> rels = mapper.get(hid);
if (rels == null || rels.size() == 0) {
sourcesToRemove.add(hid);
}
@@ -1101,8 +1084,8 @@ public class AsmManager implements IStructureModel {
}
}
// Remove sources that have no valid relationships any more
for (Iterator srciter = sourcesToRemove.iterator(); srciter.hasNext();) {
String hid = (String) srciter.next();
for (Iterator<String> srciter = sourcesToRemove.iterator(); srciter.hasNext();) {
String hid = srciter.next();
mapper.removeAll(hid);
IProgramElement ipe = hierarchy.getElement(hid);
if (ipe != null) {
@@ -1130,8 +1113,8 @@ public class AsmManager implements IStructureModel {
}
boolean deleteOK = false;
IProgramElement parent = progElem.getParent();
List kids = parent.getChildren();
for (int i = 0; i < kids.size(); i++) {
List<IProgramElement> kids = parent.getChildren();
for (int i = 0, max = kids.size(); i < max; i++) {
if (kids.get(i).equals(progElem)) {
kids.remove(i);
deleteOK = true;
@@ -1164,7 +1147,7 @@ public class AsmManager implements IStructureModel {
// boolean deleteOK = false;
IProgramElement parent = progElem.getParent();
// flightrecorder.append("Parent of it is "+parent+"\n");
List kids = parent.getChildren();
List<IProgramElement> kids = parent.getChildren();
// flightrecorder.append("Which has "+kids.size()+" kids\n");
for (int i = 0; i < kids.size(); i++) {
// flightrecorder.append("Comparing with "+kids.get(i)+"\n");
@@ -1219,7 +1202,7 @@ public class AsmManager implements IStructureModel {
* A ModelInfo object captures basic information about the structure model. It is used for testing and producing debug info.
*/
public static class ModelInfo {
private final Hashtable nodeTypeCount = new Hashtable();
private final Hashtable<String, Integer> nodeTypeCount = new Hashtable<String, Integer>();
private final Properties extraProperties = new Properties();

private ModelInfo(IHierarchy hierarchy, IRelationshipMap relationshipMap) {
@@ -1231,16 +1214,14 @@ public class AsmManager implements IStructureModel {

private void walkModel(IProgramElement ipe) {
countNode(ipe);
List kids = ipe.getChildren();
for (Iterator iter = kids.iterator(); iter.hasNext();) {
IProgramElement nextElement = (IProgramElement) iter.next();
walkModel(nextElement);
for (IProgramElement child : ipe.getChildren()) {
walkModel(child);
}
}

private void countNode(IProgramElement ipe) {
String node = ipe.getKind().toString();
Integer ctr = (Integer) nodeTypeCount.get(node);
Integer ctr = nodeTypeCount.get(node);
if (ctr == null) {
nodeTypeCount.put(node, new Integer(1));
} else {
@@ -1252,10 +1233,10 @@ public class AsmManager implements IStructureModel {
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Model node summary:\n");
Enumeration nodeKeys = nodeTypeCount.keys();
Enumeration<String> nodeKeys = nodeTypeCount.keys();
while (nodeKeys.hasMoreElements()) {
String key = (String) nodeKeys.nextElement();
Integer ct = (Integer) nodeTypeCount.get(key);
String key = nodeKeys.nextElement();
Integer ct = nodeTypeCount.get(key);
sb.append(key + "=" + ct + "\n");
}
sb.append("Model stats:\n");
@@ -1270,11 +1251,8 @@ public class AsmManager implements IStructureModel {

public Properties getProperties() {
Properties p = new Properties();
Enumeration nodeKeys = nodeTypeCount.keys();
while (nodeKeys.hasMoreElements()) {
String key = (String) nodeKeys.nextElement();
Integer ct = (Integer) nodeTypeCount.get(key);
p.setProperty(key, ct.toString());
for (Map.Entry<String, Integer> entry : nodeTypeCount.entrySet()) {
p.setProperty(entry.getKey(), entry.getValue().toString());
}
p.putAll(extraProperties);
return p;
@@ -1329,14 +1307,14 @@ public class AsmManager implements IStructureModel {
* @return the Set of files for which the structure model was modified (they may have been removed or otherwise rebuilt). Set is
* empty for a full build.
*/
public Set getModelChangesOnLastBuild() {
public Set<File> getModelChangesOnLastBuild() {
return lastBuildChanges;
}

/**
* @return the Set of aspects that wove files on the last build (either incremental or full build)
*/
public Set getAspectsWeavingFilesOnLastBuild() {
public Set<File> getAspectsWeavingFilesOnLastBuild() {
return aspectsWeavingInLastBuild;
}

@@ -1351,86 +1329,6 @@ public class AsmManager implements IStructureModel {
}

public String getHandleElementForInpath(String binaryPath) {
return (String) inpathMap.get(new File(binaryPath));
}

private List pieces = new ArrayList();

private Object intern(String substring) {
int lastIdx = -1;
if ((lastIdx = substring.lastIndexOf('/')) != -1) {
String pkg = substring.substring(0, lastIdx);
String type = substring.substring(lastIdx + 1);
pkg = internOneThing(pkg);
type = internOneThing(type);
return new String[] { pkg, type };
} else {
return internOneThing(substring);
}
}

private String internOneThing(String substring) {
// simple name
for (int p = 0, max = pieces.size(); p < max; p++) {
String s = (String) pieces.get(p);
if (s.equals(substring)) {
return s;
}
}
pieces.add(substring);
return substring;
return inpathMap.get(new File(binaryPath));
}

/**
* What we can rely on: <br>
* - it is a method signature of the form (La/B;Lc/D;)LFoo;<br>
* - there are no generics<br>
*
* What we must allow for: - may use primitive refs (single chars rather than L)
*/
/*
* public List compress(String s) { int openParen = 0; int closeParen = s.indexOf(')'); int pos = 1; List compressed = new
* ArrayList(); // do the parens while (pos < closeParen) { char ch = s.charAt(pos); if (ch == 'L') { int idx = s.indexOf(';',
* pos); compressed.add(intern(s.substring(pos + 1, idx))); pos = idx + 1; } else if (ch == '[') { int x = pos; while
* (s.charAt(++pos) == '[') ; // now pos will point at something not an array compressed.add(intern(s.substring(x, pos))); //
* intern the [[[[[[ char ch2 = s.charAt(pos); if (ch2 == 'L') { int idx = s.indexOf(';', pos);
* compressed.add(intern(s.substring(pos + 1, idx))); pos = idx + 1; } else if (ch2 == 'T') { int idx = s.indexOf(';');
* compressed.add(intern(s.substring(pos, idx + 1))); // should be TT; pos = idx + 1; } else {
* compressed.add(toCharacter(s.charAt(pos))); pos++; } } else { // it is a primitive ref (SVBCZJ)
* compressed.add(toCharacter(ch)); pos++; } } // do the return type pos++; char ch = s.charAt(pos); if (ch == 'L') { int idx =
* s.indexOf(';', pos); compressed.add(intern(s.substring(pos, idx))); } else if (ch == '[') { int x = pos; while
* (s.charAt(++pos) == '[') ; // now pos will point at something not an array compressed.add(intern(s.substring(x, pos))); //
* intern the [[[[[[ char ch2 = s.charAt(pos); if (ch2 == 'L') { int idx = s.indexOf(';', pos);
* compressed.add(intern(s.substring(pos + 1, idx))); pos = idx + 1; } else if (ch2 == 'T') { int idx = s.indexOf(';');
* compressed.add(intern(s.substring(pos, idx + 1))); // should be TT; pos = idx + 2; } else {
* compressed.add(toCharacter(s.charAt(pos))); pos++; } } else { // it is a primitive ref (SVBCZJ) compressed.add(new
* Character(ch)); } return compressed;
*
* // char delimiter = '/'; // int pos = -1; // List compressed = new ArrayList(); // int start = 0; // while ((pos =
* s.indexOf(delimiter, start)) != -1) { // String part = s.substring(start, pos); // int alreadyRecorded =
* pieces.indexOf(part); // if (alreadyRecorded != -1) { // compressed.add(new Integer(alreadyRecorded)); // } else { //
* compressed.add(new Integer(pieces.size())); // pieces.add(part); // } // start = pos + 1; // } // // last piece // String
* part = s.substring(start, s.length()); // int alreadyRecorded = pieces.indexOf(part); // if (alreadyRecorded != -1) { //
* compressed.add(youkirtyounew Integer(alreadyRecorded)); // } else { // compressed.add(new Integer(pieces.size())); //
* pieces.add(part); // } // return compressed; }
*
* static final Character charB = new Character('B'); static final Character charS = new Character('S'); static final Character
* charI = new Character('I'); static final Character charF = new Character('F'); static final Character charD = new
* Character('D'); static final Character charJ = new Character('J'); static final Character charC = new Character('C'); static
* final Character charV = new Character('V'); static final Character charZ = new Character('Z');
*
* private Character toCharacter(char ch) { switch (ch) { case 'B': return charB; case 'S': return charS; case 'I': return
* charI; case 'F': return charF; case 'D': return charD; case 'J': return charJ; case 'C': return charC; case 'V': return
* charV; case 'Z': return charZ; default: throw new IllegalStateException(new Character(ch).toString()); } }
*
* public String decompress(List refs, char delimiter) { StringBuilder result = new StringBuilder(); result.append("("); for
* (int i = 0, max = refs.size() - 1; i < max; i++) { result.append(unintern(refs.get(i))); } result.append(")");
* result.append(unintern(refs.get(refs.size() - 1))); return result.toString(); }
*
* private String unintern(Object o) { if (o instanceof Character) { return ((Character) o).toString(); } else if (o instanceof
* String[]) { String[] strings = (String[]) o; StringBuilder sb = new StringBuilder(); sb.append('L');
* sb.append(strings[0]).append('/').append(strings[1]); sb.append(';'); return sb.toString(); } else { // String String so =
* (String) o; if (so.endsWith(";")) { // will be TT; return so; } else { StringBuilder sb = new StringBuilder();
* sb.append('L'); sb.append(so); sb.append(';'); return sb.toString(); } } }
*/
}

+ 15
- 11
asm/src/org/aspectj/asm/HierarchyWalker.java View File

@@ -1,5 +1,5 @@
/* *******************************************************************
* Copyright (c) 2003 Contributors.
* Copyright (c) 2003,2010 Contributors
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Mik Kersten initial implementation
* Andy Clement
* ******************************************************************/

package org.aspectj.asm;
@@ -18,16 +19,19 @@ package org.aspectj.asm;
*/
public abstract class HierarchyWalker {

public HierarchyWalker() { }
protected void preProcess(IProgramElement node) { }
protected void postProcess(IProgramElement node) { }
public HierarchyWalker() {
}

public IProgramElement process(IProgramElement node) {
protected void preProcess(IProgramElement node) {
}

protected void postProcess(IProgramElement node) {
}

public IProgramElement process(IProgramElement node) {
preProcess(node);
node.walk(this);
postProcess(node);
return node;
}
node.walk(this);
postProcess(node);
return node;
}
}

+ 3
- 2
asm/src/org/aspectj/asm/IHierarchy.java View File

@@ -14,6 +14,7 @@ package org.aspectj.asm;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.aspectj.asm.internal.ProgramElement;
@@ -42,7 +43,7 @@ public interface IHierarchy extends Serializable {

public Object findInFileMap(Object key);

public Set getFileMapEntrySet();
public Set<Map.Entry<String, IProgramElement>> getFileMapEntrySet();

public boolean isValid();

@@ -104,7 +105,7 @@ public interface IHierarchy extends Serializable {

public void flushHandleMap();

public void updateHandleMap(Set deletedFiles);
public void updateHandleMap(Set<String> deletedFiles);

/**
* For a specified node, check if any of the children more accurately represent the specified line.

+ 2
- 5
asm/src/org/aspectj/asm/IHierarchyListener.java View File

@@ -10,19 +10,16 @@
* Mik Kersten initial implementation
* ******************************************************************/


package org.aspectj.asm;

import java.util.EventListener;

//import org.aspectj.asm.internal.*;

/**
* Compiler listeners get notified of structure model update events.
*
*
* @author Mik Kersten
*/
public interface IHierarchyListener extends EventListener {

public void elementsUpdated(IHierarchy rootNode);
public void elementsUpdated(IHierarchy rootNode);
}

+ 8
- 8
asm/src/org/aspectj/asm/IModelFilter.java View File

@@ -12,21 +12,21 @@
package org.aspectj.asm;

/**
* When dumping the model out (for debugging/testing), various parts of
* it can be passed through this filter. Currently it is used to ensure
* the source locations we dump out are independent of sandbox directory.
* When dumping the model out (for debugging/testing), various parts of it can be passed through this filter. Currently it is used
* to ensure the source locations we dump out are independent of sandbox directory.
*
* @author Andy Clement
*/
public interface IModelFilter {

/**
* Called when about to dump out an absolute file location, enabling
* it to be altered (eg. c:/temp/ajcsSandbox/foo/ajctemp.12323/<BLAH>
* could become TEST_SANDBOX/<BLAH>
* Called when about to dump out an absolute file location, enabling it to be altered (eg.
* c:/temp/ajcsSandbox/foo/ajctemp.12323/<BLAH> could become TEST_SANDBOX/<BLAH>
*/
String processFilelocation(String loc);

/**
* When the relationship map is dumped, lines are prefixed with a handle ID.
* Return true if you want these, false if you dont.
* When the relationship map is dumped, lines are prefixed with a handle ID. Return true if you want these, false if you do not.
*/
boolean wantsHandleIds();
}

+ 7
- 7
asm/src/org/aspectj/asm/IProgramElement.java View File

@@ -67,9 +67,9 @@ public interface IProgramElement extends Serializable {

public void setParent(IProgramElement parent);

public void setParentTypes(List parentTypes);
public void setParentTypes(List<String> parentTypes);

public List getParentTypes();
public List<String> getParentTypes();

public String getName();

@@ -83,7 +83,7 @@ public interface IProgramElement extends Serializable {

public void setKind(Kind kind);

public List getModifiers();
public List<IProgramElement.Modifiers> getModifiers();

public void setModifiers(int i);

@@ -156,13 +156,13 @@ public interface IProgramElement extends Serializable {

public void setParameterNames(List<String> list);

public List getParameterSignatures();
public List<char[]> getParameterSignatures();

public List getParameterSignaturesSourceRefs();
public List<String> getParameterSignaturesSourceRefs();

public void setParameterSignatures(List list, List paramSourceRefs);
public void setParameterSignatures(List<char[]> list, List<String> paramSourceRefs);

public List getParameterTypes();
public List<char[]> getParameterTypes();

/**
* The format of the string handle is not specified, but is stable across compilation sessions.

+ 8
- 5
asm/src/org/aspectj/asm/IRelationshipMap.java View File

@@ -17,14 +17,17 @@ import java.util.List;
import java.util.Set;

/**
* Maps from a program element handles to a list of relationships between that element and othe program elements. Each element in
* Maps from a program element handles to a list of relationships between that element and other program elements. Each element in
* the list or relationships is uniquely identified by a kind and a relationship name. For example, the advice affecting a
* particular shadow (e.g. method call) can be retrieved by calling <CODE>get</CODE> on the handle for that method. Symmetrically
* the method call shadows that an advice affects can be retrieved.
* <p>
*
* <p>
* The elements can be stored and looked up as IProgramElement(s), in which cases the element corresponding to the handle is looked
* up in the containment hierarchy.
*
* <p>
* put/get methods taking IProgramElement as a parameter are for convenience only. They work identically to calling their
* counterparts with IProgramElement.getIdentifierHandle()
*
@@ -34,14 +37,14 @@ import java.util.Set;
public interface IRelationshipMap extends Serializable {

/**
* @return null if the element is not found.
* @return list of relationships or null if the source element has no relationships
*/
public List<IRelationship> get(IProgramElement source);
public List<IRelationship> get(IProgramElement sourceProgramElement);

/**
* @return null if the element is not found.
* @return list of relationships or null if the source element has no relationships
*/
public List<IRelationship> get(String handle);
public List<IRelationship> get(String sourceHandle);

/**
* Return a relationship matching the kind and name for the given element.

+ 19
- 22
asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java View File

@@ -44,8 +44,8 @@ public class AspectJElementHierarchy implements IHierarchy {
// Access to the handleMap and typeMap are now synchronized - at least the find methods and the updateHandleMap function
// see pr305788
private Map<String, IProgramElement> fileMap = null;
private Map handleMap = new HashMap();
private Map typeMap = null;
private Map<String, IProgramElement> handleMap = new HashMap<String, IProgramElement>();
private Map<String, IProgramElement> typeMap = null;

public AspectJElementHierarchy(AsmManager asm) {
this.asm = asm;
@@ -65,8 +65,8 @@ public class AspectJElementHierarchy implements IHierarchy {

public void setRoot(IProgramElement root) {
this.root = root;
handleMap = new HashMap();
typeMap = new HashMap();
handleMap = new HashMap<String, IProgramElement>();
typeMap = new HashMap<String, IProgramElement>();
}

public void addToFileMap(String key, IProgramElement value) {
@@ -85,7 +85,7 @@ public class AspectJElementHierarchy implements IHierarchy {
return fileMap.get(key);
}

public Set getFileMapEntrySet() {
public Set<Map.Entry<String, IProgramElement>> getFileMapEntrySet() {
return fileMap.entrySet();
}

@@ -145,7 +145,7 @@ public class AspectJElementHierarchy implements IHierarchy {
StringBuffer keyb = (packageName == null) ? new StringBuffer() : new StringBuffer(packageName);
keyb.append(".").append(typeName);
String key = keyb.toString();
IProgramElement cachedValue = (IProgramElement) typeMap.get(key);
IProgramElement cachedValue = typeMap.get(key);
if (cachedValue != null) {
return cachedValue;
}
@@ -216,12 +216,10 @@ public class AspectJElementHierarchy implements IHierarchy {
if ((children.get(0)).getKind() == IProgramElement.Kind.SOURCE_FOLDER) {
String searchPackageName = (packagename == null ? "" : packagename); // default package means match on ""
// dealing with source folders
List matchingPackageNodes = new ArrayList();
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
IProgramElement sourceFolder = (IProgramElement) iterator.next();
List possiblePackageNodes = sourceFolder.getChildren();
for (Iterator iterator2 = possiblePackageNodes.iterator(); iterator2.hasNext();) {
IProgramElement possiblePackageNode = (IProgramElement) iterator2.next();
List<IProgramElement> matchingPackageNodes = new ArrayList<IProgramElement>();
for (IProgramElement sourceFolder : children) {
List<IProgramElement> possiblePackageNodes = sourceFolder.getChildren();
for (IProgramElement possiblePackageNode : possiblePackageNodes) {
if (possiblePackageNode.getKind() == IProgramElement.Kind.PACKAGE) {
if (possiblePackageNode.getName().equals(searchPackageName)) {
matchingPackageNodes.add(possiblePackageNode);
@@ -236,13 +234,12 @@ public class AspectJElementHierarchy implements IHierarchy {
// thing to return in the list
if (packagename == null) {
// default package
List result = new ArrayList();
List<IProgramElement> result = new ArrayList<IProgramElement>();
result.add(root);
return result;
}
List result = new ArrayList();
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
IProgramElement possiblePackage = (IProgramElement) iterator.next();
List<IProgramElement> result = new ArrayList<IProgramElement>();
for (IProgramElement possiblePackage : children) {
if (possiblePackage.getKind() == IProgramElement.Kind.PACKAGE && possiblePackage.getName().equals(packagename)) {
result.add(possiblePackage);
}
@@ -380,8 +377,8 @@ public class AspectJElementHierarchy implements IHierarchy {
return null; // no need to search children of a source file node
} else {
// check the children
for (Iterator iterator = node.getChildren().iterator(); iterator.hasNext();) {
IProgramElement foundit = findNodeForSourceFile((IProgramElement) iterator.next(), sourcefilePath);
for (IProgramElement child : node.getChildren()) {
IProgramElement foundit = findNodeForSourceFile(child, sourcefilePath);
if (foundit != null) {
return foundit;
}
@@ -521,7 +518,7 @@ public class AspectJElementHierarchy implements IHierarchy {
// try the cache first...
IProgramElement ipe = null;
synchronized (this) {
ipe = (IProgramElement) handleMap.get(handle);
ipe = handleMap.get(handle);
if (ipe != null) {
return ipe;
}
@@ -596,7 +593,7 @@ public class AspectJElementHierarchy implements IHierarchy {
}

// TODO rename this method ... it does more than just the handle map
public void updateHandleMap(Set deletedFiles) {
public void updateHandleMap(Set<String> deletedFiles) {
// Only delete the entries we need to from the handle map - for performance reasons
List<String> forRemoval = new ArrayList<String>();
Set k = null;
@@ -604,7 +601,7 @@ public class AspectJElementHierarchy implements IHierarchy {
k = handleMap.keySet();
for (Iterator iter = k.iterator(); iter.hasNext();) {
String handle = (String) iter.next();
IProgramElement ipe = (IProgramElement) handleMap.get(handle);
IProgramElement ipe = handleMap.get(handle);
if (deletedFiles.contains(getCanonicalFilePath(ipe))) {
forRemoval.add(handle);
}
@@ -616,7 +613,7 @@ public class AspectJElementHierarchy implements IHierarchy {
k = typeMap.keySet();
for (Iterator iter = k.iterator(); iter.hasNext();) {
String typeName = (String) iter.next();
IProgramElement ipe = (IProgramElement) typeMap.get(typeName);
IProgramElement ipe = typeMap.get(typeName);
if (deletedFiles.contains(getCanonicalFilePath(ipe))) {
forRemoval.add(typeName);
}

+ 17
- 25
asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java View File

@@ -41,6 +41,10 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
this.asm = asm;
}

public void initialize() {
// nothing to do
}

public String createHandleIdentifier(IProgramElement ipe) {
// AjBuildManager.setupModel --> top of the tree is either
// <root> or the .lst file
@@ -124,7 +128,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
return "";
}
List sourceRefs = ipe.getParameterSignaturesSourceRefs();
List parameterTypes = ipe.getParameterSignatures();
List<char[]> parameterTypes = ipe.getParameterSignatures();
StringBuffer sb = new StringBuffer();
if (sourceRefs != null) {
for (int i = 0; i < sourceRefs.size(); i++) {
@@ -133,8 +137,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
sb.append(sourceRef);
}
} else {
for (Iterator iter = parameterTypes.iterator(); iter.hasNext();) {
char[] element = (char[]) iter.next();
for (char[] element : parameterTypes) {
sb.append(HandleProviderDelimiter.getDelimiter(ipe));
sb.append(NameConvertor.createShortName(element, false, false));
}
@@ -155,10 +158,9 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {

if (ipe.getKind().isInterTypeMember()) {
int count = 1;
List kids = ipe.getParent().getChildren();
int idx = 0;
for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
IProgramElement object = (IProgramElement) iterator.next();
List<IProgramElement> kids = ipe.getParent().getChildren();
for (Iterator<IProgramElement> iterator = kids.iterator(); iterator.hasNext();) {
IProgramElement object = iterator.next();
if (object.equals(ipe)) {
break;
}
@@ -182,10 +184,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
} else if (ipe.getKind().isDeclareAnnotation()) {
// look at peer declares
int count = 1;
List kids = ipe.getParent().getChildren();
int idx = 0;
for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
IProgramElement object = (IProgramElement) iterator.next();
for (IProgramElement object : ipe.getParent().getChildren()) {
if (object.equals(ipe)) {
break;
}
@@ -214,7 +213,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
} else if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) {
// Look at any peer advice
int count = 1;
List kids = ipe.getParent().getChildren();
List<IProgramElement> kids = ipe.getParent().getChildren();
String ipeSig = ipe.getBytecodeSignature();
// remove return type from the signature - it should not be included in the comparison
int idx = 0;
@@ -234,8 +233,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
}
}
}
for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
IProgramElement object = (IProgramElement) iterator.next();
for (IProgramElement object : kids) {
if (object.equals(ipe)) {
break;
}
@@ -282,7 +280,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
// return String.valueOf(++initializerCounter).toCharArray();
// Look at any peer advice
int count = 1;
List kids = ipe.getParent().getChildren();
List<IProgramElement> kids = ipe.getParent().getChildren();
String ipeSig = ipe.getBytecodeSignature();
// remove return type from the signature - it should not be included in the comparison
int idx = 0;
@@ -302,8 +300,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
}
}
}
for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
IProgramElement object = (IProgramElement) iterator.next();
for (IProgramElement object : kids) {
if (object.equals(ipe)) {
break;
}
@@ -355,11 +352,10 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
} else if (ipe.getKind() == IProgramElement.Kind.CLASS) {
// depends on previous children
int count = 1;
List kids = ipe.getParent().getChildren();
List<IProgramElement> kids = ipe.getParent().getChildren();
if (ipe.getName().endsWith("{..}")) {
// only depends on previous anonymous children, name irrelevant
for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
IProgramElement object = (IProgramElement) iterator.next();
for (IProgramElement object : kids) {
if (object.equals(ipe)) {
break;
}
@@ -379,8 +375,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
}
}
} else {
for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
IProgramElement object = (IProgramElement) iterator.next();
for (IProgramElement object : kids) {
if (object.equals(ipe)) {
break;
}
@@ -480,7 +475,4 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
return false;
}

public void initialize() {
// nop
}
}

+ 42
- 100
asm/src/org/aspectj/asm/internal/ProgramElement.java View File

@@ -1,5 +1,5 @@
/* *******************************************************************
* Copyright (c) 2003 Contributors.
* Copyright (c) 2003,2010 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
@@ -8,7 +8,7 @@
*
* Contributors:
* Mik Kersten initial implementation
* Andy Clement Extensions for better IDE representation
* Andy Clement, IBM, SpringSource Extensions for better IDE representation
* ******************************************************************/

package org.aspectj.asm.internal;
@@ -28,6 +28,7 @@ import org.aspectj.bridge.ISourceLocation;

/**
* @author Mik Kersten
* @author Andy Clement
*/
public class ProgramElement implements IProgramElement {

@@ -54,7 +55,7 @@ public class ProgramElement implements IProgramElement {
private Kind kind;
protected IProgramElement parent = null;
protected List<IProgramElement> children = Collections.emptyList();
public Map kvpairs = Collections.EMPTY_MAP;
public Map<String, Object> kvpairs = Collections.emptyMap();
protected ISourceLocation sourceLocation = null;
public int modifiers;
private String handle = null;
@@ -63,7 +64,7 @@ public class ProgramElement implements IProgramElement {
return asm;
}

/** Used during de-externalization */
/** Used during deserialization */
public ProgramElement() {
}

@@ -89,39 +90,11 @@ public class ProgramElement implements IProgramElement {
this.modifiers = modifiers;
}

// /**
// * Use to create program element nodes that correspond to source locations.
// */
// public ProgramElement(
// String name,
// Kind kind,
// int modifiers,
// //Accessibility accessibility,
// String declaringType,
// String packageName,
// String comment,
// ISourceLocation sourceLocation,
// List relations,
// List children,
// boolean member) {
//
// this(name, kind, children);
// this.sourceLocation = sourceLocation;
// this.kind = kind;
// this.modifiers = modifiers;
// setDeclaringType(declaringType);//this.declaringType = declaringType;
// //this.packageName = packageName;
// setFormalComment(comment);
// // if (comment!=null && comment.length()>0) formalComment = comment;
// if (relations!=null && relations.size()!=0) setRelations(relations);
// // this.relations = relations;
// }

public int getRawModifiers() {
return this.modifiers;
}

public List getModifiers() {
public List<IProgramElement.Modifiers> getModifiers() {
return genModifiers(this.modifiers);
}

@@ -131,9 +104,7 @@ public class ProgramElement implements IProgramElement {

public void setDeclaringType(String t) {
if (t != null && t.length() > 0) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("declaringType", t);
}
}
@@ -180,9 +151,7 @@ public class ProgramElement implements IProgramElement {
}

public void setMessage(IMessage message) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("message", message);
// this.message = message;
}
@@ -200,9 +169,7 @@ public class ProgramElement implements IProgramElement {
}

public void setRunnable(boolean value) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
if (value) {
kvpairs.put("isRunnable", "true");
} else {
@@ -222,9 +189,7 @@ public class ProgramElement implements IProgramElement {
}

public void setImplementor(boolean value) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
if (value) {
kvpairs.put("isImplementor", "true");
} else {
@@ -239,9 +204,7 @@ public class ProgramElement implements IProgramElement {
}

public void setOverrider(boolean value) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
if (value) {
kvpairs.put("isOverrider", "true");
} else {
@@ -252,14 +215,11 @@ public class ProgramElement implements IProgramElement {

public List getRelations() {
return (List) kvpairs.get("relations");
// return relations;
}

public void setRelations(List relations) {
if (relations.size() > 0) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("relations", relations);
// this.relations = relations;
}
@@ -326,14 +286,12 @@ public class ProgramElement implements IProgramElement {
}

public void setBytecodeName(String s) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("bytecodeName", s);
}

public void setBytecodeSignature(String s) {
initMap();
fixMap();
// Different kinds of format here. The one worth compressing starts with a '(':
// (La/b/c/D;Le/f/g/G;)Ljava/lang/String;
// maybe want to avoid generics initially.
@@ -359,20 +317,12 @@ public class ProgramElement implements IProgramElement {
return s;
}

private void initMap() {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
}

public String getSourceSignature() {
return (String) kvpairs.get("sourceSignature");
}

public void setSourceSignature(String string) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
// System.err.println(name+" SourceSig=>"+string);
kvpairs.put("sourceSignature", string);
// sourceSignature = string;
@@ -383,31 +333,26 @@ public class ProgramElement implements IProgramElement {
}

public void setCorrespondingType(String s) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("returnType", s);
// this.returnType = s;
}

public void setParentTypes(List ps) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
public void setParentTypes(List<String> ps) {
fixMap();
kvpairs.put("parentTypes", ps);
}

public List getParentTypes() {
return (List) (kvpairs == null ? null : kvpairs.get("parentTypes"));
@SuppressWarnings("unchecked")
public List<String> getParentTypes() {
return (List<String>) (kvpairs == null ? null : kvpairs.get("parentTypes"));
}

/**
* {@inheritDoc}
*/
public void setAnnotationType(String fullyQualifiedAnnotationType) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("annotationType", fullyQualifiedAnnotationType);
}

@@ -533,14 +478,14 @@ public class ProgramElement implements IProgramElement {
StringBuffer sb = new StringBuffer();
sb.append(name);

List ptypes = getParameterTypes();
List<char[]> ptypes = getParameterTypes();
if (ptypes != null && (!ptypes.isEmpty() || this.kind.equals(IProgramElement.Kind.METHOD))
|| this.kind.equals(IProgramElement.Kind.CONSTRUCTOR) || this.kind.equals(IProgramElement.Kind.ADVICE)
|| this.kind.equals(IProgramElement.Kind.POINTCUT) || this.kind.equals(IProgramElement.Kind.INTER_TYPE_METHOD)
|| this.kind.equals(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR)) {
sb.append('(');
for (Iterator it = ptypes.iterator(); it.hasNext();) {
char[] arg = (char[]) it.next();
for (Iterator<char[]> it = ptypes.iterator(); it.hasNext();) {
char[] arg = it.next();
if (getFullyQualifiedArgTypes) {
sb.append(arg);
} else {
@@ -637,6 +582,7 @@ public class ProgramElement implements IProgramElement {
this.handle = handle;
}

@SuppressWarnings("unchecked")
public List<String> getParameterNames() {
List<String> parameterNames = (List<String>) kvpairs.get("parameterNames");
return parameterNames;
@@ -646,9 +592,7 @@ public class ProgramElement implements IProgramElement {
if (list == null || list.size() == 0) {
return;
}
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("parameterNames", list);
// parameterNames = list;
}
@@ -666,13 +610,15 @@ public class ProgramElement implements IProgramElement {
return params;
}

@SuppressWarnings("unchecked")
public List<char[]> getParameterSignatures() {
List<char[]> parameters = (List<char[]>) kvpairs.get("parameterSigs");
return parameters;
}

public List getParameterSignaturesSourceRefs() {
List parameters = (List) kvpairs.get("parameterSigsSourceRefs");
@SuppressWarnings("unchecked")
public List<String> getParameterSignaturesSourceRefs() {
List<String> parameters = (List<String>) kvpairs.get("parameterSigsSourceRefs");
return parameters;
}

@@ -681,10 +627,8 @@ public class ProgramElement implements IProgramElement {
* the source. A singletypereference would be 'String' - whilst a qualifiedtypereference would be 'java.lang.String' - this has
* an effect on the handles.
*/
public void setParameterSignatures(List list, List sourceRefs) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
public void setParameterSignatures(List<char[]> list, List<String> sourceRefs) {
fixMap();
if (list == null || list.size() == 0) {
kvpairs.put("parameterSigs", Collections.EMPTY_LIST);
} else {
@@ -701,25 +645,25 @@ public class ProgramElement implements IProgramElement {
}

public void setDetails(String string) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("details", string);
}

public void setFormalComment(String txt) {
if (txt != null && txt.length() > 0) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("formalComment", txt);
}
}

public void setExtraInfo(ExtraInformation info) {
private void fixMap() {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
kvpairs = new HashMap<String, Object>();
}
}

public void setExtraInfo(ExtraInformation info) {
fixMap();
kvpairs.put("ExtraInformation", info);
}

@@ -733,9 +677,7 @@ public class ProgramElement implements IProgramElement {

public void setAnnotationStyleDeclaration(boolean b) {
if (b) {
if (kvpairs == Collections.EMPTY_MAP) {
kvpairs = new HashMap();
}
fixMap();
kvpairs.put("annotationStyleDeclaration", "true");
}
}

+ 10
- 27
asm/src/org/aspectj/asm/internal/RelationshipMap.java View File

@@ -19,7 +19,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.aspectj.asm.IHierarchy;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;
import org.aspectj.asm.IRelationship.Kind;
@@ -33,22 +32,9 @@ public class RelationshipMap extends HashMap<String, List<IRelationship>> implem

private static final long serialVersionUID = 496638323566589643L;

// // As this gets serialized, make the hierarchy transient and
// // settable
// private transient IHierarchy hierarchy;

public RelationshipMap() {
}

public RelationshipMap(IHierarchy hierarchy) {
// this.hierarchy = hierarchy;
}

public void setHierarchy(IHierarchy hierarchy) {
// commented out as field never read !
// this.hierarchy = hierarchy;
}

public List<IRelationship> get(String handle) {
List<IRelationship> relationships = super.get(handle);
if (relationships == null) {
@@ -124,20 +110,17 @@ public class RelationshipMap extends HashMap<String, List<IRelationship>> implem
}

public void put(String source, IRelationship relationship) {

// System.err.println(">> for: " + source + ", put::" + relationship);

List<IRelationship> list = super.get(source);
if (list == null) {
list = new ArrayList<IRelationship>();
list.add(relationship);

super.put(source, list);
List<IRelationship> existingRelationships = super.get(source);
if (existingRelationships == null) {
// new entry
existingRelationships = new ArrayList<IRelationship>();
existingRelationships.add(relationship);
super.put(source, existingRelationships);
} else {
boolean matched = false;
for (IRelationship curr : list) {
if (curr.getName().equals(relationship.getName()) && curr.getKind() == relationship.getKind()) {
curr.getTargets().addAll(relationship.getTargets());
for (IRelationship existingRelationship : existingRelationships) {
if (existingRelationship.getName().equals(relationship.getName()) && existingRelationship.getKind() == relationship.getKind()) {
existingRelationship.getTargets().addAll(relationship.getTargets());
matched = true;
}
}
@@ -146,7 +129,7 @@ public class RelationshipMap extends HashMap<String, List<IRelationship>> implem
System.err.println("matched = true");
}
if (matched) {
list.add(relationship); // Is this a bug, will it give us double entries?
existingRelationships.add(relationship); // Is this a bug, will it give us double entries?
}
}
}

Loading…
Cancel
Save