diff options
author | aclement <aclement> | 2006-06-13 13:23:14 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-06-13 13:23:14 +0000 |
commit | f58b5d89371ed4454e65dbbca54032db4039151a (patch) | |
tree | 6c927ba696194b367aed96ddaa7e7f098a5c3958 /asm/src | |
parent | b8e83b78c412178f79f3d2fa9e1fcecfb0c033aa (diff) | |
download | aspectj-f58b5d89371ed4454e65dbbca54032db4039151a.tar.gz aspectj-f58b5d89371ed4454e65dbbca54032db4039151a.zip |
141730: underpinning changes for new handles support. No longer 'leak' implementation details of the handles out into the rest of the code.
Diffstat (limited to 'asm/src')
6 files changed, 75 insertions, 40 deletions
diff --git a/asm/src/org/aspectj/asm/IElementHandleProvider.java b/asm/src/org/aspectj/asm/IElementHandleProvider.java index d88799b62..3e5ef9570 100644 --- a/asm/src/org/aspectj/asm/IElementHandleProvider.java +++ b/asm/src/org/aspectj/asm/IElementHandleProvider.java @@ -38,6 +38,11 @@ public interface IElementHandleProvider { public String createHandleIdentifier(File sourceFile, int line,int column,int offset); /** + * @return a String uniquely identifying this element + */ + public String createHandleIdentifier(IProgramElement ipe); + + /** * NOTE: this is necessary for the current implementation to look up nodes, * but we may want to consider removing it. * diff --git a/asm/src/org/aspectj/asm/IProgramElement.java b/asm/src/org/aspectj/asm/IProgramElement.java index f88c2dbba..6fbc15b09 100644 --- a/asm/src/org/aspectj/asm/IProgramElement.java +++ b/asm/src/org/aspectj/asm/IProgramElement.java @@ -127,9 +127,11 @@ public interface IProgramElement extends Serializable { * The format of the string handle is not specified, but is stable across * compilation sessions. * - * @return a string representtaion of this element + * @return a string representation of this element */ public String getHandleIdentifier(); + public String getHandleIdentifier(boolean create); + public void setHandleIdentifier(String handle); /** * @return a string representation of this node and all of its children (recursive) diff --git a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java index 8260c4805..8c525b083 100644 --- a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java +++ b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java @@ -37,16 +37,7 @@ public class AspectJElementHierarchy implements IHierarchy { public IProgramElement getElement(String handle) { IProgramElement cachedEntry = (IProgramElement)handleMap.get(handle); if (cachedEntry!=null) return cachedEntry; - -// StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM); -// int line = new Integer(st.nextToken()).intValue(); - // int col = new Integer(st.nextToken()).intValue(); TODO: use column number when available - String file = AsmManager.getDefault().getHandleProvider().getFileForHandle(handle); // st.nextToken(); - int line = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(handle); // st.nextToken(); - int offSet = AsmManager.getDefault().getHandleProvider().getOffSetForHandle(handle); - - String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file)); - IProgramElement ret = findNodeForSourceLineHelper(root,canonicalSFP, line, offSet); + IProgramElement ret = findElementForHandle(handle); if (ret!=null) { cache(handle,ret); } @@ -68,7 +59,10 @@ public class AspectJElementHierarchy implements IHierarchy { } public boolean removeFromFileMap(Object key) { - return (fileMap.remove(key)!=null); + if (fileMap.containsKey(key)) { + return (fileMap.remove(key)!=null); + } + return true; } public void setFileMap(HashMap fileMap) { @@ -344,30 +338,26 @@ public class AspectJElementHierarchy implements IHierarchy { IProgramElement ret = (IProgramElement) handleMap.get(handle); if (ret != null) return ret; -// StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM); -// String file = st.nextToken(); -// int line = new Integer(st.nextToken()).intValue(); -// int col = new Integer(st.nextToken()).intValue(); - // TODO: use column number when available - String file = AsmManager.getDefault().getHandleProvider().getFileForHandle(handle); // st.nextToken(); - int line = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(handle); // st.nextToken(); - int offSet = AsmManager.getDefault().getHandleProvider().getOffSetForHandle(handle); - - ret = findElementForOffSet(file, line, offSet); - if (ret != null) { + ret = findElementForHandle(root,handle); + if (ret != null) { cache(handle,(ProgramElement)ret); } return ret; - -// IProgramElement parent = findElementForType(packageName, typeName); -// if (parent == null) return null; -// if (kind == IProgramElement.Kind.CLASS || -// kind == IProgramElement.Kind.ASPECT) { -// return parent; -// } else { -// return findElementForSignature(parent, kind, name); -// } } + + private IProgramElement findElementForHandle(IProgramElement parent, String handle) { + for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) { + IProgramElement node = (IProgramElement)it.next(); + if (handle.equals(node.getHandleIdentifier())) { + return node; + } else { + IProgramElement childSearch = findElementForHandle(node,handle); + if (childSearch != null) return childSearch; + } + } + return null; + } + // // private IProgramElement findElementForBytecodeInfo( // IProgramElement node, diff --git a/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java index d58834ae3..6ab254d45 100644 --- a/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java +++ b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java @@ -17,9 +17,12 @@ import java.util.StringTokenizer; import org.aspectj.asm.AsmManager; import org.aspectj.asm.IElementHandleProvider; +import org.aspectj.asm.IProgramElement; import org.aspectj.bridge.ISourceLocation; /** + * HandleProvider of the form '<full path to src file>|line|column|offset' + * * @author Mik Kersten */ public class FullPathHandleProvider implements IElementHandleProvider { @@ -70,4 +73,18 @@ public class FullPathHandleProvider implements IElementHandleProvider { st.nextToken(); // skip over the column return new Integer(st.nextToken()).intValue(); } + + public String createHandleIdentifier(IProgramElement ipe) { + if (ipe.getHandleIdentifier(false) != null) { + return ipe.getHandleIdentifier(false); + } + String handle = null; + if (ipe.getSourceLocation() != null) { + handle = createHandleIdentifier(ipe.getSourceLocation()); + } else { + handle = createHandleIdentifier(ISourceLocation.NO_FILE,-1,-1,-1); + } + ipe.setHandleIdentifier(handle); + return handle; + } } diff --git a/asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java b/asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java index 39013169d..e7b364241 100644 --- a/asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java +++ b/asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java @@ -21,10 +21,11 @@ import java.util.StringTokenizer; import org.aspectj.asm.AsmManager; import org.aspectj.asm.IElementHandleProvider; +import org.aspectj.asm.IProgramElement; import org.aspectj.bridge.ISourceLocation; /** - * Not currently used - uses int keys rather than the full file path as the first part of the handle. + * Uses int keys rather than the full file path as the first part of the handle. */ public class OptimizedFullPathHandleProvider implements IElementHandleProvider { @@ -96,4 +97,18 @@ public class OptimizedFullPathHandleProvider implements IElementHandleProvider { st.nextToken(); // skip over the column return new Integer(st.nextToken()).intValue(); } + + public String createHandleIdentifier(IProgramElement ipe) { + if (ipe.getHandleIdentifier(false) != null) { + return ipe.getHandleIdentifier(false); + } + String handle = null; + if (ipe.getSourceLocation() != null) { + handle = createHandleIdentifier(ipe.getSourceLocation()); + } else { + handle = createHandleIdentifier(ISourceLocation.NO_FILE,-1,-1,-1); + } + ipe.setHandleIdentifier(handle); + return handle; + } } diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java index af5a16960..7bf2b3e44 100644 --- a/asm/src/org/aspectj/asm/internal/ProgramElement.java +++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java @@ -493,19 +493,25 @@ public class ProgramElement implements IProgramElement { } public String getHandleIdentifier() { - if (null == handle) { - if (sourceLocation != null) { - handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation); -// return genHandleIdentifier(sourceLocation); - } - } - return handle; + return getHandleIdentifier(true); + } + + public String getHandleIdentifier(boolean create) { + if (null == handle && create) { + handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(this); + } + return handle; + } + + public void setHandleIdentifier(String handle) { + this.handle = handle; } public List getParameterNames() { List parameterNames = (List)kvpairs.get("parameterNames"); return parameterNames; } + public void setParameterNames(List list) { if (list==null || list.size()==0) return; if (kvpairs==Collections.EMPTY_MAP) kvpairs = new HashMap(); |