*/
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.
* 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)
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);
}
}
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) {
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,
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 {
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;
+ }
}
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 {
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;
+ }
}
}
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();
//import java.io.IOException;
import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;
import org.aspectj.asm.IRelationshipMap;
import org.aspectj.weaver.ResolvedType;
if (munger.getSourceLocation() != null
&& munger.getSourceLocation() != null) {
- String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- munger.getSourceLocation().getSourceFile(),
- munger.getSourceLocation().getLine(),
- munger.getSourceLocation().getColumn(),
- munger.getSourceLocation().getOffset());
-
- String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- onType.getSourceLocation().getSourceFile(),
- onType.getSourceLocation().getLine(),
- onType.getSourceLocation().getColumn(),
- onType.getSourceLocation().getOffset());
+ IProgramElement sourceIPE = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(munger.getSourceLocation());
+ String sourceHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(sourceIPE);
+
+ IProgramElement targetIPE = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(onType.getSourceLocation());
+ String targetHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(targetIPE);
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
ReferencePointcut rp = (ReferencePointcut) it.next();
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(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(member.getSourceLocation()));
+ IRelationship foreward = AsmManager.getDefault().getRelationshipMap()
+ .get(peNode.getHandleIdentifier(),
+ IRelationship.Kind.USES_POINTCUT, "uses pointcut", false, true);
+ IProgramElement forwardIPE = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(member.getSourceLocation());
+ foreward.addTarget(AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(forwardIPE));
- IRelationship back = AsmManager.getDefault().getRelationshipMap().get(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(member.getSourceLocation()), IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true);
+ IRelationship back = AsmManager.getDefault().getRelationshipMap()
+ .get(AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(forwardIPE),
+ IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true);
back.addTarget(peNode.getHandleIdentifier());
}
}
protected void tearDown() throws Exception {
super.tearDown();
AjState.FORCE_INCREMENTAL_DURING_TESTING = false;
+ configureBuildStructureModel(false);
}
public void build(String projectName) {
// Ensure a node for the target exists
IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow);
-
- String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- checker.getSourceLocation().getSourceFile(),
- checker.getSourceLocation().getLine(),
- checker.getSourceLocation().getColumn(),
- checker.getSourceLocation().getOffset());
-
+ IProgramElement sourceNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(checker.getSourceLocation());
+ String sourceHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(sourceNode);
+ String targetHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(targetNode);
+
if (World.createInjarHierarchy) {
checker.createHierarchy();
}
- String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- shadow.getSourceLocation().getSourceFile(),
- shadow.getSourceLocation().getLine(),
- shadow.getSourceLocation().getColumn(),
- shadow.getSourceLocation().getOffset());
-
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE, MATCHED_BY,false,true);
foreward.addTarget(targetHandle);
-// foreward.getTargets().add(targetHandle);
IRelationship back = mapper.get(targetHandle, IRelationship.Kind.DECLARE, MATCHES_DECLARE,false,true);
if (back != null && back.getTargets() != null) {
back.addTarget(sourceHandle);
- //back.getTargets().add(sourceHandle);
}
}
}
if (!AsmManager.isCreatingModel()) return;
String sourceHandle = "";
if (munger.getSourceLocation()!=null && munger.getSourceLocation().getOffset()!=-1) {
- sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- munger.getSourceLocation().getSourceFile(),
- munger.getSourceLocation().getLine(),
- munger.getSourceLocation().getColumn(),
- munger.getSourceLocation().getOffset());
+ IProgramElement sourceNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(munger.getSourceLocation());
+ sourceHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(sourceNode);
} else {
- sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- originatingAspect.getSourceLocation().getSourceFile(),
- originatingAspect.getSourceLocation().getLine(),
- originatingAspect.getSourceLocation().getColumn(),
- originatingAspect.getSourceLocation().getOffset());
+ IProgramElement sourceNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(originatingAspect.getSourceLocation());
+ sourceHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(sourceNode);
}
if (originatingAspect.getSourceLocation() != null) {
-
- String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- onType.getSourceLocation().getSourceFile(),
- onType.getSourceLocation().getLine(),
- onType.getSourceLocation().getColumn(),
- onType.getSourceLocation().getOffset());
+ IProgramElement targetNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(onType.getSourceLocation());
+ String targetHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(targetNode);
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
public void addDeclareParentsRelationship(ISourceLocation decp,ResolvedType targetType, List newParents) {
if (!AsmManager.isCreatingModel()) return;
- String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn(),decp.getOffset());
-
- IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle);
+ IProgramElement sourceNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(decp);
+ String sourceHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(sourceNode);
+ IProgramElement targetNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(targetType.getSourceLocation());
+ String targetHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(targetNode);
-
- String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- targetType.getSourceLocation().getSourceFile(),
- targetType.getSourceLocation().getLine(),
- targetType.getSourceLocation().getColumn(),
- targetType.getSourceLocation().getOffset());
-
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARES,false,true);
*/
public void addDeclareAnnotationRelationship(ISourceLocation declareAnnotationLocation,ISourceLocation annotatedLocation) {
if (!AsmManager.isCreatingModel()) return;
- String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(declareAnnotationLocation.getSourceFile(),declareAnnotationLocation.getLine(),
- declareAnnotationLocation.getColumn(),declareAnnotationLocation.getOffset());
- IProgramElement declareAnnotationPE = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle);
-
- String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- annotatedLocation.getSourceFile(),
- annotatedLocation.getLine(),
- annotatedLocation.getColumn(),
- annotatedLocation.getOffset());
+
+ IProgramElement sourceNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(declareAnnotationLocation);
+ String sourceHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(sourceNode);
+
+ IProgramElement targetNode = AsmManager.getDefault().getHierarchy()
+ .findElementForSourceLine(annotatedLocation);
+ String targetHandle = AsmManager.getDefault().getHandleProvider()
+ .createHandleIdentifier(targetNode);
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
AdviceKind ak = ((Advice)munger).getKind();
ai.setExtraAdviceInformation(ak.getName());
IProgramElement adviceElement = AsmManager.getDefault().getHierarchy().findElementForHandle(adviceHandle);
- adviceElement.setExtraInfo(ai);
+ if (adviceElement != null) {
+ adviceElement.setExtraInfo(ai);
+ }
if (adviceHandle != null && targetNode != null) {
if (methodElem == null) return;
try {
- String sourceHandle =
- AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(),
- sourceLocation.getColumn(),sourceLocation.getOffset());
+
+ IProgramElement sourceNode = AsmManager.getDefault().getHierarchy().findElementForSourceLine(sourceLocation);
+ String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceNode);
String targetHandle = methodElem.getHandleIdentifier();
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
IProgramElement fieldElem = AsmManager.getDefault().getHierarchy().findElementForSignature(typeElem,IProgramElement.Kind.FIELD,field.getName());
if (fieldElem== null) return;
- String sourceHandle =
- AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(),
- sourceLocation.getColumn(),sourceLocation.getOffset());
+ IProgramElement sourceNode = AsmManager.getDefault().getHierarchy().findElementForSourceLine(sourceLocation);
+ String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceNode);
String targetHandle = fieldElem.getHandleIdentifier();
if (World.createInjarHierarchy) {
createHierarchy();
}
- handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
- sl.getSourceFile(),
- sl.getLine(),
- sl.getColumn(),
- sl.getOffset());
+ IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForSourceLine(sl);
+ handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(ipe);
}
}
return handle;