From: mkersten Date: Tue, 12 Aug 2003 10:23:30 +0000 (+0000) Subject: Minor improvements to structure model generation, clean up of test suite output,... X-Git-Tag: V1_1_1~98 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1e0113299d9eea6272c7b83b40d95b808076a028;p=aspectj.git Minor improvements to structure model generation, clean up of test suite output, and port of AJDT to new ASM APIs. --- diff --git a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java index 6ed175fed..c11db4399 100644 --- a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java +++ b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java @@ -102,7 +102,7 @@ public class BrowserManager { AjdeUIManager.getDefault().getOptionsFrame().addOptionsPanel(new BrowserOptionsPanel()); - StructureModelManager.getDefault().addListener(VIEW_LISTENER); + AsmManager.getDefault().addListener(VIEW_LISTENER); //String lastOpenFilePath = browserProjectProperties.getLastOpenSourceFilePath(); //editorManager.showSourceLine(lastOpenFilePath, 1, false); diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java new file mode 100644 index 000000000..dda0ab096 --- /dev/null +++ b/asm/src/org/aspectj/asm/AsmManager.java @@ -0,0 +1,175 @@ +/* ******************************************************************* + * 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.*; + +/** + * @author Mik Kersten + */ +public class AsmManager { + + /** + * @deprecated use getDefault() method instead + */ + private static AsmManager INSTANCE = new AsmManager(); + private boolean shouldSaveModel = true; + protected StructureModel model = new StructureModel(); + private List structureListeners = new ArrayList(); + private IRelationshipMapper mapper; + + protected AsmManager() { + List relationships = new ArrayList(); +// relationships.add(ADVICE); + mapper = new RelationshipMapper(); + } + + public StructureModel getModel() { + return model; + } + + public void fireModelUpdated() { + notifyListeners(); + if (model.getConfigFile() != null) { + writeStructureModel(model.getConfigFile()); + } + } + + /** + * Constructs map each time it's called. + */ + public HashMap getInlineAnnotations( + String sourceFile, + boolean showSubMember, + boolean showMemberAndType) { + + throw new RuntimeException("unimplemented"); + +// if (!model.isValid()) return null; +// +// HashMap annotations = new HashMap(); +// IProgramElement node = model.findRootNodeForSourceFile(sourceFile); +// if (node == StructureModel.NO_STRUCTURE) { +// return null; +// } else { +// IProgramElement fileNode = (IProgramElement)node; +// ArrayList peNodes = new ArrayList(); +// getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType); +// for (Iterator it = peNodes.iterator(); it.hasNext(); ) { +// IProgramElement peNode = (IProgramElement)it.next(); +// List entries = new ArrayList(); +// entries.add(peNode); +// ISourceLocation sourceLoc = peNode.getSourceLocation(); +// if (null != sourceLoc) { +// Integer hash = new Integer(sourceLoc.getLine()); +// List existingEntry = (List)annotations.get(hash); +// if (existingEntry != null) { +// entries.addAll(existingEntry); +// } +// annotations.put(hash, entries); +// } +// } +// return annotations; +// } + } + +// private void getAllStructureChildren(IProgramElement node, List result, boolean showSubMember, boolean showMemberAndType) { +// List children = node.getChildren(); +// for (Iterator it = children.iterator(); it.hasNext(); ) { +// IProgramElement next = (IProgramElement)it.next(); +// if (next instanceof IProgramElement) { +// IProgramElement pNode = (IProgramElement)next; +// if (pNode != null +// && ((pNode.isCode() && showSubMember) || (!pNode.isCode() && showMemberAndType)) +// && pNode.getRelations() != null +// && pNode.getRelations().size() > 0) { +// result.add(next); +// } +// getAllStructureChildren((IProgramElement)next, result, showSubMember, showMemberAndType); +// } +// } +// } + + public void addListener(IStructureModelListener listener) { + structureListeners.add(listener); + } + + public void removeStructureListener(IStructureModelListener listener) { + structureListeners.remove(listener); + } + + private void notifyListeners() { + for (Iterator it = structureListeners.iterator(); it.hasNext(); ) { + ((IStructureModelListener)it.next()).containmentHierarchyUpdated(model); + } + } + + /** + * Fails silently. + */ + public void writeStructureModel(String configFilePath) { + try { + String filePath = genExternFilePath(configFilePath); + ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(filePath)); + s.writeObject(model); + s.flush(); + } catch (Exception e) { + // ignore + } + } + + /** + * @todo add proper handling of bad paths/suffixes/etc + * @param configFilePath path to an ".lst" file + */ + public void readStructureModel(String configFilePath) { + try { + if (configFilePath == null) { + model.setRoot(StructureModel.NO_STRUCTURE); + } else { + String filePath = genExternFilePath(configFilePath); + FileInputStream in = new FileInputStream(filePath); + ObjectInputStream s = new ObjectInputStream(in); + model = (StructureModel)s.readObject(); + } + } catch (Exception e) { + //System.err.println("AJDE Message: could not read structure model: " + e); + model.setRoot(StructureModel.NO_STRUCTURE); + } finally { + notifyListeners(); + } + } + + private String genExternFilePath(String configFilePath) { + return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym"; + } + + 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/IProgramElement.java b/asm/src/org/aspectj/asm/IProgramElement.java index 8cde25862..ced44fa7e 100644 --- a/asm/src/org/aspectj/asm/IProgramElement.java +++ b/asm/src/org/aspectj/asm/IProgramElement.java @@ -23,46 +23,63 @@ import org.aspectj.bridge.*; public interface IProgramElement extends Serializable { public List/*IProgramElement*/ getChildren(); + + public void setChildren(List children); public void addChild(IProgramElement child); - public Kind getKind(); + + public IProgramElement getParent(); + public void setParent(IProgramElement parent); + + public String getName(); + public void setName(String name); + + public IProgramElement.Kind getKind(); + public void setKind(Kind kind); + public List getModifiers(); + public void setModifiers(int i); + public Accessibility getAccessibility(); - public String getDeclaringType(); + + public String getDeclaringType(); // TODO: remove (Emacs uses it) public String getPackageName(); - public String getSignature(); - public String getName(); - public boolean isCode(); - public boolean isMemberKind(); + + public void setReturnType(String returnType); + public String getReturnType(); + + public String getFullSignature(); + public void setFullSignature(String string); + public void setRunnable(boolean value); public boolean isRunnable(); + public boolean isImplementor(); public void setImplementor(boolean value); + public boolean isOverrider(); public void setOverrider(boolean value); - public List getRelations(); - public void setRelations(List relations); - public String getFormalComment(); + + public IMessage getMessage(); + public void setMessage(IMessage message); + + public ISourceLocation getSourceLocation(); + public void setSourceLocation(ISourceLocation sourceLocation); + public String toString(); + + // public String getHandle() TODO: check IJavaElement + + /** + * @return a string representation of this node and all of its children (recursive) + */ + public String toLongString(); + public String getBytecodeName(); public String getBytecodeSignature(); public void setBytecodeName(String bytecodeName); public void setBytecodeSignature(String bytecodeSignature); - public String getFullSignature(); - public void setFullSignature(String string); - public void setKind(Kind kind); - public void setReturnType(String returnType); - public String getReturnType(); - public ISourceLocation getSourceLocation(); - public void setSourceLocation(ISourceLocation sourceLocation); - public IMessage getMessage(); - public void setMessage(IMessage message); - public IProgramElement getParent(); - public void setParent(IProgramElement parent); + public IProgramElement walk(HierarchyWalker walker); - public void setName(String name); - public void setChildren(List children); - public void setModifiers(int i); -// public String getSignatureKey(); /** * Uses "typesafe enum" pattern. diff --git a/asm/src/org/aspectj/asm/IRelationshipMapper.java b/asm/src/org/aspectj/asm/IRelationshipMapper.java index d27aec8d3..ab8fffd34 100644 --- a/asm/src/org/aspectj/asm/IRelationshipMapper.java +++ b/asm/src/org/aspectj/asm/IRelationshipMapper.java @@ -21,17 +21,15 @@ import org.aspectj.asm.IRelationship.Kind; * @author Mik Kersten */ public interface IRelationshipMapper extends Serializable { - -// public List getRelationshipsForElement(String source, IRelationship relationship); -// -// public void putRelationshipForElement(String source, IRelationship relationship, List targets); -// -// public void putRelationshipForElement(String source, IRelationship kind, String target); + // TODO: return a list public IRelationship get(IProgramElement source); - -// public void putRelationshipForElement(IProgramElement source, IRelationship relationship, List targets); - + + // TODO: return a list + public IRelationship get(String handle); + public void put(IProgramElement source, IRelationship relationship); + + } diff --git a/asm/src/org/aspectj/asm/StructureModel.java b/asm/src/org/aspectj/asm/StructureModel.java index 60f48edcb..36318a2e5 100644 --- a/asm/src/org/aspectj/asm/StructureModel.java +++ b/asm/src/org/aspectj/asm/StructureModel.java @@ -18,7 +18,7 @@ import java.io.*; import java.util.*; import org.aspectj.asm.internal.ProgramElement; -import org.aspectj.bridge.SourceLocation; +import org.aspectj.bridge.*; /** * @author Mik Kersten @@ -32,6 +32,10 @@ public class StructureModel implements Serializable { public static final IProgramElement NO_STRUCTURE = new ProgramElement("", IProgramElement.Kind.ERROR, null); + public IProgramElement getElement(String handle) { + throw new RuntimeException("unimplemented"); + } + public IProgramElement getRoot() { return root; } @@ -40,21 +44,18 @@ public class StructureModel implements Serializable { this.root = root; } - private Map getFileMap() { - return fileMap; - } - 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 void setFileMap(HashMap fileMap) { - this.fileMap = fileMap; - } public Set getFileMapEntrySet() { return fileMap.entrySet(); @@ -64,6 +65,7 @@ public class StructureModel implements Serializable { return root != null && fileMap != null; } + /** * Returns the first match * @@ -86,8 +88,12 @@ public class StructureModel implements Serializable { return null; } + /** + * + * @param signatureKey PackageName.TypeName.Signature.SourceLine.SourceColumn + */ public IProgramElement findNodeForSignatureKey(String signatureKey) { - return null; + throw new RuntimeException("unimplemented"); } /** @@ -166,6 +172,13 @@ public class StructureModel implements Serializable { } } + /** + * TODO: discriminate columns + */ + public IProgramElement findNodeForSourceLine(ISourceLocation location) { + return findNodeForSourceLine(location.getSourceFile().getAbsolutePath(), location.getLine()); + } + /** * Never returns null * @@ -174,8 +187,7 @@ public class StructureModel implements Serializable { * @return a new structure node for the file if it was not found in the model */ public IProgramElement findNodeForSourceLine(String sourceFilePath, int lineNumber) { - String correctedPath = sourceFilePath;//.replace('\\', '/'); - IProgramElement node = findNodeForSourceLineHelper(root, correctedPath, lineNumber); + IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber); if (node != null) { return node; } else { @@ -224,7 +236,7 @@ public class StructureModel implements Serializable { && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath) && ((node.getSourceLocation().getLine() <= lineNumber && node.getSourceLocation().getEndLine() >= lineNumber) - || + || (lineNumber <= 1 && node instanceof IProgramElement && ((IProgramElement)node).getKind().isSourceFileKind()) @@ -249,6 +261,5 @@ public class StructureModel implements Serializable { public void setConfigFile(String configFile) { this.configFile = configFile; } - } diff --git a/asm/src/org/aspectj/asm/StructureModelManager.java b/asm/src/org/aspectj/asm/StructureModelManager.java deleted file mode 100644 index 1e966bb01..000000000 --- a/asm/src/org/aspectj/asm/StructureModelManager.java +++ /dev/null @@ -1,176 +0,0 @@ -/* ******************************************************************* - * 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.*; - -/** - * @author Mik Kersten - */ -public class StructureModelManager { - - /** - * @deprecated use getDefault() method instead - */ - public static StructureModelManager INSTANCE = new StructureModelManager(); - private boolean shouldSaveModel = true; - protected StructureModel model = new StructureModel(); - private List structureListeners = new ArrayList(); - - private IRelationshipMapper mapper; -// public static final IRelationship ADVICE = new Relationship("advises", "advised by", IRelationship.Kind.ADVICE); - - protected StructureModelManager() { - List relationships = new ArrayList(); -// relationships.add(ADVICE); - mapper = new RelationshipMapper(); - } - - public StructureModel getModel() { - return model; - } - - public void fireModelUpdated() { - notifyListeners(); - if (model.getConfigFile() != null) { - writeStructureModel(model.getConfigFile()); - } - } - - /** - * Constructs map each time it's called. - */ - public HashMap getInlineAnnotations( - String sourceFile, - boolean showSubMember, - boolean showMemberAndType) { - - throw new RuntimeException("unimplemented"); - -// if (!model.isValid()) return null; -// -// HashMap annotations = new HashMap(); -// IProgramElement node = model.findRootNodeForSourceFile(sourceFile); -// if (node == StructureModel.NO_STRUCTURE) { -// return null; -// } else { -// IProgramElement fileNode = (IProgramElement)node; -// ArrayList peNodes = new ArrayList(); -// getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType); -// for (Iterator it = peNodes.iterator(); it.hasNext(); ) { -// IProgramElement peNode = (IProgramElement)it.next(); -// List entries = new ArrayList(); -// entries.add(peNode); -// ISourceLocation sourceLoc = peNode.getSourceLocation(); -// if (null != sourceLoc) { -// Integer hash = new Integer(sourceLoc.getLine()); -// List existingEntry = (List)annotations.get(hash); -// if (existingEntry != null) { -// entries.addAll(existingEntry); -// } -// annotations.put(hash, entries); -// } -// } -// return annotations; -// } - } - -// private void getAllStructureChildren(IProgramElement node, List result, boolean showSubMember, boolean showMemberAndType) { -// List children = node.getChildren(); -// for (Iterator it = children.iterator(); it.hasNext(); ) { -// IProgramElement next = (IProgramElement)it.next(); -// if (next instanceof IProgramElement) { -// IProgramElement pNode = (IProgramElement)next; -// if (pNode != null -// && ((pNode.isCode() && showSubMember) || (!pNode.isCode() && showMemberAndType)) -// && pNode.getRelations() != null -// && pNode.getRelations().size() > 0) { -// result.add(next); -// } -// getAllStructureChildren((IProgramElement)next, result, showSubMember, showMemberAndType); -// } -// } -// } - - public void addListener(IStructureModelListener listener) { - structureListeners.add(listener); - } - - public void removeStructureListener(IStructureModelListener listener) { - structureListeners.remove(listener); - } - - private void notifyListeners() { - for (Iterator it = structureListeners.iterator(); it.hasNext(); ) { - ((IStructureModelListener)it.next()).containmentHierarchyUpdated(model); - } - } - - /** - * Fails silently. - */ - public void writeStructureModel(String configFilePath) { - try { - String filePath = genExternFilePath(configFilePath); - ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(filePath)); - s.writeObject(model); - s.flush(); - } catch (Exception e) { - // ignore - } - } - - /** - * @todo add proper handling of bad paths/suffixes/etc - * @param configFilePath path to an ".lst" file - */ - public void readStructureModel(String configFilePath) { - try { - if (configFilePath == null) { - model.setRoot(StructureModel.NO_STRUCTURE); - } else { - String filePath = genExternFilePath(configFilePath); - FileInputStream in = new FileInputStream(filePath); - ObjectInputStream s = new ObjectInputStream(in); - model = (StructureModel)s.readObject(); - } - } catch (Exception e) { - //System.err.println("AJDE Message: could not read structure model: " + e); - model.setRoot(StructureModel.NO_STRUCTURE); - } finally { - notifyListeners(); - } - } - - private String genExternFilePath(String configFilePath) { - return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym"; - } - - public void setShouldSaveModel(boolean shouldSaveModel) { - this.shouldSaveModel = shouldSaveModel; - } - - public static StructureModelManager getDefault() { - return INSTANCE; - } - public IRelationshipMapper getMapper() { - return mapper; - } - -} - diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java index 9562169cd..9b2e3fdb0 100644 --- a/asm/src/org/aspectj/asm/internal/ProgramElement.java +++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java @@ -121,7 +121,7 @@ public class ProgramElement implements IProgramElement { } public String getPackageName() { - if (kind == Kind.PACKAGE) return getSignature(); + if (kind == Kind.PACKAGE) return getName(); if (getParent() == null || !(getParent() instanceof IProgramElement)) { return ""; } @@ -132,10 +132,6 @@ public class ProgramElement implements IProgramElement { return kind; } - public String getSignature() { - return name; - } - public boolean isCode() { return kind.equals(Kind.CODE); } diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java index 706a5603b..e794b76e0 100644 --- a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java +++ b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java @@ -25,12 +25,15 @@ public class RelationshipMapper extends HashMap implements IRelationshipMapper { return (IRelationship)super.get(source); } - /** - * Creates the relationship if not present. - */ + public IRelationship get(String handle) { + throw new RuntimeException("unimplemented"); + } + public void put(IProgramElement source, IRelationship relationship) { super.put(source, relationship); } + + // TODO: add a remove, and a clear all private static class RelationshipTable { private IRelationship relationship; @@ -49,4 +52,5 @@ public class RelationshipMapper extends HashMap implements IRelationshipMapper { return relationship; } } + } diff --git a/docs/developer/asm.doc b/docs/developer/asm.doc index 608f8dca5..693bf5f06 100644 Binary files a/docs/developer/asm.doc and b/docs/developer/asm.doc differ