private static TopFrame topFrame = null;
public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() {
- public void containmentHierarchyUpdated(StructureModel model) {
+ public void containmentHierarchyUpdated(AspectJModel model) {
FileStructureView fsv = Ajde.getDefault().getStructureViewManager().getDefaultFileView();
if (fsv != null) {
fsv.setSourceFile(BrowserManager.getDefault().getEditorManager().getCurrFile());
public static List getPackagesInModel() {
List packages = new ArrayList();
- StructureModel model =
+ AspectJModel model =
Ajde.getDefault().getStructureModelManager().getModel();
- if (model.equals(StructureModel.NO_STRUCTURE)) {
+ if (model.equals(AspectJModel.NO_STRUCTURE)) {
return null;
} else {
return getPackagesHelper(
IProgramElement.Kind kind) {
List matches = new ArrayList();
- StructureModel model = Ajde.getDefault().getStructureModelManager().getModel();
- if (model.equals(StructureModel.NO_STRUCTURE)) {
+ AspectJModel model = Ajde.getDefault().getStructureModelManager().getModel();
+ if (model.equals(AspectJModel.NO_STRUCTURE)) {
return null;
} else {
return findMatchesHelper((IProgramElement)model.getRoot(), pattern, kind, matches);
private static final List AVAILABLE_RELATIONS;
public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() {
- public void containmentHierarchyUpdated(StructureModel model) {
+ public void containmentHierarchyUpdated(AspectJModel model) {
Ajde.getDefault().logEvent("updating structure views: " + structureViews);
//
// if (defaultFileView != null) {
// }
for (Iterator it = structureViews.iterator(); it.hasNext(); ) {
- treeViewBuilder.buildView((StructureView)it.next(), (StructureModel)model);
+ treeViewBuilder.buildView((StructureView)it.next(), (AspectJModel)model);
}
}
};
*/
private void navigationAction(IProgramElement node, boolean recordHistory) {
if (node == null
- || node == StructureModel.NO_STRUCTURE) {
+ || node == AspectJModel.NO_STRUCTURE) {
Ajde.getDefault().getIdeUIAdapter().displayStatusInformation("Source not available for node: " + node.getName());
return;
}
AbstractIcon icon = iconRegistry.getStructureIcon(node.getKind(), node.getAccessibility());
IStructureViewNode svNode = createDeclaration(node, icon, children);
- IRelationship rel = AsmManager.getDefault().getMapper().get(node);
- if (rel != null && rel.getTargets().size() > 0) {
- IStructureViewNode relNode = createRelationship(
- rel,
- iconRegistry.getIcon(rel.getKind())
- );
- svNode.add(relNode, 0);
-
- for (Iterator it = rel.getTargets().iterator(); it.hasNext(); ) {
- IProgramElement link = (IProgramElement)it.next();
- IStructureViewNode linkNode = createLink(
- link,
- iconRegistry.getStructureIcon(link.getKind(), link.getAccessibility())
- );
- relNode.add(linkNode);
-
+ List relationships = AsmManager.getDefault().getMapper().get(node);
+ for (Iterator it = relationships.iterator(); it.hasNext(); ) {
+ IRelationship rel = (IRelationship)it.next();
+ if (rel != null && rel.getTargets().size() > 0) {
+ IStructureViewNode relNode = createRelationship(
+ rel,
+ iconRegistry.getIcon(rel.getKind())
+ );
+ svNode.add(relNode, 0);
+
+ for (Iterator it2 = rel.getTargets().iterator(); it2.hasNext(); ) {
+ IProgramElement link = (IProgramElement)it2.next();
+ IStructureViewNode linkNode = createLink(
+ link,
+ iconRegistry.getStructureIcon(link.getKind(), link.getAccessibility())
+ );
+ relNode.add(linkNode);
+
+ }
}
}
return svNode;
/**
* @todo get rid of instanceof tests
*/
- public void buildView(StructureView view, StructureModel model) {
+ public void buildView(StructureView view, AspectJModel model) {
StructureViewProperties properties = view.getViewProperties();
IProgramElement modelRoot = null;
boolean noStructure = false;
if (isFileView(view)) {
FileStructureView fileView = (FileStructureView)view;
if (fileView.getSourceFile() == null) {
- modelRoot = StructureModel.NO_STRUCTURE;
+ modelRoot = AspectJModel.NO_STRUCTURE;
noStructure = true;
} else {
modelRoot = model.findRootNodeForSourceFile(fileView.getSourceFile());
}
}
- private IStructureViewNode buildCustomTree(GlobalStructureView view, StructureModel model) {
+ private IStructureViewNode buildCustomTree(GlobalStructureView view, AspectJModel model) {
IProgramElement rootNode = model.getRoot();
IStructureViewNode treeNode = nodeFactory.createNode(rootNode);
import org.aspectj.ajde.ui.StructureView;
import org.aspectj.ajde.ui.StructureViewProperties;
import org.aspectj.asm.IProgramElement;
-import org.aspectj.asm.StructureModel;
+import org.aspectj.asm.AspectJModel;
import org.aspectj.asm.IStructureModelListener;
public class SimpleStructureViewToolPanel extends JPanel {
BorderLayout borderLayout4 = new BorderLayout();
public final IStructureModelListener MODEL_LISTENER = new IStructureModelListener() {
- public void containmentHierarchyUpdated(StructureModel model) {
+ public void containmentHierarchyUpdated(AspectJModel model) {
String path = Ajde.getDefault().getConfigurationManager().getActiveConfigFile();
String fileName = "<no active config>";
if (path != null) fileName = new File(path).getName();
private TreeSelectionListener treeListener = null;
private final StructureTreeModel NO_STRUCTURE_MODEL
- = new StructureTreeModel(new SwingTreeViewNode(StructureModel.NO_STRUCTURE, new AbstractIcon(null), new ArrayList()));
+ = new StructureTreeModel(new SwingTreeViewNode(AspectJModel.NO_STRUCTURE, new AbstractIcon(null), new ArrayList()));
/**
* @todo should probably avoid that MouseListener cast
// TODO: add tests for java kinds
public class AsmDeclarationsTest extends AjdeTestCase {
- private StructureModel model = null;
+ private AspectJModel model = null;
private static final String CONFIG_FILE_PATH = "../examples/coverage/coverage.lst";
private static final int DEC_MESSAGE_LENGTH = AsmNodeFormatter.MAX_MESSAGE_LENGTH;
import org.aspectj.asm.*;
import org.aspectj.asm.internal.ProgramElement;
-
// TODO: check for return types
public class AsmRelationshipsTest extends AjdeTestCase {
}
// public void testInterTypeDeclarations() {
-// checkMapping("InterTypeDecCoverage", "Point", "Point.xxx:", "xxx");
+// checkMapping("InterTypeDecCoverage", "Point", "Point.xxx:", "xxx", "declared on", "aspect declarations");
// }
public void testAdvice() {
- checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)");
- checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)");
- checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.xxx)");
+ checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)", "advises", "advised by");
+ checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)", "advises");
+ checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.xxx)", "advises");
}
- private void checkUniDirectionalMapping(String fromType, String toType, String from, String to) {
+ private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) {
IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from;
IProgramElement beforeExecNode = manager.getModel().findNode(aspect, IProgramElement.Kind.ADVICE, beforeExec);
assertNotNull(beforeExecNode);
- IRelationship rel = manager.getMapper().get(beforeExecNode);
+ IRelationship rel = manager.getMapper().get(beforeExecNode, IRelationship.Kind.ADVICE, relName);
assertEquals(((IProgramElement)rel.getTargets().get(0)).getName(), to);
}
- private void checkMapping(String fromType, String toType, String from, String to) {
+ private void checkMapping(String fromType, String toType, String from, String to, String forwardRelName, String backRelName) {
IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from;
IProgramElement beforeExecNode = manager.getModel().findNode(aspect, IProgramElement.Kind.ADVICE, beforeExec);
assertNotNull(beforeExecNode);
- IRelationship rel = manager.getMapper().get(beforeExecNode);
+ IRelationship rel = manager.getMapper().get(beforeExecNode, IRelationship.Kind.ADVICE, forwardRelName);
assertEquals(((IProgramElement)rel.getTargets().get(0)).getName(), to);
IProgramElement clazz = AsmManager.getDefault().getModel().findNodeForType(null, toType);
String set = to;
IProgramElement setNode = manager.getModel().findNode(clazz, IProgramElement.Kind.METHOD, set);
assertNotNull(setNode);
- IRelationship rel2 = manager.getMapper().get(setNode);
+ IRelationship rel2 = manager.getMapper().get(setNode, IRelationship.Kind.ADVICE, backRelName);
assertEquals(((IProgramElement)rel2.getTargets().get(0)).getName(), from);
}
public boolean verifyAgainstSavedModel(String lstFile) {
File modelFile = new File(genStructureModelExternFilePath(lstFile));
- StructureModel model = getModelForFile(lstFile);
+ AspectJModel model = getModelForFile(lstFile);
if (modelFile.exists()) {
Ajde.getDefault().getStructureModelManager().readStructureModel(lstFile);
- StructureModel savedModel = Ajde.getDefault().getStructureModelManager().getModel();
+ AspectJModel savedModel = Ajde.getDefault().getStructureModelManager().getModel();
// AMC This test will not pass as written until IProgramElement defines
// equals. The equals loic is commented out in the IProgramElement
// class - adding it back in could have unforeseen system-wide
return equal;
}
- private StructureModel getModelForFile(String lstFile) {
+ private AspectJModel getModelForFile(String lstFile) {
Ajde.getDefault().getConfigurationManager().setActiveConfigFile(lstFile);
Ajde.getDefault().getBuildManager().build(); // was buildStructure...
while(!testerBuildListener.getBuildFinished()) {
* @todo add negative test to make sure things that aren't runnable aren't annotated
*/
public void testMainClassNodeInfo() throws IOException {
- StructureModel model = Ajde.getDefault().getStructureModelManager().getModel();
+ AspectJModel model = Ajde.getDefault().getStructureModelManager().getModel();
assertTrue("model exists", model != null);
assertTrue("root exists", model.getRoot() != null);
File testFile = openFile("figures-coverage/figures/Main.java");
assertTrue(
"no structure",
currentView.getRootNode().getStructureNode().getChildren().get(0)
- == StructureModel.NO_STRUCTURE
+ == AspectJModel.NO_STRUCTURE
);
}
assertTrue(
"no structure",
//currentView.getRootNode().getIProgramElement().getChildren().get(0)
- n == StructureModel.NO_STRUCTURE
+ n == AspectJModel.NO_STRUCTURE
);
}
assertTrue(
"no structure",
currentView.getRootNode().getStructureNode()
- == StructureModel.NO_STRUCTURE
+ == AspectJModel.NO_STRUCTURE
);
}
*/
private static AsmManager INSTANCE = new AsmManager();
private boolean shouldSaveModel = true;
- protected StructureModel model = new StructureModel();
+ protected AspectJModel model = new AspectJModel();
private List structureListeners = new ArrayList();
private IRelationshipMapper mapper;
mapper = new RelationshipMapper();
}
- public StructureModel getModel() {
+ public AspectJModel getModel() {
return model;
}
public void readStructureModel(String configFilePath) {
try {
if (configFilePath == null) {
- model.setRoot(StructureModel.NO_STRUCTURE);
+ model.setRoot(AspectJModel.NO_STRUCTURE);
} else {
String filePath = genExternFilePath(configFilePath);
FileInputStream in = new FileInputStream(filePath);
ObjectInputStream s = new ObjectInputStream(in);
- model = (StructureModel)s.readObject();
+ model = (AspectJModel)s.readObject();
}
} catch (Exception e) {
//System.err.println("AJDE Message: could not read structure model: " + e);
- model.setRoot(StructureModel.NO_STRUCTURE);
+ model.setRoot(AspectJModel.NO_STRUCTURE);
} finally {
notifyListeners();
}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * 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:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.asm;
+
+import java.io.*;
+import java.util.*;
+
+import org.aspectj.asm.internal.ProgramElement;
+import org.aspectj.bridge.*;
+
+/**
+ * @author Mik Kersten
+ */
+public class AspectJModel implements Serializable {
+
+ protected IProgramElement root = null;
+ protected String configFile = null;
+
+ private Map fileMap = null;
+
+ public static final IProgramElement NO_STRUCTURE = new ProgramElement("<build to view structure>", IProgramElement.Kind.ERROR, null);
+
+ public IProgramElement getElement(String handle) {
+ throw new RuntimeException("unimplemented");
+ }
+
+ public IProgramElement getRoot() {
+ return root;
+ }
+
+ public void setRoot(IProgramElement root) {
+ this.root = root;
+ }
+
+ public void addToFileMap( Object key, Object value ){
+ fileMap.put( key, value );
+ }
+
+ public void setFileMap(HashMap fileMap) {
+ this.fileMap = fileMap;
+ }
+
+ public Object findInFileMap( Object key ) {
+ return fileMap.get(key);
+ }
+
+
+ public Set getFileMapEntrySet() {
+ return fileMap.entrySet();
+ }
+
+ public boolean isValid() {
+ return root != null && fileMap != null;
+ }
+
+
+ /**
+ * Returns the first match
+ *
+ * @param parent
+ * @param kind not null
+ * @param decErrLabel
+ * @return null if not found
+ */
+ public IProgramElement findNode(IProgramElement parent, IProgramElement.Kind kind, String name) {
+ for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) {
+ IProgramElement node = (IProgramElement)it.next();
+ if (node.getKind().equals(kind)
+ && name.equals(node.getName())) {
+ return node;
+ } else {
+ IProgramElement childSearch = findNode(node, kind, name);
+ if (childSearch != null) return childSearch;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param signatureKey PackageName.TypeName.Signature.SourceLine.SourceColumn
+ */
+ public IProgramElement findNodeForSignatureKey(String signatureKey) {
+ throw new RuntimeException("unimplemented");
+ }
+
+ /**
+ * @param packageName if null default package is searched
+ * @param className can't be null
+ */
+ public IProgramElement findNodeForType(String packageName, String typeName) {
+ IProgramElement packageNode = null;
+ if (packageName == null) {
+ packageNode = root;
+ } else {
+ for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) {
+ IProgramElement node = (IProgramElement)it.next();
+ if (packageName.equals(node.getName())) {
+ packageNode = node;
+ }
+ }
+ if (packageNode == null) return null;
+ }
+
+ // this searches each file for a class
+ for (Iterator it = packageNode.getChildren().iterator(); it.hasNext(); ) {
+ IProgramElement fileNode = (IProgramElement)it.next();
+ IProgramElement ret = findClassInNodes(fileNode.getChildren(), typeName);
+ if (ret != null) return ret;
+ }
+
+ return null;
+ }
+
+ private IProgramElement findClassInNodes(Collection nodes, String name) {
+ String baseName;
+ String innerName;
+ int dollar = name.indexOf('$');
+ if (dollar == -1) {
+ baseName = name;
+ innerName = null;
+ } else {
+ baseName = name.substring(0, dollar);
+ innerName = name.substring(dollar+1);
+ }
+
+ for (Iterator j = nodes.iterator(); j.hasNext(); ) {
+ IProgramElement classNode = (IProgramElement)j.next();
+ if (baseName.equals(classNode.getName())) {
+ if (innerName == null) return classNode;
+ else return findClassInNodes(classNode.getChildren(), innerName);
+ } else if (name.equals(classNode.getName())) {
+ return classNode;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * @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 findRootNodeForSourceFile(String sourceFile) {
+ try {
+ if (!isValid() || sourceFile == null) {
+ return AspectJModel.NO_STRUCTURE;
+ } else {
+ String correctedPath = new File(sourceFile).getCanonicalPath();//.replace('\\', '/');
+ //StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model);
+ IProgramElement node = (IProgramElement)findInFileMap(correctedPath);//findFileNode(filePath, model);
+ if (node != null) {
+ return node;
+ } else {
+ return createFileStructureNode(correctedPath);
+ }
+ }
+ } catch (Exception e) {
+ return AspectJModel.NO_STRUCTURE;
+ }
+ }
+
+ /**
+ * TODO: discriminate columns
+ */
+ public IProgramElement findNodeForSourceLine(ISourceLocation location) {
+ return findNodeForSourceLine(location.getSourceFile().getAbsolutePath(), location.getLine());
+ }
+
+ /**
+ * 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
+ */
+ public IProgramElement findNodeForSourceLine(String sourceFilePath, int lineNumber) {
+ IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber);
+ if (node != null) {
+ return node;
+ } else {
+ return createFileStructureNode(sourceFilePath);
+ }
+ }
+
+ private IProgramElement createFileStructureNode(String sourceFilePath) {
+ String fileName = new File(sourceFilePath).getName();
+ IProgramElement fileNode = new ProgramElement(fileName, IProgramElement.Kind.FILE_JAVA, null);
+ fileNode.setSourceLocation(new SourceLocation(new File(sourceFilePath), 1, 1));
+ fileNode.addChild(NO_STRUCTURE);
+ return fileNode;
+ }
+
+
+ private IProgramElement findNodeForSourceLineHelper(IProgramElement node, String sourceFilePath, int lineNumber) {
+ if (matches(node, sourceFilePath, lineNumber)
+ && !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) {
+ return node;
+ }
+
+ if (node != null && node.getChildren() != null) {
+ for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
+ IProgramElement foundNode = findNodeForSourceLineHelper(
+ (IProgramElement)it.next(),
+ sourceFilePath,
+ lineNumber);
+ if (foundNode != null) return foundNode;
+ }
+ }
+
+ return null;
+ }
+
+ private boolean matches(IProgramElement node, String sourceFilePath, int lineNumber) {
+ try {
+// if (node != null && node.getSourceLocation() != null)
+// System.err.println("====\n1: " +
+// sourceFilePath + "\n2: " +
+// node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
+// );
+
+ return node != null
+ && node.getSourceLocation() != null
+ && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
+ && ((node.getSourceLocation().getLine() <= lineNumber
+ && node.getSourceLocation().getEndLine() >= lineNumber)
+ ||
+ (lineNumber <= 1
+ && node instanceof IProgramElement
+ && ((IProgramElement)node).getKind().isSourceFileKind())
+ );
+ } catch (IOException ioe) {
+ return false;
+ }
+ }
+
+ private boolean hasMoreSpecificChild(IProgramElement node, String sourceFilePath, int lineNumber) {
+ for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
+ IProgramElement child = (IProgramElement)it.next();
+ if (matches(child, sourceFilePath, lineNumber)) return true;
+ }
+ return false;
+ }
+
+ public String getConfigFile() {
+ return configFile;
+ }
+
+ public void setConfigFile(String configFile) {
+ this.configFile = configFile;
+ }
+}
+
/**
* @author Mik Kersten
*/
-public class HierarchyWalker {
+public abstract class HierarchyWalker {
- private StructureModel model;
+ private AspectJModel model;
public HierarchyWalker() {
super();
}
- public HierarchyWalker(StructureModel model) {
+ public HierarchyWalker(AspectJModel model) {
this.model = model;
}
public IProgramElement getSource();
public Kind getKind();
-
+
/**
* Uses "typesafe enum" pattern.
*/
import org.aspectj.asm.IRelationship.Kind;
/**
+ * Maps from a program element to a list of relationships between that element
+ * and othe program elements. Each element in the list or relationships is
+ * uniquely identified by a kind and a relationship name.
+ *
* @author Mik Kersten
*/
public interface IRelationshipMapper extends Serializable {
- // TODO: return a list
- public IRelationship get(IProgramElement source);
+ /**
+ * @return an empty list if the element is not found.
+ */
+ public List get(IProgramElement source);
+
+ /**
+ * Return a relationship matching the kind and name for the given element.
+ *
+ * @return null if the relationship is not found.
+ */
+ public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName);
- // TODO: return a list
- public IRelationship get(String handle);
- public void put(IProgramElement source, IRelationship relationship);
+ public List/*IRelationship*/ get(String handle);
+ public void put(IProgramElement source, IRelationship relationship);
+
}
*/
public interface IStructureModelListener extends EventListener {
- public void containmentHierarchyUpdated(StructureModel rootNode);
+ public void containmentHierarchyUpdated(AspectJModel rootNode);
}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 1999-2001 Xerox Corporation,
- * 2002 Palo Alto Research Center, Incorporated (PARC).
- * 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:
- * Xerox/PARC initial implementation
- * ******************************************************************/
-
-
-package org.aspectj.asm;
-
-import java.io.*;
-import java.util.*;
-
-import org.aspectj.asm.internal.ProgramElement;
-import org.aspectj.bridge.*;
-
-/**
- * @author Mik Kersten
- */
-public class StructureModel implements Serializable {
-
- protected IProgramElement root = null;
- protected String configFile = null;
-
- private Map fileMap = null;
-
- public static final IProgramElement NO_STRUCTURE = new ProgramElement("<build to view structure>", IProgramElement.Kind.ERROR, null);
-
- public IProgramElement getElement(String handle) {
- throw new RuntimeException("unimplemented");
- }
-
- public IProgramElement getRoot() {
- return root;
- }
-
- public void setRoot(IProgramElement root) {
- this.root = root;
- }
-
- public void addToFileMap( Object key, Object value ){
- fileMap.put( key, value );
- }
-
- public void setFileMap(HashMap fileMap) {
- this.fileMap = fileMap;
- }
-
- public Object findInFileMap( Object key ) {
- return fileMap.get(key);
- }
-
-
- public Set getFileMapEntrySet() {
- return fileMap.entrySet();
- }
-
- public boolean isValid() {
- return root != null && fileMap != null;
- }
-
-
- /**
- * Returns the first match
- *
- * @param parent
- * @param kind not null
- * @param decErrLabel
- * @return null if not found
- */
- public IProgramElement findNode(IProgramElement parent, IProgramElement.Kind kind, String name) {
- for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) {
- IProgramElement node = (IProgramElement)it.next();
- if (node.getKind().equals(kind)
- && name.equals(node.getName())) {
- return node;
- } else {
- IProgramElement childSearch = findNode(node, kind, name);
- if (childSearch != null) return childSearch;
- }
- }
- return null;
- }
-
- /**
- *
- * @param signatureKey PackageName.TypeName.Signature.SourceLine.SourceColumn
- */
- public IProgramElement findNodeForSignatureKey(String signatureKey) {
- throw new RuntimeException("unimplemented");
- }
-
- /**
- * @param packageName if null default package is searched
- * @param className can't be null
- */
- public IProgramElement findNodeForType(String packageName, String typeName) {
- IProgramElement packageNode = null;
- if (packageName == null) {
- packageNode = root;
- } else {
- for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) {
- IProgramElement node = (IProgramElement)it.next();
- if (packageName.equals(node.getName())) {
- packageNode = node;
- }
- }
- if (packageNode == null) return null;
- }
-
- // this searches each file for a class
- for (Iterator it = packageNode.getChildren().iterator(); it.hasNext(); ) {
- IProgramElement fileNode = (IProgramElement)it.next();
- IProgramElement ret = findClassInNodes(fileNode.getChildren(), typeName);
- if (ret != null) return ret;
- }
-
- return null;
- }
-
- private IProgramElement findClassInNodes(Collection nodes, String name) {
- String baseName;
- String innerName;
- int dollar = name.indexOf('$');
- if (dollar == -1) {
- baseName = name;
- innerName = null;
- } else {
- baseName = name.substring(0, dollar);
- innerName = name.substring(dollar+1);
- }
-
- for (Iterator j = nodes.iterator(); j.hasNext(); ) {
- IProgramElement classNode = (IProgramElement)j.next();
- if (baseName.equals(classNode.getName())) {
- if (innerName == null) return classNode;
- else return findClassInNodes(classNode.getChildren(), innerName);
- } else if (name.equals(classNode.getName())) {
- return classNode;
- }
- }
- return null;
- }
-
-
- /**
- * @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 findRootNodeForSourceFile(String sourceFile) {
- try {
- if (!isValid() || sourceFile == null) {
- return StructureModel.NO_STRUCTURE;
- } else {
- String correctedPath = new File(sourceFile).getCanonicalPath();//.replace('\\', '/');
- //StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model);
- IProgramElement node = (IProgramElement)findInFileMap(correctedPath);//findFileNode(filePath, model);
- if (node != null) {
- return node;
- } else {
- return createFileStructureNode(correctedPath);
- }
- }
- } catch (Exception e) {
- return StructureModel.NO_STRUCTURE;
- }
- }
-
- /**
- * TODO: discriminate columns
- */
- public IProgramElement findNodeForSourceLine(ISourceLocation location) {
- return findNodeForSourceLine(location.getSourceFile().getAbsolutePath(), location.getLine());
- }
-
- /**
- * 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
- */
- public IProgramElement findNodeForSourceLine(String sourceFilePath, int lineNumber) {
- IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber);
- if (node != null) {
- return node;
- } else {
- return createFileStructureNode(sourceFilePath);
- }
- }
-
- private IProgramElement createFileStructureNode(String sourceFilePath) {
- String fileName = new File(sourceFilePath).getName();
- IProgramElement fileNode = new ProgramElement(fileName, IProgramElement.Kind.FILE_JAVA, null);
- fileNode.setSourceLocation(new SourceLocation(new File(sourceFilePath), 1, 1));
- fileNode.addChild(NO_STRUCTURE);
- return fileNode;
- }
-
-
- private IProgramElement findNodeForSourceLineHelper(IProgramElement node, String sourceFilePath, int lineNumber) {
- if (matches(node, sourceFilePath, lineNumber)
- && !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) {
- return node;
- }
-
- if (node != null && node.getChildren() != null) {
- for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
- IProgramElement foundNode = findNodeForSourceLineHelper(
- (IProgramElement)it.next(),
- sourceFilePath,
- lineNumber);
- if (foundNode != null) return foundNode;
- }
- }
-
- return null;
- }
-
- private boolean matches(IProgramElement node, String sourceFilePath, int lineNumber) {
- try {
-// if (node != null && node.getSourceLocation() != null)
-// System.err.println("====\n1: " +
-// sourceFilePath + "\n2: " +
-// node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
-// );
-
- return node != null
- && node.getSourceLocation() != null
- && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
- && ((node.getSourceLocation().getLine() <= lineNumber
- && node.getSourceLocation().getEndLine() >= lineNumber)
- ||
- (lineNumber <= 1
- && node instanceof IProgramElement
- && ((IProgramElement)node).getKind().isSourceFileKind())
- );
- } catch (IOException ioe) {
- return false;
- }
- }
-
- private boolean hasMoreSpecificChild(IProgramElement node, String sourceFilePath, int lineNumber) {
- for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
- IProgramElement child = (IProgramElement)it.next();
- if (matches(child, sourceFilePath, lineNumber)) return true;
- }
- return false;
- }
-
- public String getConfigFile() {
- return configFile;
- }
-
- public void setConfigFile(String configFile) {
- this.configFile = configFile;
- }
-}
-
*/
public class RelationshipMapper extends HashMap implements IRelationshipMapper {
- public IRelationship get(IProgramElement source) {
- return (IRelationship)super.get(source);
+ public List get(IProgramElement source) {
+ List relationships = (List)super.get(source);
+ if (relationships == null) {
+ return Collections.EMPTY_LIST;
+ } else {
+ return relationships;
+ }
}
- public IRelationship get(String handle) {
+ /**
+ * @return null if the relationship is not found.
+ */
+ public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName) {
+ List relationships = get(source);
+ for (Iterator it = relationships.iterator(); it.hasNext(); ) {
+ IRelationship curr = (IRelationship)it.next();
+ if (curr.getKind() == kind && curr.getName() == relationshipName) {
+ return curr;
+ }
+ }
+ return null;
+ }
+
+ public List get(String handle) {
throw new RuntimeException("unimplemented");
}
public void put(IProgramElement source, IRelationship relationship) {
- super.put(source, relationship);
+ List list = (List)super.get(source);
+ if (list == null) {
+ list = new ArrayList();
+ list.add(relationship);
+ super.put(source, list);
+ } else {
+ boolean matched = false;
+ for (Iterator it = list.iterator(); it.hasNext(); ) {
+ IRelationship curr = (IRelationship)it.next();
+ if (curr.getName().equals(relationship.getName())) {
+ curr.getTargets().addAll(relationship.getTargets());
+ matched = true;
+ }
+ }
+ if (!matched) list.add(relationship);
+ }
}
// TODO: add a remove, and a clear all
private int compiledCount;
private int sourceFileCount;
- private StructureModel structureModel;
+ private AspectJModel structureModel;
public AjBuildConfig buildConfig;
AjState state = new AjState(this);
private void setupModel() {
String rootLabel = "<root>";
- StructureModel model = AsmManager.getDefault().getModel();
+ AspectJModel model = AsmManager.getDefault().getModel();
IProgramElement.Kind kind = IProgramElement.Kind.FILE_JAVA;
if (buildConfig.getConfigFile() != null) {
rootLabel = buildConfig.getConfigFile().getName();
}
- public void setStructureModel(StructureModel structureModel) {
+ public void setStructureModel(AspectJModel structureModel) {
this.structureModel = structureModel;
}
/**
* Returns null if there is no structure model
*/
- public StructureModel getStructureModel() {
+ public AspectJModel getStructureModel() {
return structureModel;
}
public static void build(
CompilationUnitDeclaration unit,
- StructureModel structureModel) {
+ AspectJModel structureModel) {
LangUtil.throwIaxIfNull(unit, "unit");
new AsmHierarchyBuilder(unit.compilationResult()).internalBuild(unit, structureModel);
}
*/
private void internalBuild(
CompilationUnitDeclaration unit,
- StructureModel structureModel) {
+ AspectJModel structureModel) {
LangUtil.throwIaxIfNull(structureModel, "structureModel");
if (!currCompilationResult.equals(unit.compilationResult())) {
throw new IllegalArgumentException("invalid unit: " + unit);
*/
private IProgramElement genAddToNode(
CompilationUnitDeclaration unit,
- StructureModel structureModel) {
+ AspectJModel structureModel) {
final IProgramElement addToNode;
{
ImportReference currentPackage = unit.currentPackage;
public static final String DECLARES_ON = "declares on";
public static final String DECLAREDY_BY = "declared by";
- public static void checkerMunger(StructureModel model, Shadow shadow) {
+ public static void checkerMunger(AspectJModel model, Shadow shadow) {
// System.err.println("> " + shadow.getThisVar() + " to " + shadow.getTargetVar());
}
- public static void nodeMunger(StructureModel model, Shadow shadow, ShadowMunger munger) {
+ public static void nodeMunger(AspectJModel model, Shadow shadow, ShadowMunger munger) {
if (munger instanceof Advice) {
Advice a = (Advice)munger;
if (a.getKind().isPerEntry() || a.getKind().isCflow()) {
IProgramElement adviceNode = getNode(model, a);
if (adviceNode != null && targetNode != null) {
- IRelationship foreward = mapper.get(adviceNode);
+ IRelationship foreward = mapper.get(adviceNode, IRelationship.Kind.ADVICE, ADVISES);
if (foreward == null) {
foreward = new Relationship(
ADVISES,
}
foreward.getTargets().add(targetNode);
- IRelationship back = mapper.get(targetNode);
+ IRelationship back = mapper.get(targetNode, IRelationship.Kind.ADVICE, ADVISED_BY);
if (back == null) {
back = new Relationship(
ADVISED_BY,
}
}
- private static IProgramElement getNode(StructureModel model, Advice a) {
+ private static IProgramElement getNode(AspectJModel model, Advice a) {
//ResolvedTypeX inAspect = a.getConcreteAspect();
Member member = a.getSignature();
if (a.getSignature() == null) return null;
return lookupMember(model, member);
}
- private static IProgramElement getNode(StructureModel model, Shadow shadow) {
+ private static IProgramElement getNode(AspectJModel model, Shadow shadow) {
Member enclosingMember = shadow.getEnclosingCodeSignature();
IProgramElement enclosingNode = lookupMember(model, enclosingMember);
return peNode;
}
- public static IProgramElement lookupMember(StructureModel model, Member member) {
+ public static IProgramElement lookupMember(AspectJModel model, Member member) {
TypeX declaringType = member.getDeclaringType();
IProgramElement classNode =
model.findNodeForType(declaringType.getPackageName(), declaringType.getClassName());
import java.util.List;
import java.util.Map;
-import org.aspectj.asm.StructureModel;
+import org.aspectj.asm.AspectJModel;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
protected CrosscuttingMembersSet crosscuttingMembersSet = new CrosscuttingMembersSet(this);
- protected StructureModel model = null;
+ protected AspectJModel model = null;
protected Lint lint = new Lint(this);
return crosscuttingMembersSet;
}
- public StructureModel getModel() {
+ public AspectJModel getModel() {
return model;
}
- public void setModel(StructureModel model) {
+ public void setModel(AspectJModel model) {
this.model = model;
}