diff options
Diffstat (limited to 'asm/src')
-rw-r--r-- | asm/src/org/aspectj/asm/AsmManager.java | 52 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/HierarchyWalker.java | 14 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/IHierarchy.java | 92 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/IHierarchyListener.java (renamed from asm/src/org/aspectj/asm/IStructureModelListener.java) | 11 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/IProgramElement.java | 71 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/IRelationship.java | 10 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/IRelationshipMap.java (renamed from asm/src/org/aspectj/asm/IRelationshipMapper.java) | 32 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java (renamed from asm/src/org/aspectj/asm/AspectJModel.java) | 114 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/internal/ProgramElement.java | 96 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/internal/Relationship.java | 16 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/internal/RelationshipMap.java | 114 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/internal/RelationshipMapper.java | 90 |
12 files changed, 505 insertions, 207 deletions
diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java index b090abfcf..3fcb353e0 100644 --- a/asm/src/org/aspectj/asm/AsmManager.java +++ b/asm/src/org/aspectj/asm/AsmManager.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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 @@ -8,7 +7,7 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ @@ -29,24 +28,32 @@ public class AsmManager { */ private static AsmManager INSTANCE = new AsmManager(); private boolean shouldSaveModel = true; - protected AspectJModel model = new AspectJModel(); + protected IHierarchy hierarchy; private List structureListeners = new ArrayList(); - private IRelationshipMapper mapper; + private IRelationshipMap mapper; protected AsmManager() { + hierarchy = new AspectJElementHierarchy(); List relationships = new ArrayList(); -// relationships.add(ADVICE); - mapper = new RelationshipMapper(); + mapper = new RelationshipMap(hierarchy); } - public AspectJModel getModel() { - return model; + public IHierarchy getHierarchy() { + return hierarchy; + } + + public static AsmManager getDefault() { + return INSTANCE; + } + + public IRelationshipMap getRelationshipMap() { + return mapper; } public void fireModelUpdated() { notifyListeners(); - if (model.getConfigFile() != null) { - writeStructureModel(model.getConfigFile()); + if (hierarchy.getConfigFile() != null) { + writeStructureModel(hierarchy.getConfigFile()); } } @@ -105,17 +112,17 @@ public class AsmManager { // } // } - public void addListener(IStructureModelListener listener) { + public void addListener(IHierarchyListener listener) { structureListeners.add(listener); } - public void removeStructureListener(IStructureModelListener listener) { + public void removeStructureListener(IHierarchyListener listener) { structureListeners.remove(listener); } private void notifyListeners() { for (Iterator it = structureListeners.iterator(); it.hasNext(); ) { - ((IStructureModelListener)it.next()).containmentHierarchyUpdated(model); + ((IHierarchyListener)it.next()).elementsUpdated(hierarchy); } } @@ -126,7 +133,7 @@ public class AsmManager { try { String filePath = genExternFilePath(configFilePath); ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(filePath)); - s.writeObject(model); + s.writeObject(hierarchy); s.flush(); } catch (Exception e) { // ignore @@ -140,16 +147,16 @@ public class AsmManager { public void readStructureModel(String configFilePath) { try { if (configFilePath == null) { - model.setRoot(AspectJModel.NO_STRUCTURE); + hierarchy.setRoot(IHierarchy.NO_STRUCTURE); } else { String filePath = genExternFilePath(configFilePath); FileInputStream in = new FileInputStream(filePath); ObjectInputStream s = new ObjectInputStream(in); - model = (AspectJModel)s.readObject(); + hierarchy = (AspectJElementHierarchy)s.readObject(); } } catch (Exception e) { //System.err.println("AJDE Message: could not read structure model: " + e); - model.setRoot(AspectJModel.NO_STRUCTURE); + hierarchy.setRoot(IHierarchy.NO_STRUCTURE); } finally { notifyListeners(); } @@ -162,14 +169,5 @@ public class AsmManager { public void setShouldSaveModel(boolean shouldSaveModel) { this.shouldSaveModel = shouldSaveModel; } - - public static AsmManager getDefault() { - return INSTANCE; - } - - public IRelationshipMapper getMapper() { - return mapper; - } - } diff --git a/asm/src/org/aspectj/asm/HierarchyWalker.java b/asm/src/org/aspectj/asm/HierarchyWalker.java index cac375482..2e2c08df3 100644 --- a/asm/src/org/aspectj/asm/HierarchyWalker.java +++ b/asm/src/org/aspectj/asm/HierarchyWalker.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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 @@ -8,25 +7,28 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ package org.aspectj.asm; +import org.aspectj.asm.internal.*; +import org.aspectj.asm.internal.*; + /** * @author Mik Kersten */ public abstract class HierarchyWalker { - private AspectJModel model; + private IHierarchy hierarchy; public HierarchyWalker() { super(); } - public HierarchyWalker(AspectJModel model) { - this.model = model; + public HierarchyWalker(IHierarchy hierarchy) { + this.hierarchy = hierarchy; } protected void preProcess(IProgramElement node) { } diff --git a/asm/src/org/aspectj/asm/IHierarchy.java b/asm/src/org/aspectj/asm/IHierarchy.java new file mode 100644 index 000000000..34816ee12 --- /dev/null +++ b/asm/src/org/aspectj/asm/IHierarchy.java @@ -0,0 +1,92 @@ +/* ******************************************************************* + * 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 + * ******************************************************************/ +package org.aspectj.asm; + +import java.io.Serializable; +import java.util.*; + +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 IProgramElement getElement(String handle); + public IProgramElement getRoot(); + public void setRoot(IProgramElement root); + public void addToFileMap(Object key, Object value); + public void setFileMap(HashMap fileMap); + public Object findInFileMap(Object key); + public Set getFileMapEntrySet(); + public boolean isValid(); + + /** + * @return null if not found + */ + public IProgramElement findElementForHandle(String handle); + + /** + * Returns the first match + * + * @param parent + * @param kind not null + * @return null if not found + */ + public IProgramElement findElementForSignature( + IProgramElement parent, + IProgramElement.Kind kind, + String signature); + + /** + * Returns the first match + * + * @param parent + * @param kind not null + * @return null if not found + */ + public IProgramElement findElementForLabel( + IProgramElement parent, + IProgramElement.Kind kind, + String label); + + /** + * @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 + */ + public IProgramElement findElementForSourceFile(String sourceFile); + + /** + * TODO: discriminate columns + */ + public IProgramElement findElementForSourceLine(ISourceLocation location); + + /** + * 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 findElementForSourceLine(String sourceFilePath, int lineNumber); + + public String getConfigFile(); + + public void setConfigFile(String configFile); +}
\ No newline at end of file diff --git a/asm/src/org/aspectj/asm/IStructureModelListener.java b/asm/src/org/aspectj/asm/IHierarchyListener.java index 6e2879ee1..96381934f 100644 --- a/asm/src/org/aspectj/asm/IStructureModelListener.java +++ b/asm/src/org/aspectj/asm/IHierarchyListener.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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 @@ -8,7 +7,7 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ @@ -16,12 +15,14 @@ package org.aspectj.asm; import java.util.EventListener; +import org.aspectj.asm.internal.*; + /** * Compiler listeners get notified of structure model update events. * * @author Mik Kersten */ -public interface IStructureModelListener extends EventListener { +public interface IHierarchyListener extends EventListener { - public void containmentHierarchyUpdated(AspectJModel rootNode); + public void elementsUpdated(IHierarchy rootNode); } diff --git a/asm/src/org/aspectj/asm/IProgramElement.java b/asm/src/org/aspectj/asm/IProgramElement.java index ced44fa7e..42a83d2b3 100644 --- a/asm/src/org/aspectj/asm/IProgramElement.java +++ b/asm/src/org/aspectj/asm/IProgramElement.java @@ -1,11 +1,13 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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; @@ -22,6 +24,8 @@ import org.aspectj.bridge.*; */ public interface IProgramElement extends Serializable { + public static final String ID_DELIM = "|"; + public List/*IProgramElement*/ getChildren(); public void setChildren(List children); @@ -32,6 +36,9 @@ public interface IProgramElement extends Serializable { public String getName(); public void setName(String name); + + public String getDetails(); + public void setDetails(String details); public IProgramElement.Kind getKind(); public void setKind(Kind kind); @@ -47,8 +54,7 @@ public interface IProgramElement extends Serializable { public void setReturnType(String returnType); public String getReturnType(); - public String getFullSignature(); - public void setFullSignature(String string); + public String toSignatureString(); public void setRunnable(boolean value); public boolean isRunnable(); @@ -66,8 +72,25 @@ public interface IProgramElement extends Serializable { public void setSourceLocation(ISourceLocation sourceLocation); public String toString(); + + /** + * Includes name, parameter types (if any) and details (if any). + */ + public String toLabelString(); + + public List getParameterTypes(); + public void setParameterTypes(List list); + + public List getParameterNames(); + public void setParameterNames(List list); - // public String getHandle() TODO: check IJavaElement + /** + * The format of the string handle is not specified, but is stable across + * compilation sessions. + * + * @return a string representtaion of this element + */ + public String getHandleIdentifier(); /** * @return a string representation of this node and all of its children (recursive) @@ -160,6 +183,7 @@ public interface IProgramElement extends Serializable { public static final Kind INTER_TYPE_FIELD = new Kind("inter-type field"); public static final Kind INTER_TYPE_METHOD = new Kind("inter-type method"); public static final Kind INTER_TYPE_CONSTRUCTOR = new Kind("inter-type constructor"); + public static final Kind INTER_TYPE_PARENT = new Kind("inter-type parent"); public static final Kind CONSTRUCTOR = new Kind("constructor"); public static final Kind METHOD = new Kind("method"); public static final Kind FIELD = new Kind("field"); @@ -170,14 +194,39 @@ public interface IProgramElement extends Serializable { public static final Kind DECLARE_ERROR = new Kind("declare error"); public static final Kind DECLARE_SOFT = new Kind("declare soft"); public static final Kind DECLARE_PRECEDENCE= new Kind("declare precedence"); - public static final Kind CODE = new Kind("decBodyElement"); + public static final Kind CODE = new Kind("code"); public static final Kind ERROR = new Kind("error"); - public static final Kind[] ALL = { PROJECT, PACKAGE, FILE, FILE_JAVA, - FILE_ASPECTJ, FILE_LST, CLASS, INTERFACE, ASPECT, - INITIALIZER, INTER_TYPE_FIELD, INTER_TYPE_METHOD, INTER_TYPE_CONSTRUCTOR, - CONSTRUCTOR, METHOD, FIELD, POINTCUT, ADVICE, DECLARE_PARENTS, - DECLARE_WARNING, DECLARE_ERROR, DECLARE_SOFT, CODE, ERROR }; + + + public static final Kind[] ALL = + { + PROJECT, + PACKAGE, + FILE, + FILE_JAVA, + FILE_ASPECTJ, + FILE_LST, + CLASS, + INTERFACE, + ASPECT, + INITIALIZER, + INTER_TYPE_FIELD, + INTER_TYPE_METHOD, + INTER_TYPE_CONSTRUCTOR, + INTER_TYPE_PARENT, + CONSTRUCTOR, + METHOD, + FIELD, + POINTCUT, + ADVICE, + DECLARE_PARENTS, + DECLARE_WARNING, + DECLARE_ERROR, + DECLARE_SOFT, + DECLARE_PRECEDENCE, + CODE, + ERROR }; public static Kind getKindForString(String kindString) { for (int i = 0; i < ALL.length; i++) { diff --git a/asm/src/org/aspectj/asm/IRelationship.java b/asm/src/org/aspectj/asm/IRelationship.java index b6377e832..9edb5c0e6 100644 --- a/asm/src/org/aspectj/asm/IRelationship.java +++ b/asm/src/org/aspectj/asm/IRelationship.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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 @@ -8,7 +7,7 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ @@ -24,9 +23,9 @@ public interface IRelationship extends Serializable { public String getName(); - public List getTargets(); + public List/*String*/ getTargets(); - public IProgramElement getSource(); + public String getSourceHandle(); public Kind getKind(); @@ -37,6 +36,7 @@ public interface IRelationship extends Serializable { public static final Kind ADVICE = new Kind("advice"); public static final Kind DECLARE = new Kind("declare"); + public static final Kind DECLARE_INTER_TYPE = new Kind("inter-type declaration"); public static final Kind[] ALL = { ADVICE, DECLARE }; private final String name; diff --git a/asm/src/org/aspectj/asm/IRelationshipMapper.java b/asm/src/org/aspectj/asm/IRelationshipMap.java index 747347222..b5a12e534 100644 --- a/asm/src/org/aspectj/asm/IRelationshipMapper.java +++ b/asm/src/org/aspectj/asm/IRelationshipMap.java @@ -18,18 +18,29 @@ import java.util.List; import org.aspectj.asm.IRelationship.Kind; /** - * Maps from a program element to a list of relationships between that element + * Maps from a program element handles 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. * + * The elemetns can be stored and looked up as IProgramElement(s), in which cases the + * element corresponding to the handle is looked up in the containment hierarchy. + * + * put/get methods taking IProgramElement as a parameter are for convenience only. + * They work identically to calling their counterparts with IProgramElement.getIdentifierHandle() + * * @author Mik Kersten */ -public interface IRelationshipMapper extends Serializable { +public interface IRelationshipMap extends Serializable { /** * @return an empty list if the element is not found. */ - public List get(IProgramElement source); + public List/*IRelationship*/ get(IProgramElement source); + + /** + * @return an empty list if the element is not found. + */ + public List/*IRelationship*/ get(String handle); /** * Return a relationship matching the kind and name for the given element. @@ -37,12 +48,21 @@ public interface IRelationshipMapper extends Serializable { * @return null if the relationship is not found. */ public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName); - - - public List/*IRelationship*/ get(String handle); + + /** + * Return a relationship matching the kind and name for the given element. + * Creates the relationship if not found. + * + * @return null if the relationship is not found. + */ + public IRelationship get(String source, IRelationship.Kind kind, String relationshipName); public void put(IProgramElement source, IRelationship relationship); + public void put(String handle, IRelationship relationship); + + public void remove(String handle, IRelationship relationship); + public void removeAll(String source); } diff --git a/asm/src/org/aspectj/asm/AspectJModel.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java index e8c723edc..6a523da11 100644 --- a/asm/src/org/aspectj/asm/AspectJModel.java +++ b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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 @@ -8,30 +7,29 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ -package org.aspectj.asm; +package org.aspectj.asm.internal; import java.io.*; import java.util.*; -import org.aspectj.asm.internal.ProgramElement; +import org.aspectj.asm.*; +import org.aspectj.asm.IProgramElement.Kind; import org.aspectj.bridge.*; /** * @author Mik Kersten */ -public class AspectJModel implements Serializable { +public class AspectJElementHierarchy implements IHierarchy { 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"); } @@ -64,43 +62,49 @@ public class AspectJModel implements Serializable { 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) { + public IProgramElement findElementForSignature(IProgramElement parent, IProgramElement.Kind kind, String signature) { for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) { IProgramElement node = (IProgramElement)it.next(); - if (node.getKind().equals(kind) - && name.equals(node.getName())) { + if (node.getKind() == kind && signature.equals(node.toSignatureString())) { return node; } else { - IProgramElement childSearch = findNode(node, kind, name); + IProgramElement childSearch = findElementForSignature(node, kind, signature); if (childSearch != null) return childSearch; } } return null; } - - /** - * - * @param signatureKey PackageName.TypeName.Signature.SourceLine.SourceColumn - */ - public IProgramElement findNodeForSignatureKey(String signatureKey) { - throw new RuntimeException("unimplemented"); - } - + + public IProgramElement findElementForLabel( + IProgramElement parent, + IProgramElement.Kind kind, + String label) { + + for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) { + IProgramElement node = (IProgramElement)it.next(); + if (node.getKind() == kind && label.equals(node.toLabelString())) { + return node; + } else { + IProgramElement childSearch = findElementForSignature(node, kind, label); + if (childSearch != null) return childSearch; + } + } + return null; + } + /** * @param packageName if null default package is searched * @param className can't be null */ - public IProgramElement findNodeForType(String packageName, String typeName) { + public IProgramElement findElementForType(String packageName, String typeName) { IProgramElement packageNode = null; if (packageName == null) { packageNode = root; @@ -153,10 +157,10 @@ public class AspectJModel implements Serializable { * @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) { + public IProgramElement findElementForSourceFile(String sourceFile) { try { if (!isValid() || sourceFile == null) { - return AspectJModel.NO_STRUCTURE; + return IHierarchy.NO_STRUCTURE; } else { String correctedPath = new File(sourceFile).getCanonicalPath();//.replace('\\', '/'); //StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model); @@ -168,15 +172,19 @@ public class AspectJModel implements Serializable { } } } catch (Exception e) { - return AspectJModel.NO_STRUCTURE; + return IHierarchy.NO_STRUCTURE; } } /** * TODO: discriminate columns */ - public IProgramElement findNodeForSourceLine(ISourceLocation location) { - return findNodeForSourceLine(location.getSourceFile().getAbsolutePath(), location.getLine()); + public IProgramElement findElementForSourceLine(ISourceLocation location) { + try { + return findElementForSourceLine(location.getSourceFile().getCanonicalPath(), location.getLine()); + } catch (Exception e) { + return null; + } } /** @@ -186,7 +194,7 @@ public class AspectJModel implements Serializable { * @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) { + public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber) { IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber); if (node != null) { return node; @@ -229,8 +237,7 @@ public class AspectJModel implements Serializable { // System.err.println("====\n1: " + // sourceFilePath + "\n2: " + // node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath) -// ); - +// ); return node != null && node.getSourceLocation() != null && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath) @@ -238,8 +245,7 @@ public class AspectJModel implements Serializable { && node.getSourceLocation().getEndLine() >= lineNumber) || (lineNumber <= 1 - && node instanceof IProgramElement - && ((IProgramElement)node).getKind().isSourceFileKind()) + && node.getKind().isSourceFileKind()) ); } catch (IOException ioe) { return false; @@ -261,5 +267,43 @@ public class AspectJModel implements Serializable { public void setConfigFile(String configFile) { this.configFile = configFile; } + + // TODO: optimize this lookup + public IProgramElement findElementForHandle(String handle) { + StringTokenizer st = new StringTokenizer(handle, IProgramElement.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 + return findElementForSourceLine(file, line); + +// 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 findElementForBytecodeInfo( +// IProgramElement node, +// String parentName, +// String name, +// String signature) { +// for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { +// IProgramElement curr = (IProgramElement)it.next(); +// if (parentName.equals(curr.getParent().getBytecodeName()) +// && name.equals(curr.getBytecodeName()) +// && signature.equals(curr.getBytecodeSignature())) { +// return node; +// } else { +// IProgramElement childSearch = findElementForBytecodeInfo(curr, parentName, name, signature); +// if (childSearch != null) return childSearch; +// } +// } +// return null; +// } } diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java index 9b2e3fdb0..ff509689d 100644 --- a/asm/src/org/aspectj/asm/internal/ProgramElement.java +++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java @@ -1,16 +1,19 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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.IOException; import java.util.*; import org.aspectj.asm.*; @@ -46,6 +49,11 @@ public class ProgramElement implements IProgramElement { private String bytecodeSignature; private String fullSignature; private String returnType; + + private List parameterNames = null; + private List parameterTypes = null; + + private String details = null; /** * Used during de-externalization. @@ -203,7 +211,7 @@ public class ProgramElement implements IProgramElement { } public String toString() { - return getName(); + return toLabelString(); } private static List genModifiers(int modifiers) { @@ -258,13 +266,13 @@ public class ProgramElement implements IProgramElement { this.bytecodeSignature = bytecodeSignature; } - public String getFullSignature() { - return fullSignature; - } - - public void setFullSignature(String string) { - fullSignature = string; - } +// public String getFullSignature() { +// return fullSignature; +// } +// +// public void setFullSignature(String string) { +// fullSignature = string; +// } public void setKind(Kind kind) { this.kind = kind; @@ -359,12 +367,70 @@ public class ProgramElement implements IProgramElement { this.modifiers = genModifiers(i); } - public String getSignatureKey() { - return packageName + '/' - + name + ':' - + sourceLocation.getLine() + ':' - + sourceLocation.getColumn(); + public String toSignatureString() { + StringBuffer sb = new StringBuffer(); + sb.append(name); + + if (parameterTypes != null ) { + sb.append('('); + for (Iterator it = parameterTypes.iterator(); it.hasNext(); ) { + sb.append((String)it.next()); + if (it.hasNext()) sb.append(", "); + } + sb.append(')'); + } + + return sb.toString(); } + public String toLabelString() { + String label = toSignatureString(); + if (details != null) { + label += ": " + details; + } + return label; + } + + public String getHandleIdentifier() { + try { + StringBuffer sb = new StringBuffer(); + if (sourceLocation == null) { + return null; + } else { + sb.append(sourceLocation.getSourceFile().getCanonicalPath()); + sb.append(ID_DELIM); + sb.append(sourceLocation.getLine()); + sb.append(ID_DELIM); + sb.append(sourceLocation.getColumn()); + return sb.toString(); + } + } catch (IOException ioe) { + return null; + } + } + + public List getParameterNames() { + return parameterNames; + } + + public List getParameterTypes() { + return parameterTypes; + } + + public void setParameterNames(List list) { + parameterNames = list; + } + + public void setParameterTypes(List list) { + parameterTypes = list; + } + + public String getDetails() { + return details; + } + + public void setDetails(String string) { + details = string; + } } diff --git a/asm/src/org/aspectj/asm/internal/Relationship.java b/asm/src/org/aspectj/asm/internal/Relationship.java index ef6d98683..cb9b97b60 100644 --- a/asm/src/org/aspectj/asm/internal/Relationship.java +++ b/asm/src/org/aspectj/asm/internal/Relationship.java @@ -1,11 +1,13 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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 * ******************************************************************/ @@ -25,18 +27,18 @@ public class Relationship implements IRelationship { private String name; private Kind kind; - private IProgramElement source; + private String sourceHandle; private List targets; public Relationship( String name, Kind kind, - IProgramElement source, + String sourceHandle, List targets) { this.name = name; this.kind = kind; - this.source = source; + this.sourceHandle = sourceHandle; this.targets = targets; } @@ -52,8 +54,8 @@ public class Relationship implements IRelationship { return name; } - public IProgramElement getSource() { - return source; + public String getSourceHandle() { + return sourceHandle; } public List getTargets() { diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMap.java b/asm/src/org/aspectj/asm/internal/RelationshipMap.java new file mode 100644 index 000000000..cd7e776c6 --- /dev/null +++ b/asm/src/org/aspectj/asm/internal/RelationshipMap.java @@ -0,0 +1,114 @@ +/* ******************************************************************* + * 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.util.*; + +import org.aspectj.asm.*; + +/** + * TODO: add a remove, and a clear all + * + * @author Mik Kersten + * + */ +public class RelationshipMap extends HashMap implements IRelationshipMap { + + private IHierarchy hierarchy; + + public RelationshipMap(IHierarchy hierarchy) { + this.hierarchy = hierarchy; + } + + public List get(String handle) { + List relationships = (List)super.get(handle); + if (relationships == null) { + return null; + } else { + return relationships; + } + } + + public List get(IProgramElement source) { + return get(source.getHandleIdentifier()); + } + + public IRelationship get(String source, IRelationship.Kind kind, String relationshipName) { + List relationships = get(source); + if (relationships == null) { + relationships = new ArrayList(); + IRelationship rel = new Relationship(relationshipName, kind, source, new ArrayList()); + relationships.add(rel); + super.put(source, relationships); + return rel; + } else { + for (Iterator it = relationships.iterator(); it.hasNext(); ) { + IRelationship curr = (IRelationship)it.next(); + if (curr.getKind() == kind && curr.getName().equals(relationshipName)) { + return curr; + } + } + } + return null; + } + + public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName) { + return get(source.getHandleIdentifier(), kind, relationshipName); + } + + public void remove(String source, IRelationship relationship) { + List list = (List)super.get(source); + if (list != null) { + 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.remove(relationship); + } + } + + public void removeAll(String source) { + List list = (List)super.remove(source); + } + + public void put(String source, IRelationship relationship) { + System.err.println(">> for: " + source + ", put::" + 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.getKind() == relationship.getKind()) { + curr.getTargets().addAll(relationship.getTargets()); + matched = true; + } + } + if (matched) list.add(relationship); + } + } + + public void put(IProgramElement source, IRelationship relationship) { + put(source.getHandleIdentifier(), relationship); + } + +} diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java deleted file mode 100644 index c3d1a5f4c..000000000 --- a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java +++ /dev/null @@ -1,90 +0,0 @@ -/* ******************************************************************* - * 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.util.*; - -import org.aspectj.asm.*; - -/** - * @author Mik Kersten - */ -public class RelationshipMapper extends HashMap implements IRelationshipMapper { - - public List get(IProgramElement source) { - List relationships = (List)super.get(source); - if (relationships == null) { - return Collections.EMPTY_LIST; - } else { - return relationships; - } - } - - /** - * @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) { - 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 static class RelationshipTable { - private IRelationship relationship; - private Map map; - - public RelationshipTable(IRelationship relationship) { - this.relationship = relationship; - map = new HashMap(); - } - - public Map getMap() { - return map; - } - - public IRelationship getRelationship() { - return relationship; - } - } - -} |