* @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();
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()
hierarchy = new AspectJElementHierarchy();
// List relationships = new ArrayList();
mapper = new RelationshipMap(hierarchy);
+ handleProvider = new FullPathHandleProvider();
}
public IHierarchy getHierarchy() {
}
}
+ public IElementHandleProvider getHandleProvider() {
+ return handleProvider;
+ }
+
+ public void setHandleProvider(IElementHandleProvider handleProvider) {
+ this.handleProvider = handleProvider;
+ }
+
/**
* Fails silently.
*/
}
}
+
/**
* Set to indicate whether we are currently building a structure model, should
* be set up front.
--- /dev/null
+/* *******************************************************************
+ * 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);
+
+}
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);
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);
--- /dev/null
+/* *******************************************************************
+ * 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();
+ }
+}
*/
public class ProgramElement implements IProgramElement {
- static final String ID_DELIM = "|";
-
protected IProgramElement parent = null;
protected String name = "";
// children.listIterator() should support remove() operation
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;
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(),
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(),
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());
}
}
// 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(),
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(),
}
if (originatingAspect.getSourceLocation() != null) {
- String targetHandle = ProgramElement.createHandleIdentifier(
+ String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
onType.getSourceLocation().getSourceFile(),
onType.getSourceLocation().getLine(),
onType.getSourceLocation().getColumn(),
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(),
*/
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(),
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();
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();
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;
if (null == handle) {
ISourceLocation sl = getSourceLocation();
if (sl != null) {
- handle = ProgramElement.createHandleIdentifier(
+ handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
sl.getSourceFile(),
sl.getLine(),
sl.getColumn(),