import org.aspectj.bridge.ISourceLocation;
/**
- * The Abstract Structure Model (ASM) represents the containment hierarchy and crossccutting structure map for AspectJ programs. It
+ * The Abstract Structure Model (ASM) represents the containment hierarchy and crosscutting structure map for AspectJ programs. It
* is used by IDE views such as the document outline, and by other tools such as ajdoc to show both AspectJ declarations and
* crosscutting links, such as which advice affects which join point shadows.
*
* @author Mik Kersten
+ * @author Andy Clement
*/
public class AsmManager {
- private static AsmManager instance = new AsmManager();
+ // For testing ONLY
+ public static boolean recordingLastActiveStructureModel = true;
+ public static AsmManager lastActiveStructureModel;
+ public static boolean forceSingletonBehaviour = false;
+
+ // SECRETAPI asc pull the secret options together into a system API you lazy fool
+ public static boolean attemptIncrementalModelRepairs = false;
+ // Dumping the model is expensive
+ public static boolean dumpModelPostBuild = false;
+ // For offline debugging, you can now ask for the AsmManager to
+ // dump the model - see the method setReporting()
+ private static boolean dumpModel = false;
+ private static boolean dumpRelationships = false;
+ private static boolean dumpDeltaProcessing = false;
+ private static IModelFilter modelFilter = null;
+ private static String dumpFilename = "";
+ private static boolean reporting = false;
+
+ private static boolean completingTypeBindings = false;
- private IElementHandleProvider handleProvider;
private final List structureListeners = new ArrayList();
// The model is 'manipulated' by the AjBuildManager.setupModel() code which
// between projects.
protected IHierarchy hierarchy;
private IRelationshipMap mapper;
+ private IElementHandleProvider handleProvider;
- private static boolean creatingModel = false;
- public static boolean dumpModelPostBuild = false; // Dumping the model is
- // expensive
- // SECRETAPI asc pull the secret options together into a system API you lazy
- // fool
- public static boolean attemptIncrementalModelRepairs = false;
-
- // For offline debugging, you can now ask for the AsmManager to
- // dump the model - see the method setReporting()
- private static boolean dumpModel = false;
- private static boolean dumpRelationships = false;
- private static boolean dumpDeltaProcessing = false;
- private static IModelFilter modelFilter = null;
- private static String dumpFilename = "";
- private static boolean reporting = false;
-
- private static boolean completingTypeBindings = false;
private final CanonicalFilePathMap canonicalFilePathMap = new CanonicalFilePathMap();
// Record the Set<File> for which the model has been modified during the
// last incremental build
// setReporting("c:/model.nfo",true,true,true,true);
// }
- protected AsmManager() {
- handleProvider = new JDTLikeHandleProvider();
- createNewASM();
+ private AsmManager() {
}
- public void createNewASM() {
- hierarchy = new AspectJElementHierarchy();
- mapper = new RelationshipMap(hierarchy);
+ public static AsmManager createNewStructureModel() {
+ if (forceSingletonBehaviour && lastActiveStructureModel != null) {
+ return lastActiveStructureModel;
+ }
+ AsmManager asm = new AsmManager();
+ asm.hierarchy = new AspectJElementHierarchy(asm);
+ asm.mapper = new RelationshipMap(asm.hierarchy);
+ 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
- handleProvider.initialize();
- resetDeltaProcessing();
+ asm.handleProvider.initialize();
+ asm.resetDeltaProcessing();
+ setLastActiveStructureModel(asm);
+ return asm;
}
public IHierarchy getHierarchy() {
return hierarchy;
}
- public static AsmManager getDefault() {
- return instance;
- }
public IRelationshipMap getRelationshipMap() {
return mapper;
return;
for (Iterator it = children.iterator(); it.hasNext();) {
IProgramElement next = (IProgramElement) it.next();
- List rels = AsmManager.getDefault().getRelationshipMap().get(next);
+ List rels = mapper.get(next);
if (next != null
&& ((next.getKind() == IProgramElement.Kind.CODE && showSubMember) || (next.getKind() != IProgramElement.Kind.CODE && showMemberAndType))
&& rels != null && rels.size() > 0) {
FileInputStream in = new FileInputStream(filePath);
ObjectInputStream s = new ObjectInputStream(in);
hierarchy = (AspectJElementHierarchy) s.readObject();
+ ((AspectJElementHierarchy) hierarchy).setAsmManager(this);
hierarchyReadOK = true;
mapper = (RelationshipMap) s.readObject();
((RelationshipMap) mapper).setHierarchy(hierarchy);
BufferedWriter bw = new BufferedWriter(fw);
if (dumpModel) {
bw.write("=== MODEL STATUS REPORT ========= " + reasonForReport + "\n");
- dumptree(bw, AsmManager.getDefault().getHierarchy().getRoot(), 0);
+ dumptree(bw, hierarchy.getRoot(), 0);
bw.write("=== END OF MODEL REPORT =========\n");
}
dumprels(bw);
bw.write("=== END OF RELATIONSHIPS REPORT ==\n");
}
- Properties p = ModelInfo.summarizeModel().getProperties();
+ Properties p = summarizeModel().getProperties();
Enumeration pkeyenum = p.keys();
bw.write("=== Properties of the model and relationships map =====\n");
while (pkeyenum.hasMoreElements()) {
}
public void dumprels(Writer w) throws IOException {
- IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
int ctr = 1;
- Set entries = irm.getEntries();
+ Set entries = mapper.getEntries();
for (Iterator iter = entries.iterator(); iter.hasNext();) {
String hid = (String) iter.next();
- List rels = irm.get(hid);
+ List rels = mapper.get(hid);
for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
IRelationship ir = (IRelationship) iterator.next();
List targets = ir.getTargets();
private void dumprelsStderr(String key) {
System.err.println("Relationships dump follows: " + key);
- IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
int ctr = 1;
- Set entries = irm.getEntries();
+ Set entries = mapper.getEntries();
for (Iterator iter = entries.iterator(); iter.hasNext();) {
String hid = (String) iter.next();
- List rels = irm.get(hid);
+ List rels = mapper.get(hid);
for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
IRelationship ir = (IRelationship) iterator.next();
List targets = ir.getTargets();
*/
public boolean removeStructureModelForFiles(Writer fw, Collection files) throws IOException {
- IHierarchy model = AsmManager.getDefault().getHierarchy();
-
boolean modelModified = false;
Set deletedNodes = new HashSet();
for (Iterator iter = files.iterator(); iter.hasNext();) {
File fileForCompilation = (File) iter.next();
- String correctedPath = AsmManager.getDefault().getCanonicalFilePath(fileForCompilation);
- IProgramElement progElem = (IProgramElement) model.findInFileMap(correctedPath);
+ String correctedPath = getCanonicalFilePath(fileForCompilation);
+ IProgramElement progElem = (IProgramElement) hierarchy.findInFileMap(correctedPath);
if (progElem != null) {
// Found it, let's remove it
if (dumpDeltaProcessing) {
removeNode(progElem);
lastBuildChanges.add(fileForCompilation);
deletedNodes.add(getCanonicalFilePath(progElem.getSourceLocation().getSourceFile()));
- if (!model.removeFromFileMap(correctedPath))
+ if (!hierarchy.removeFromFileMap(correctedPath))
throw new RuntimeException("Whilst repairing model, couldn't remove entry for file: " + correctedPath
+ " from the filemap");
modelModified = true;
}
}
- if (modelModified)
- model.updateHandleMap(deletedNodes);
+ if (modelModified) {
+ hierarchy.updateHandleMap(deletedNodes);
+ }
return modelModified;
}
// config.getFiles())
// List files = config.getFiles();
- IHierarchy model = AsmManager.getDefault().getHierarchy();
boolean modelModified = false;
// Files to delete are: those to be compiled + those that have been
Set deletedNodes = new HashSet();
for (Iterator iter = filesToRemoveFromStructureModel.iterator(); iter.hasNext();) {
File fileForCompilation = (File) iter.next();
- String correctedPath = AsmManager.getDefault().getCanonicalFilePath(fileForCompilation);
- IProgramElement progElem = (IProgramElement) model.findInFileMap(correctedPath);
+ String correctedPath = getCanonicalFilePath(fileForCompilation);
+ IProgramElement progElem = (IProgramElement) hierarchy.findInFileMap(correctedPath);
if (progElem != null) {
// Found it, let's remove it
if (dumpDeltaProcessing) {
}
removeNode(progElem);
deletedNodes.add(getCanonicalFilePath(progElem.getSourceLocation().getSourceFile()));
- if (!model.removeFromFileMap(correctedPath))
+ if (!hierarchy.removeFromFileMap(correctedPath))
throw new RuntimeException("Whilst repairing model, couldn't remove entry for file: " + correctedPath
+ " from the filemap");
modelModified = true;
}
}
if (modelModified) {
- model.flushTypeMap();
- model.updateHandleMap(deletedNodes);
+ hierarchy.flushTypeMap();
+ hierarchy.updateHandleMap(deletedNodes);
}
}
*/
private void repairRelationships(Writer fw) {
try {
- IHierarchy model = AsmManager.getDefault().getHierarchy();
+ // IHierarchy model = AsmManager.getDefault().getHierarchy();
// TODO Speed this code up by making this assumption:
// the only piece of the handle that is interesting is the file
// name. We are working at file granularity, if the
fw.write("Repairing relationships map:\n");
// Now sort out the relationships map
- IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
+ // IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
Set sourcesToRemove = new HashSet();
Set nonExistingHandles = new HashSet(); // Cache of handles that we
// *know* are invalid
int tgthandlecounter = 0;
// Iterate over the source handles in the relationships map
- Set keyset = irm.getEntries(); // These are source handles
+ Set keyset = mapper.getEntries(); // These are source handles
for (Iterator keyiter = keyset.iterator(); keyiter.hasNext();) {
String hid = (String) keyiter.next();
srchandlecounter++;
sourcesToRemove.add(hid);
} else {
// We better check if it actually exists
- IProgramElement existingElement = model.getElement(hid);
+ IProgramElement existingElement = hierarchy.getElement(hid);
if (dumpDeltaProcessing)
fw.write("Looking for handle [" + hid + "] in model, found: " + existingElement + "\n");
nonExistingHandles.add(hid); // Speed up a bit you swine
} else {
// Ok, so the source is valid, what about the targets?
- List relationships = irm.get(hid);
+ List relationships = mapper.get(hid);
List relationshipsToRemove = new ArrayList();
// Iterate through the relationships against this source
// handle
targetsToRemove.add(targethid);
} else {
// We better check
- IProgramElement existingTarget = model.getElement(targethid);
+ IProgramElement existingTarget = hierarchy.getElement(targethid);
if (existingTarget == null) {
if (dumpDeltaProcessing)
fw.write("Target handle [" + targethid + "] for srchid[" + hid + "]rel["
// relationships !!
for (int i = 0; i < relationshipsToRemove.size(); i++) {
IRelationship irel = (IRelationship) relationshipsToRemove.get(i);
- verifyAssumption(irm.remove(hid, irel), "Failed to remove relationship " + irel.getName()
+ verifyAssumption(mapper.remove(hid, irel), "Failed to remove relationship " + irel.getName()
+ " for shid " + hid);
}
- List rels = irm.get(hid);
+ List rels = mapper.get(hid);
if (rels == null || rels.size() == 0)
sourcesToRemove.add(hid);
}
// Remove sources that have no valid relationships any more
for (Iterator srciter = sourcesToRemove.iterator(); srciter.hasNext();) {
String hid = (String) srciter.next();
- irm.removeAll(hid);
- IProgramElement ipe = model.getElement(hid);
+ mapper.removeAll(hid);
+ IProgramElement ipe = hierarchy.getElement(hid);
if (ipe != null) {
// If the relationship was hanging off a 'code' node, delete
// it.
/**
* A ModelInfo object captures basic information about the structure model. It is used for testing and producing debug info.
*/
- public static class ModelInfo {
+ public class ModelInfo {
private final Hashtable nodeTypeCount = new Hashtable();
private final Properties extraProperties = new Properties();
extraProperties.setProperty(string, string2);
}
- public static ModelInfo summarizeModel() {
- return new ModelInfo(AsmManager.getDefault().getHierarchy(), AsmManager.getDefault().getRelationshipMap());
- }
}
- /**
- * Set to indicate whether we are currently building a structure model, should be set up front.
- */
- public static void setCreatingModel(boolean b) {
- creatingModel = b;
+ public ModelInfo summarizeModel() {
+ return new ModelInfo(getHierarchy(), getRelationshipMap());
}
/**
- * returns true if we are currently generating a structure model, enables guarding of expensive operations on an empty/null
- * model.
+ * Set to indicate whether we are currently building a structure model, should be set up front.
*/
- public static boolean isCreatingModel() {
- return creatingModel;
- }
-
+ // public static void setCreatingModel(boolean b) {
+ // creatingModel = b;
+ // }
+ //
+ // /**
+ // * returns true if we are currently generating a structure model, enables guarding of expensive operations on an empty/null
+ // * model.
+ // */
+ // public static boolean isCreatingModel() {
+ // return creatingModel;
+ // }
public static void setCompletingTypeBindings(boolean b) {
completingTypeBindings = b;
}
return completingTypeBindings;
}
- public void setRelationshipMap(IRelationshipMap irm) {
- mapper = irm;
- }
-
- public void setHierarchy(IHierarchy ih) {
- hierarchy = ih;
- }
+ // public void setRelationshipMap(IRelationshipMap irm) {
+ // mapper = irm;
+ // }
+ //
+ // public void setHierarchy(IHierarchy ih) {
+ // hierarchy = ih;
+ // }
public void resetDeltaProcessing() {
lastBuildChanges.clear();
aspectsWeavingInLastBuild.add(f);
}
+ public static void setLastActiveStructureModel(AsmManager structureModel) {
+ if (recordingLastActiveStructureModel) {
+ lastActiveStructureModel = structureModel;
+ }
+ }
+
}
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.
+ * 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(ISourceLocation location);
- /**
- * @return a String uniquely identifying this element
- */
- public String createHandleIdentifier(File sourceFile, int line,int column,int offset);
+ /**
+ * @return a String uniquely identifying this element
+ */
+ public String createHandleIdentifier(File sourceFile, int line, int column, int offset);
- /**
- * @return a String uniquely identifying this element
- */
+ /**
+ * @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.
- *
- * @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);
-
- public int getOffSetForHandle(String handle);
-
- // See pr134471
- /**
- * @return true if the handles produced by the provider
- * depend on ISourceLocations and false otherwise
- */
- public boolean dependsOnLocation();
-
- /**
- * Initializes handle provider state.
- *
- * The initializer is invoked when a new ASM is
- * created on a full build.
- */
- public void initialize();
+
+ /**
+ * 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);
+
+ public int getOffSetForHandle(String handle);
+
+ /**
+ * Initializes handle provider state.
+ *
+ * The initializer is invoked when a new ASM is created on a full build.
+ */
+ public void initialize();
}
package org.aspectj.asm;
import java.io.Serializable;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Set;
import org.aspectj.asm.internal.ProgramElement;
import org.aspectj.bridge.ISourceLocation;
* @author Mik Kersten
*/
public interface IHierarchy extends Serializable {
- public static final IProgramElement NO_STRUCTURE =
- new ProgramElement(
- "<build to view structure>",
- IProgramElement.Kind.ERROR,
- null);
+ public static final IProgramElement NO_STRUCTURE = new ProgramElement(null, "<build to view structure>",
+ IProgramElement.Kind.ERROR, null);
public IProgramElement getElement(String handle);
+
public IProgramElement getRoot();
+
public void setRoot(IProgramElement root);
+
public void addToFileMap(Object key, Object value);
+
public boolean removeFromFileMap(Object key);
+
public void setFileMap(HashMap fileMap);
+
public Object findInFileMap(Object key);
+
public Set getFileMapEntrySet();
+
public boolean isValid();
/**
- * @return null if not found
+ * @return null if not found
*/
public IProgramElement findElementForHandle(String handle);
- /**
+ /**
* Returns the first match
*
* @param parent
- * @param kind not null
+ * @param kind not null
* @return null if not found
*/
- public IProgramElement findElementForSignature(
- IProgramElement parent,
- IProgramElement.Kind kind,
- String signature);
+ public IProgramElement findElementForSignature(IProgramElement parent, IProgramElement.Kind kind, String signature);
- /**
+ /**
* Returns the first match
*
* @param parent
- * @param kind not null
+ * @param kind not null
* @return null if not found
*/
- public IProgramElement findElementForLabel(
- IProgramElement parent,
- IProgramElement.Kind kind,
- String label);
+ public IProgramElement findElementForLabel(IProgramElement parent, IProgramElement.Kind kind, String label);
/**
- * @param packageName if null default package is searched
- * @param className can't be null
+ * @param packageName if null default package is searched
+ * @param className can't be null
*/
public IProgramElement findElementForType(String packageName, String typeName);
-
+
/**
- * @param sourceFilePath modified to '/' delimited path for consistency
- * @return a new structure node for the file if it was not found in the model
+ * @param sourceFilePath modified to '/' delimited path for consistency
+ * @return a new structure node for the file if it was not found in the model
*/
public IProgramElement findElementForSourceFile(String sourceFile);
-
+
/**
* TODO: discriminate columns
*/
public IProgramElement findElementForSourceLine(ISourceLocation location);
-
+
/**
- * Never returns null
+ * Never returns null
*
- * @param sourceFilePath canonicalized path for consistency
- * @param lineNumber if 0 or 1 the corresponding file node will be returned
- * @return a new structure node for the file if it was not found in the model
+ * @param sourceFilePath canonicalized path for consistency
+ * @param lineNumber if 0 or 1 the corresponding file node will be returned
+ * @return a new structure node for the file if it was not found in the model
*/
public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber);
+
public IProgramElement findElementForOffSet(String sourceFilePath, int lineNumber, int offSet);
-
+
public String getConfigFile();
-
+
public void setConfigFile(String configFile);
public void flushTypeMap();
public IProgramElement walk(HierarchyWalker walker);
+ public AsmManager getModel();
+
/**
* Uses "typesafe enum" pattern.
*/
private static final long serialVersionUID = 6462734311117048620L;
+ private transient AsmManager asm;
protected IProgramElement root = null;
protected String configFile = null;
private Map fileMap = null;
- private Map handleMap = null;
+ private Map handleMap = new HashMap();
private Map typeMap = null;
+ public AspectJElementHierarchy(AsmManager asm) {
+ this.asm = asm;
+ }
+
public IProgramElement getElement(String handle) {
return findElementForHandleOrCreate(handle, false);
}
+ public void setAsmManager(AsmManager asm) { // used when deserializing
+ this.asm = asm;
+ }
+
public IProgramElement getRoot() {
return root;
}
if (!isValid() || sourceFile == null) {
return IHierarchy.NO_STRUCTURE;
} else {
- String correctedPath = AsmManager.getDefault().getCanonicalFilePath(new File(sourceFile));
+ String correctedPath = asm.getCanonicalFilePath(new File(sourceFile));
// StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model);
IProgramElement node = (IProgramElement) findInFileMap(correctedPath);// findFileNode(filePath, model);
if (node != null) {
*/
public IProgramElement findElementForSourceLine(ISourceLocation location) {
try {
- return findElementForSourceLine(AsmManager.getDefault().getCanonicalFilePath(location.getSourceFile()), location
- .getLine());
+ return findElementForSourceLine(asm.getCanonicalFilePath(location.getSourceFile()), location.getLine());
} catch (Exception e) {
return null;
}
* @return a new structure node for the file if it was not found in the model
*/
public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber) {
- String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(sourceFilePath));
+ String canonicalSFP = asm.getCanonicalFilePath(new File(sourceFilePath));
IProgramElement node = findNodeForSourceLineHelper(root, canonicalSFP, lineNumber, -1);
if (node != null) {
return node;
}
public IProgramElement findElementForOffSet(String sourceFilePath, int lineNumber, int offSet) {
- String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(sourceFilePath));
+ String canonicalSFP = asm.getCanonicalFilePath(new File(sourceFilePath));
IProgramElement node = findNodeForSourceLineHelper(root, canonicalSFP, lineNumber, offSet);
if (node != null) {
return node;
lastSlash = i;
}
String fileName = sourceFilePath.substring(lastSlash + 1);
- IProgramElement fileNode = new ProgramElement(fileName, IProgramElement.Kind.FILE_JAVA, new SourceLocation(new File(
+ IProgramElement fileNode = new ProgramElement(asm, fileName, IProgramElement.Kind.FILE_JAVA, new SourceLocation(new File(
sourceFilePath), 1, 1), 0, null, null);
// fileNode.setSourceLocation();
fileNode.addChild(NO_STRUCTURE);
}
private String getFilename(String hid) {
- return AsmManager.getDefault().getHandleProvider().getFileForHandle(hid);
+ return asm.getHandleProvider().getFileForHandle(hid);
}
private String getCanonicalFilePath(IProgramElement ipe) {
if (ipe.getSourceLocation() != null) {
- return AsmManager.getDefault().getCanonicalFilePath(ipe.getSourceLocation().getSourceFile());
+ return asm.getCanonicalFilePath(ipe.getSourceLocation().getSourceFile());
}
return "";
}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2003 Contributors.
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-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.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 {
-
- 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 int getOffSetForHandle(String handle) {
- StringTokenizer st = new StringTokenizer(handle, ID_DELIM);
- st.nextToken(); // skip over the file
- st.nextToken(); // skip over the line number
- st.nextToken(); // skip over the column
- return new Integer(st.nextToken()).intValue();
- }
-
- public String createHandleIdentifier(IProgramElement ipe) {
- if (ipe == null) return null;
- 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 boolean dependsOnLocation() {
- // handles contain information from the source location therefore
- // return true;
- return true;
- }
-
- public void initialize() {
- // nothing to initialize...
- }
-}
*/
public class JDTLikeHandleProvider implements IElementHandleProvider {
+ private final AsmManager asm;
+
// Need to keep our own count of the number of initializers
// because this information cannot be gained from the ipe.
private int initializerCounter = 0;
private final String backslash = "\\";
private final String emptyString = "";
+ public JDTLikeHandleProvider(AsmManager asm) {
+ this.asm = asm;
+ }
+
public String createHandleIdentifier(IProgramElement ipe) {
// AjBuildManager.setupModel --> top of the tree is either
// therefore just return it
return ipe.getHandleIdentifier();
} else if (ipe.getKind().equals(IProgramElement.Kind.FILE_LST)) {
- String configFile = AsmManager.getDefault().getHierarchy().getConfigFile();
+ String configFile = asm.getHierarchy().getConfigFile();
int start = configFile.lastIndexOf(File.separator);
int end = configFile.lastIndexOf(".lst");
if (end != -1) {
}
public String getFileForHandle(String handle) {
- IProgramElement node = AsmManager.getDefault().getHierarchy().getElement(handle);
+ IProgramElement node = asm.getHierarchy().getElement(handle);
if (node != null) {
- return AsmManager.getDefault().getCanonicalFilePath(node.getSourceLocation().getSourceFile());
+ return asm.getCanonicalFilePath(node.getSourceLocation().getSourceFile());
} else if (handle.charAt(0) == HandleProviderDelimiter.ASPECT_CU.getDelimiter()
|| handle.charAt(0) == HandleProviderDelimiter.COMPILATIONUNIT.getDelimiter()) {
// it's something like *MyAspect.aj or {MyClass.java. In other words
}
public int getLineNumberForHandle(String handle) {
- IProgramElement node = AsmManager.getDefault().getHierarchy().getElement(handle);
+ IProgramElement node = asm.getHierarchy().getElement(handle);
if (node != null) {
return node.getSourceLocation().getLine();
} else if (handle.charAt(0) == HandleProviderDelimiter.ASPECT_CU.getDelimiter()
}
public int getOffSetForHandle(String handle) {
- IProgramElement node = AsmManager.getDefault().getHierarchy().getElement(handle);
+ IProgramElement node = asm.getHierarchy().getElement(handle);
if (node != null) {
return node.getSourceLocation().getOffset();
} else if (handle.charAt(0) == HandleProviderDelimiter.ASPECT_CU.getDelimiter()
}
public String createHandleIdentifier(ISourceLocation location) {
- IProgramElement node = AsmManager.getDefault().getHierarchy().findElementForSourceLine(location);
+ IProgramElement node = asm.getHierarchy().findElementForSourceLine(location);
if (node != null) {
return createHandleIdentifier(node);
}
}
public String createHandleIdentifier(File sourceFile, int line, int column, int offset) {
- IProgramElement node = AsmManager.getDefault().getHierarchy().findElementForOffSet(sourceFile.getAbsolutePath(), line,
- offset);
+ IProgramElement node = asm.getHierarchy().findElementForOffSet(sourceFile.getAbsolutePath(), line, offset);
if (node != null) {
return createHandleIdentifier(node);
}
*/
public class ProgramElement implements IProgramElement {
+ public transient AsmManager asm; // which structure model is this node part of
private static final long serialVersionUID = 171673495267384449L;
public static boolean shortITDNames = true;
// --- ctors
+ public AsmManager getModel() {
+ return asm;
+ }
+
/** Used during de-externalization */
public ProgramElement() {
+ int stop = 1;
}
/** Use to create program element nodes that do not correspond to source locations */
- public ProgramElement(String name, Kind kind, List children) {
+ public ProgramElement(AsmManager asm, String name, Kind kind, List children) {
+ this.asm = asm;
+ if (asm == null && !name.equals("<build to view structure>")) {
+ throw new RuntimeException();
+ }
this.name = name;
this.kind = kind;
if (children != null)
setChildren(children);
}
- public ProgramElement(String name, IProgramElement.Kind kind, ISourceLocation sourceLocation, int modifiers, String comment,
- List children) {
- this(name, kind, children);
+ public ProgramElement(AsmManager asm, String name, IProgramElement.Kind kind, ISourceLocation sourceLocation, int modifiers,
+ String comment, List children) {
+ this(asm, name, kind, children);
this.sourceLocation = sourceLocation;
setFormalComment(comment);
// if (comment!=null && comment.length()>0) formalComment = comment;
public String getHandleIdentifier(boolean create) {
if (null == handle && create) {
- handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(this);
+ if (asm == null && name.equals("<build to view structure>")) {
+ handle = "<build to view structure>";
+ } else {
+ handle = asm.getHandleProvider().createHandleIdentifier(this);
+ }
}
return handle;
}