diff options
10 files changed, 167 insertions, 57 deletions
diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java index 3f3a900aa..623638b79 100644 --- a/asm/src/org/aspectj/asm/AsmManager.java +++ b/asm/src/org/aspectj/asm/AsmManager.java @@ -34,6 +34,7 @@ public class AsmManager { * @deprecated use getDefault() method instead */ private static AsmManager INSTANCE = new AsmManager(); + private IElementHandleProvider handleProvider; private boolean shouldSaveModel = true; protected IHierarchy hierarchy; private List structureListeners = new ArrayList(); @@ -44,8 +45,6 @@ public class AsmManager { public static boolean dumpModelPostBuild = false; // Dumping the model is expensive public static boolean attemptIncrementalModelRepairs = false; // for debugging ... - - // For offline debugging, you can now ask for the AsmManager to // dump the model - see the method setReporting() @@ -63,6 +62,7 @@ public class AsmManager { hierarchy = new AspectJElementHierarchy(); // List relationships = new ArrayList(); mapper = new RelationshipMap(hierarchy); + handleProvider = new FullPathHandleProvider(); } public IHierarchy getHierarchy() { @@ -159,6 +159,14 @@ public class AsmManager { } } + public IElementHandleProvider getHandleProvider() { + return handleProvider; + } + + public void setHandleProvider(IElementHandleProvider handleProvider) { + this.handleProvider = handleProvider; + } + /** * Fails silently. */ @@ -789,6 +797,7 @@ public class AsmManager { } } + /** * Set to indicate whether we are currently building a structure model, should * be set up front. diff --git a/asm/src/org/aspectj/asm/IElementHandleProvider.java b/asm/src/org/aspectj/asm/IElementHandleProvider.java new file mode 100644 index 000000000..97902abf9 --- /dev/null +++ b/asm/src/org/aspectj/asm/IElementHandleProvider.java @@ -0,0 +1,56 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Mik Kersten initial implementation + * ******************************************************************/ + +package org.aspectj.asm; + +import java.io.File; + +import org.aspectj.bridge.ISourceLocation; + +/** + * Adapter used to uniquely identify program element handles. Can be + * implemented and overridden in @see{AsmManager} in order to provide + * IDE-specific mechanisms of identifying elements. For example, AJDT + * uses workspace-relative paths that are understood by its JavaCore + * class. + * + * @author Mik Kersten + */ +public interface IElementHandleProvider { + + /** + * @return a String uniquely identifying this element + */ + public String createHandleIdentifier(ISourceLocation location); + + /** + * @return a String uniquely identifying this element + */ + public String createHandleIdentifier(File sourceFile, int line,int column,int offset); + + /** + * NOTE: this is necessary for the current implementation to look up nodes, + * but we may want to consider removing it. + * + * @return a String corresponding to the + */ + public String getFileForHandle(String handle); + + /** + * NOTE: this is necessary for the current implementation to look up nodes, + * but we may want to consider removing it. + * + * @return the line number corresponding to this handel + */ + public int getLineNumberForHandle(String handle); + +} diff --git a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java index 26bf3f4b0..cc95646cf 100644 --- a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java +++ b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java @@ -36,11 +36,13 @@ public class AspectJElementHierarchy implements IHierarchy { IProgramElement cachedEntry = (IProgramElement)handleMap.get(handle); if (cachedEntry!=null) return cachedEntry; - 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 canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file)); +// 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(); + + String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file)); IProgramElement ret = findNodeForSourceLineHelper(root,canonicalSFP, line); if (ret!=null) { handleMap.put(handle,ret); @@ -318,11 +320,14 @@ 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(); +// 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(); + ret = findElementForSourceLine(file, line); if (ret != null) { cache(handle,(ProgramElement)ret); diff --git a/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java new file mode 100644 index 000000000..0a32af207 --- /dev/null +++ b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java @@ -0,0 +1,65 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Mik Kersten initial implementation + * ******************************************************************/ + +package org.aspectj.asm.internal; + +import java.io.File; +import java.util.StringTokenizer; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IElementHandleProvider; +import org.aspectj.bridge.ISourceLocation; + +/** + * @author Mik Kersten + */ +public class FullPathHandleProvider implements IElementHandleProvider { + + static final String ID_DELIM = "|"; + + public String createHandleIdentifier(ISourceLocation location) { + StringBuffer sb = new StringBuffer(); + sb.append(AsmManager.getDefault() + .getCanonicalFilePath(location.getSourceFile())); + sb.append(ID_DELIM); + sb.append(location.getLine()); + sb.append(ID_DELIM); + sb.append(location.getColumn()); + sb.append(ID_DELIM); + sb.append(location.getOffset()); + return sb.toString(); + } + + public String createHandleIdentifier(File sourceFile, int line,int column,int offset) { + StringBuffer sb = new StringBuffer(); + sb.append(AsmManager.getDefault().getCanonicalFilePath(sourceFile)); + sb.append(ID_DELIM); + sb.append(line); + sb.append(ID_DELIM); + sb.append(column); + sb.append(ID_DELIM); + sb.append(offset); + return sb.toString(); + } + + public String getFileForHandle(String handle) { + StringTokenizer st = new StringTokenizer(handle, ID_DELIM); + String file = st.nextToken(); + return file; + } + + public int getLineNumberForHandle(String handle) { + StringTokenizer st = new StringTokenizer(handle, ID_DELIM); + st.nextToken(); // skip over the file + return new Integer(st.nextToken()).intValue(); + } +} diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java index 6bfe85115..a34a5ffa8 100644 --- a/asm/src/org/aspectj/asm/internal/ProgramElement.java +++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java @@ -31,8 +31,6 @@ import org.aspectj.bridge.ISourceLocation; */ public class ProgramElement implements IProgramElement { - static final String ID_DELIM = "|"; - protected IProgramElement parent = null; protected String name = ""; // children.listIterator() should support remove() operation @@ -447,40 +445,16 @@ public class ProgramElement implements IProgramElement { return label; } - public static String createHandleIdentifier(File sourceFile, int line,int column,int offset) { - StringBuffer sb = new StringBuffer(); - sb.append(AsmManager.getDefault().getCanonicalFilePath(sourceFile)); - sb.append(ID_DELIM); - sb.append(line); - sb.append(ID_DELIM); - sb.append(column); - sb.append(ID_DELIM); - sb.append(offset); - return sb.toString(); - } - private String handle = null; public String getHandleIdentifier() { if (null == handle) { if (sourceLocation != null) { - return genHandleIdentifier(sourceLocation); - } + return AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation); +// return genHandleIdentifier(sourceLocation); + } } return handle; } - - public static String genHandleIdentifier(ISourceLocation sourceLocation) { - StringBuffer sb = new StringBuffer(); - sb.append(AsmManager.getDefault() - .getCanonicalFilePath(sourceLocation.getSourceFile())); - sb.append(ID_DELIM); - sb.append(sourceLocation.getLine()); - sb.append(ID_DELIM); - sb.append(sourceLocation.getColumn()); - sb.append(ID_DELIM); - sb.append(sourceLocation.getOffset()); - return sb.toString(); - } public List getParameterNames() { return parameterNames; diff --git a/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java b/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java index 5ffeaa85f..f11b5bc82 100644 --- a/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java +++ b/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java @@ -59,11 +59,11 @@ class DeclareInfoProvider extends AsmRelationshipProvider { for (Iterator it = newParents.iterator(); it.hasNext();) { ResolvedTypeX superType = (ResolvedTypeX) it.next(); - String sourceHandle = ProgramElement.createHandleIdentifier( + String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( decp.getSourceFile(),decp.getLine(),decp.getColumn(), decp.getOffset()); IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle); - String superHandle = ProgramElement.createHandleIdentifier( + String superHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( superType.getSourceLocation().getSourceFile(), superType.getSourceLocation().getLine(), superType.getSourceLocation().getColumn(), diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java index 523fea5a6..ab2ce9f08 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java @@ -47,13 +47,13 @@ public class AsmInterTypeRelationshipProvider { if (munger.getSourceLocation() != null && munger.getSourceLocation() != null) { - String sourceHandle = ProgramElement.createHandleIdentifier( + String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( munger.getSourceLocation().getSourceFile(), munger.getSourceLocation().getLine(), munger.getSourceLocation().getColumn(), munger.getSourceLocation().getOffset()); - String targetHandle = ProgramElement.createHandleIdentifier( + String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( onType.getSourceLocation().getSourceFile(), onType.getSourceLocation().getLine(), onType.getSourceLocation().getColumn(), diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java index b0587d3f9..460de15f4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java @@ -369,9 +369,9 @@ public class AsmHierarchyBuilder extends ASTVisitor { ResolvedMember member = getPointcutDeclaration(rp, declaration); if (member != null) { IRelationship foreward = AsmManager.getDefault().getRelationshipMap().get(peNode.getHandleIdentifier(), IRelationship.Kind.USES_POINTCUT, "uses pointcut", false, true); - foreward.addTarget(ProgramElement.genHandleIdentifier(member.getSourceLocation())); + foreward.addTarget(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(member.getSourceLocation())); - IRelationship back = AsmManager.getDefault().getRelationshipMap().get(ProgramElement.genHandleIdentifier(member.getSourceLocation()), IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true); + IRelationship back = AsmManager.getDefault().getRelationshipMap().get(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(member.getSourceLocation()), IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true); back.addTarget(peNode.getHandleIdentifier()); } } diff --git a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java index 15b58dcb2..7a1bbba43 100644 --- a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java +++ b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java @@ -55,13 +55,13 @@ public class AsmRelationshipProvider { // Ensure a node for the target exists IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow); - String sourceHandle = ProgramElement.createHandleIdentifier( + String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( checker.getSourceLocation().getSourceFile(), checker.getSourceLocation().getLine(), checker.getSourceLocation().getColumn(), checker.getSourceLocation().getOffset()); - String targetHandle = ProgramElement.createHandleIdentifier( + String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( shadow.getSourceLocation().getSourceFile(), shadow.getSourceLocation().getLine(), shadow.getSourceLocation().getColumn(), @@ -90,13 +90,13 @@ public class AsmRelationshipProvider { if (!AsmManager.isCreatingModel()) return; String sourceHandle = ""; if (munger.getSourceLocation()!=null) { - sourceHandle = ProgramElement.createHandleIdentifier( + sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( munger.getSourceLocation().getSourceFile(), munger.getSourceLocation().getLine(), munger.getSourceLocation().getColumn(), munger.getSourceLocation().getOffset()); } else { - sourceHandle = ProgramElement.createHandleIdentifier( + sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( originatingAspect.getSourceLocation().getSourceFile(), originatingAspect.getSourceLocation().getLine(), originatingAspect.getSourceLocation().getColumn(), @@ -104,7 +104,7 @@ public class AsmRelationshipProvider { } if (originatingAspect.getSourceLocation() != null) { - String targetHandle = ProgramElement.createHandleIdentifier( + String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( onType.getSourceLocation().getSourceFile(), onType.getSourceLocation().getLine(), onType.getSourceLocation().getColumn(), @@ -126,12 +126,12 @@ public class AsmRelationshipProvider { public void addDeclareParentsRelationship(ISourceLocation decp,ResolvedTypeX targetType, List newParents) { if (!AsmManager.isCreatingModel()) return; - String sourceHandle = ProgramElement.createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn(),decp.getOffset()); + String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn(),decp.getOffset()); IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle); - String targetHandle = ProgramElement.createHandleIdentifier( + String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( targetType.getSourceLocation().getSourceFile(), targetType.getSourceLocation().getLine(), targetType.getSourceLocation().getColumn(), @@ -154,11 +154,11 @@ public class AsmRelationshipProvider { */ public void addDeclareAnnotationRelationship(ISourceLocation declareAnnotationLocation,ISourceLocation annotatedLocation) { if (!AsmManager.isCreatingModel()) return; - String sourceHandle = ProgramElement.createHandleIdentifier(declareAnnotationLocation.getSourceFile(),declareAnnotationLocation.getLine(), + String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(declareAnnotationLocation.getSourceFile(),declareAnnotationLocation.getLine(), declareAnnotationLocation.getColumn(),declareAnnotationLocation.getOffset()); IProgramElement declareAnnotationPE = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle); - String targetHandle = ProgramElement.createHandleIdentifier( + String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( annotatedLocation.getSourceFile(), annotatedLocation.getLine(), annotatedLocation.getColumn(), @@ -384,7 +384,7 @@ public class AsmRelationshipProvider { try { String sourceHandle = - ProgramElement.createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(), + AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(), sourceLocation.getColumn(),sourceLocation.getOffset()); String targetHandle = methodElem.getHandleIdentifier(); @@ -425,7 +425,7 @@ public class AsmRelationshipProvider { if (fieldElem== null) return; String sourceHandle = - ProgramElement.createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(), + AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(), sourceLocation.getColumn(),sourceLocation.getOffset()); String targetHandle = fieldElem.getHandleIdentifier(); diff --git a/weaver/src/org/aspectj/weaver/ShadowMunger.java b/weaver/src/org/aspectj/weaver/ShadowMunger.java index 9924d2e7f..9425cd6fd 100644 --- a/weaver/src/org/aspectj/weaver/ShadowMunger.java +++ b/weaver/src/org/aspectj/weaver/ShadowMunger.java @@ -15,6 +15,7 @@ package org.aspectj.weaver; import java.util.Collection; +import org.aspectj.asm.AsmManager; import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.ISourceLocation; import org.aspectj.util.PartialOrder; @@ -87,7 +88,7 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH if (null == handle) { ISourceLocation sl = getSourceLocation(); if (sl != null) { - handle = ProgramElement.createHandleIdentifier( + handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier( sl.getSourceFile(), sl.getLine(), sl.getColumn(), |