diff options
Diffstat (limited to 'asm')
23 files changed, 2226 insertions, 0 deletions
diff --git a/asm/.classpath b/asm/.classpath new file mode 100644 index 000000000..5781c41ae --- /dev/null +++ b/asm/.classpath @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="testsrc"/> + <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> + <classpathentry kind="src" path="/bridge"/> + <classpathentry kind="lib" path="/lib/junit/junit.jar" sourcepath="/lib/junit/junit-src.jar"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/asm/.project b/asm/.project new file mode 100644 index 000000000..93d2ed706 --- /dev/null +++ b/asm/.project @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>asm</name> + <comment></comment> + <projects> + <project>bridge</project> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/asm/src/.cvsignore b/asm/src/.cvsignore new file mode 100644 index 000000000..edd86b356 --- /dev/null +++ b/asm/src/.cvsignore @@ -0,0 +1,2 @@ +asm.lst +asmSrc.lst diff --git a/asm/src/org/aspectj/asm/AdviceAssociation.java b/asm/src/org/aspectj/asm/AdviceAssociation.java new file mode 100644 index 000000000..c1914630d --- /dev/null +++ b/asm/src/org/aspectj/asm/AdviceAssociation.java @@ -0,0 +1,191 @@ +/* ******************************************************************* + * 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.util.*; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class AdviceAssociation implements Association { + + public static final String NAME = "Advice"; + public static final Relation METHOD_RELATION = new Relation("affects methods", "method affected by", NAME, true, false); + public static final Relation METHOD_CALL_SITE_RELATION = new Relation("affects method call sites", "method call site affected by", NAME, true, false); + public static final Relation CONSTRUCTOR_RELATION = new Relation("affects constructors", "constructor affected by", NAME, true, false); + public static final Relation CONSTRUCTOR_CALL_SITE_RELATION = new Relation("affects constructions", "construction affected by", NAME, true, false); + public static final Relation HANDLER_RELATION = new Relation("affects handlers", "handler affected by", NAME, true, false); + public static final Relation INITIALIZER_RELATION = new Relation("affects initializers", "initializer affected by", NAME, true, false); + public static final Relation FIELD_ACCESS_RELATION = new Relation("affects field access", "field access affected by", NAME, true, false); + public static final Relation INTRODUCTION_RELATION = new Relation("affects introduction", "introduction affected by", NAME, true, false); + + private List relations = new ArrayList(); + + public AdviceAssociation() { + relations.add(METHOD_RELATION); + relations.add(METHOD_CALL_SITE_RELATION); + relations.add(CONSTRUCTOR_RELATION); + relations.add(CONSTRUCTOR_CALL_SITE_RELATION); + relations.add(HANDLER_RELATION); + relations.add(INITIALIZER_RELATION); + relations.add(FIELD_ACCESS_RELATION); + relations.add(INTRODUCTION_RELATION); + } + + public List getRelations() { + return relations; + } + + public List getRelationNodes() { + List relations = new ArrayList(); + List methods = new ArrayList(); + List methodCallSites = new ArrayList(); + List constructors = new ArrayList(); + List constructorCallSites = new ArrayList(); + List handlers = new ArrayList(); + List initializers = new ArrayList(); + List fieldAccesses = new ArrayList(); + List introductions = new ArrayList(); +// Set forwardCorrs = StructureModelManager.correspondences.getAffects(astObject); +// Set backCorrs = StructureModelManager.correspondences.getAffectedBy(astObject); +// +// if (astObject instanceof AdviceDec) { +// for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) { +// ASTObject node = (ASTObject)it.next(); +// LinkNode link = StructureNodeFactory.makeLink(node, false); +// if (node instanceof MethodDec) { +// if (((MethodDec)node).isSynthetic()) { +// ASTObject resolvedNode = resolveSyntheticMethodToIntroduction((MethodDec)node); +// introductions.add(StructureNodeFactory.makeLink(resolvedNode, false)); +// } else { +// methods.add(link); +// } +// } else if (node instanceof CallExpr) { +// methodCallSites.add(link); +// } else if (node instanceof ConstructorDec) { +// constructors.add(link); +// } else if (node instanceof NewInstanceExpr) { +// constructorCallSites.add(link); +// } else if (node instanceof CatchClause) { +// handlers.add(link); +// } else if (node instanceof InitializerDec) { +// initializers.add(link); +// } else if (node instanceof FieldDec) { +// fieldAccesses.add(link); +// } else if (node instanceof BasicAssignExpr || node instanceof FieldAccessExpr) { +// fieldAccesses.add(link); +// } +// } +// if (!methods.isEmpty()) relations.add(new RelationNode(METHOD_RELATION, METHOD_RELATION.getForwardNavigationName(), methods)); +// if (!methodCallSites.isEmpty()) relations.add(new RelationNode(METHOD_RELATION, METHOD_CALL_SITE_RELATION.getForwardNavigationName(), methodCallSites)); +// if (!constructors.isEmpty()) relations.add(new RelationNode(CONSTRUCTOR_RELATION, CONSTRUCTOR_RELATION.getForwardNavigationName(), constructors)); +// if (!constructorCallSites.isEmpty()) relations.add(new RelationNode(CONSTRUCTOR_CALL_SITE_RELATION, CONSTRUCTOR_CALL_SITE_RELATION.getForwardNavigationName(), constructorCallSites)); +// if (!handlers.isEmpty()) relations.add(new RelationNode(HANDLER_RELATION, HANDLER_RELATION.getForwardNavigationName(), handlers)); +// if (!initializers.isEmpty()) relations.add(new RelationNode(INITIALIZER_RELATION, INITIALIZER_RELATION.getForwardNavigationName(), initializers)); +// if (!fieldAccesses.isEmpty()) relations.add(new RelationNode(FIELD_ACCESS_RELATION, FIELD_ACCESS_RELATION.getForwardNavigationName(), fieldAccesses)); +// if (!introductions.isEmpty()) relations.add(new RelationNode(INTRODUCTION_RELATION, INTRODUCTION_RELATION.getForwardNavigationName(), introductions)); +// } else { +// if (astObject instanceof IntroducedDec) { +// Set adviceDecs = resolveAdviceAffectingIntroduction((IntroducedDec)astObject); +// if (adviceDecs != null) { +// for (Iterator adIt = adviceDecs.iterator(); adIt.hasNext(); ) { +// introductions.add(StructureNodeFactory.makeLink((ASTObject)adIt.next(), false)); +// } +// } +// } +// +// for (Iterator it = backCorrs.iterator(); it.hasNext(); ) { +// ASTObject node = (ASTObject)it.next(); +// if (node instanceof AdviceDec) { +// if (astObject instanceof MethodDec) { +// methods.add(StructureNodeFactory.makeLink(node, false)); +// } else if (astObject instanceof CallExpr) { +// methodCallSites.add(StructureNodeFactory.makeLink(node, false)); +// } else if (astObject instanceof ConstructorDec) { +// constructors.add(StructureNodeFactory.makeLink(node, false)); +// } else if (astObject instanceof NewInstanceExpr) { +// constructorCallSites.add(StructureNodeFactory.makeLink(node, false)); +// } else if (astObject instanceof CatchClause) { +// handlers.add(StructureNodeFactory.makeLink(node, false)); +// } else if (astObject instanceof InitializerDec) { +// initializers.add(StructureNodeFactory.makeLink(node, false)); +// } else if (astObject instanceof FieldDec) { +// fieldAccesses.add(StructureNodeFactory.makeLink(node, false)); +// } else if (astObject instanceof BasicAssignExpr +// || astObject instanceof FieldAccessExpr) { +// fieldAccesses.add(StructureNodeFactory.makeLink(node, false)); +// } +// } +// } +// if (!methods.isEmpty()) relations.add(new RelationNode(METHOD_RELATION, METHOD_RELATION.getBackNavigationName(), methods)); +// if (!methodCallSites.isEmpty()) relations.add(new RelationNode(METHOD_CALL_SITE_RELATION, METHOD_CALL_SITE_RELATION.getBackNavigationName(), methodCallSites)); +// if (!constructors.isEmpty()) relations.add(new RelationNode(CONSTRUCTOR_RELATION, CONSTRUCTOR_RELATION.getBackNavigationName(), constructors)); +// if (!constructorCallSites.isEmpty()) relations.add(new RelationNode(CONSTRUCTOR_CALL_SITE_RELATION, CONSTRUCTOR_CALL_SITE_RELATION.getBackNavigationName(), constructorCallSites)); +// if (!handlers.isEmpty()) relations.add(new RelationNode(HANDLER_RELATION, HANDLER_RELATION.getBackNavigationName(), handlers)); +// if (!initializers.isEmpty()) relations.add(new RelationNode(INITIALIZER_RELATION, INITIALIZER_RELATION.getBackNavigationName(), initializers)); +// if (!fieldAccesses.isEmpty()) relations.add(new RelationNode(FIELD_ACCESS_RELATION, FIELD_ACCESS_RELATION.getBackNavigationName(), fieldAccesses)); +// if (!introductions.isEmpty()) relations.add(new RelationNode(INTRODUCTION_RELATION, INTRODUCTION_RELATION.getBackNavigationName(), introductions)); +// } + return relations; + } + + public String getName() { + return NAME; + } + +// /** +// * @todo HACK: this search and hacked name-match should be replace by a fix to the correspondeces db +// */ +// private ASTObject resolveSyntheticMethodToIntroduction(MethodDec node) { +// Set backCorrs = StructureModelManager.correspondences.getAffectedBy(node.getDeclaringType().getTypeDec()); +// Method method = node.getMethod(); +// String name = method.getDeclaringType().getName() + '.' + method.getName(); +// for (Iterator it = backCorrs.iterator(); it.hasNext(); ) { +// Object next = it.next(); +// if (next instanceof IntroducedDec) { +// IntroducedDec introducedDec = (IntroducedDec)next; +// if (name.equals(introducedDec.toShortString())) return introducedDec; +// } +// } +// return node; +// } + +// /** +// * @todo HACK: this search and hacked name-match should be replace by a fix to the correspondeces db +// */ +// private Set resolveAdviceAffectingIntroduction(IntroducedDec node) { +// Set forwardCorrs = StructureModelManager.correspondences.getAffects(node); +// String name = node.getId(); +// for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) { +// Object next = it.next(); +// if (next instanceof TypeDec) { +// TypeDec typeDec = (TypeDec)next; +// List decs = typeDec.getBody().getList(); +// for (Iterator it2 = decs.iterator(); it2.hasNext(); ) { +// Dec bodyDec = (Dec)it2.next(); +// if (bodyDec != null && !(bodyDec instanceof InitializerDec)) { +// if (bodyDec instanceof MethodDec && bodyDec.isSynthetic() && name.equals(bodyDec.getName())) { +// MethodDec methodDec = (MethodDec)bodyDec; +// return StructureModelManager.correspondences.getAffectedBy(methodDec); +// } +// } +// } +// } +// } +// return null; +// } +} + diff --git a/asm/src/org/aspectj/asm/Association.java b/asm/src/org/aspectj/asm/Association.java new file mode 100644 index 000000000..c0431d694 --- /dev/null +++ b/asm/src/org/aspectj/asm/Association.java @@ -0,0 +1,30 @@ +/* ******************************************************************* + * 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.util.List; + +/** + * @author Mik Kersten + */ +public interface Association { + + public List getRelations(); + + // XXX used ASTObject parameter + public List getRelationNodes(); + + public String getName(); +} diff --git a/asm/src/org/aspectj/asm/InheritanceAssociation.java b/asm/src/org/aspectj/asm/InheritanceAssociation.java new file mode 100644 index 000000000..fd3d446d9 --- /dev/null +++ b/asm/src/org/aspectj/asm/InheritanceAssociation.java @@ -0,0 +1,102 @@ +/* ******************************************************************* + * 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.util.*; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class InheritanceAssociation implements Association { + public static final String NAME = "Inheritance"; + public static final Relation INHERITS_RELATION = new Relation("inherits", "is inherited by", NAME, true, true); + public static final Relation IMPLEMENTS_RELATION = new Relation("implements", "is implemented by", NAME, true, true); + public static final Relation INHERITS_MEMBERS_RELATION = new Relation("inherits members", NAME, false); + private List relations = new ArrayList(); + + public InheritanceAssociation() { + relations.add(INHERITS_RELATION); + relations.add(IMPLEMENTS_RELATION); + relations.add(INHERITS_MEMBERS_RELATION); + } + + public List getRelations() { + return relations; + } + + public List getRelationNodes() { + List relations = new ArrayList(); +// if (astObject instanceof TypeDec) { +// TypeDec typeDec = (TypeDec)astObject; +// boolean isInterface = (astObject instanceof InterfaceDec); +// List superTypes = getTypeLinks(typeDec.getType().getDirectSuperTypes(), true, isInterface); +// List subTypes = getTypeLinks(typeDec.getType().getDirectSubTypes(), true, isInterface); +// if (!superTypes.isEmpty()) relations.add(new RelationNode(INHERITS_RELATION, INHERITS_RELATION.getForwardNavigationName(), superTypes)); +// if (!subTypes.isEmpty()) relations.add(new RelationNode(INHERITS_RELATION, INHERITS_RELATION.getBackNavigationName(), subTypes)); +// +// List implementedInterfaces = getTypeLinks(typeDec.getType().getDirectSuperTypes(), false, isInterface); +// List implementors = getTypeLinks(typeDec.getType().getDirectSubTypes(), false, isInterface); +// if (!implementedInterfaces.isEmpty()) relations.add(new RelationNode(IMPLEMENTS_RELATION, IMPLEMENTS_RELATION.getForwardNavigationName(), implementedInterfaces)); +// if (!implementors.isEmpty()) relations.add(new RelationNode(IMPLEMENTS_RELATION, IMPLEMENTS_RELATION.getBackNavigationName(), implementors)); +// +// List inheritedMembers = new ArrayList(getMemberLinks(typeDec.getType().getInheritedMethods())); +// if (!inheritedMembers.isEmpty()) relations.add(new RelationNode(INHERITS_MEMBERS_RELATION, INHERITS_MEMBERS_RELATION.getForwardNavigationName(), inheritedMembers)); +// } + return relations; + } + +// private List getTypeLinks(Collection types, boolean isInheritance, boolean isInterface) { +// List links = new ArrayList(); +// if (types != null) { +// for (Iterator it = types.iterator(); it.hasNext(); ) { +// NameType nameType = (NameType)it.next(); +// if (!nameType.getId().equals("Object")) { +// if (isInheritance && ((isInterface && nameType.isInterface()) || (!isInterface && !nameType.isInterface())) +// || !isInheritance && (!isInterface && nameType.isInterface())) { +// Dec dec = nameType.getCorrespondingDec(); +// links.add(StructureNodeFactory.makeLink(dec, false)); +// } +// } +// } +// } +// return links; +// } + +// private List getMemberLinks(Collection members) { +// List links = new ArrayList(); +// if (members != null) { +// for (Iterator it = members.iterator(); it.hasNext(); ) { +// Object object = it.next(); +// if (object instanceof Method) { +// Method method = (Method)object; +// if (!method.getDeclaringType().getId().equals("Object")) { +// links.add(StructureNodeFactory.makeLink(method.getCorrespondingDec(), false)); +// } +// } else if (object instanceof Field) { +// Field field = (Field)object; +// if (!field.getDeclaringType().getId().equals("Object")) { +// links.add(StructureNodeFactory.makeLink(field.getCorrespondingDec(), false)); +// } +// } +// } +// } +// return links; +// } + + public String getName() { + return NAME; + } +} diff --git a/asm/src/org/aspectj/asm/IntroductionAssociation.java b/asm/src/org/aspectj/asm/IntroductionAssociation.java new file mode 100644 index 000000000..2d55abb9d --- /dev/null +++ b/asm/src/org/aspectj/asm/IntroductionAssociation.java @@ -0,0 +1,67 @@ +/* ******************************************************************* + * 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.util.*; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class IntroductionAssociation implements Association { + public static final String NAME = "Introduction"; + public static final Relation INTRODUCES_RELATION = new Relation("declares member on", "inter-type declared members", NAME, true, false); + private List relations = new ArrayList(); + + public IntroductionAssociation() { + relations.add(INTRODUCES_RELATION); + } + + public List getRelations() { + return relations; + } + + public List getRelationNodes() { + List relations = new ArrayList(); + List introduces = new ArrayList(); +// Set forwardCorrs = StructureModelManager.correspondences.getAffects(astObject); +// Set backCorrs = StructureModelManager.correspondences.getAffectedBy(astObject); +// if (astObject instanceof IntroducedDec) { +// for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) { +// ASTObject node = (ASTObject)it.next(); +// LinkNode link = StructureNodeFactory.makeLink(node, false); +// if (node instanceof TypeDec) { +// introduces.add(link); +// } +// } +// if (!introduces.isEmpty()) relations.add(new RelationNode(INTRODUCES_RELATION, INTRODUCES_RELATION.getForwardNavigationName(), introduces)); +// } else { +// for (Iterator it = backCorrs.iterator(); it.hasNext(); ) { +// ASTObject node = (ASTObject)it.next(); +// if (astObject instanceof TypeDec) { +// if (node instanceof IntroducedDec) { +// introduces.add(StructureNodeFactory.makeLink(node, false)); +// } +// } +// } +// if (!introduces.isEmpty()) relations.add(new RelationNode(INTRODUCES_RELATION, INTRODUCES_RELATION.getBackNavigationName(), introduces)); +// } + return relations; + } + + public String getName() { + return NAME; + } +} diff --git a/asm/src/org/aspectj/asm/LinkNode.java b/asm/src/org/aspectj/asm/LinkNode.java new file mode 100644 index 000000000..72f02cb1b --- /dev/null +++ b/asm/src/org/aspectj/asm/LinkNode.java @@ -0,0 +1,54 @@ +/* ******************************************************************* + * 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; + + +/** + * @author Mik Kersten + */ +public class LinkNode extends StructureNode { + + private ProgramElementNode programElementNode = null; + + /** + * Used during de-serialization. + */ + public LinkNode() { } + + /** + * @param node can not be null + */ + public LinkNode(ProgramElementNode node) { + super(node.getSignature().toString(), "internal", null); + this.programElementNode = node; + } + + public ProgramElementNode getProgramElementNode() { + return programElementNode; + } + + public String toString() { + String name = ""; + if (programElementNode.getProgramElementKind().equals(ProgramElementNode.Kind.ADVICE) || + programElementNode.getProgramElementKind().equals(ProgramElementNode.Kind.INTRODUCTION) || + programElementNode.getProgramElementKind().equals(ProgramElementNode.Kind.CODE)) { + return programElementNode.parent.toString() + ": " + programElementNode.getName(); + } else if (programElementNode.isMemberKind()) { + return programElementNode.parent.toString() + '.' + programElementNode.getName(); + } else { + return programElementNode.toString(); + } + } +} diff --git a/asm/src/org/aspectj/asm/ModelWalker.java b/asm/src/org/aspectj/asm/ModelWalker.java new file mode 100644 index 000000000..e5e19deee --- /dev/null +++ b/asm/src/org/aspectj/asm/ModelWalker.java @@ -0,0 +1,42 @@ +/* ******************************************************************* + * 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; + +/** + * @author Mik Kersten + */ +public class ModelWalker { + + private StructureModel model; + + public ModelWalker() { + super(); + } + + public ModelWalker(StructureModel model) { + this.model = model; + } + + protected void preProcess(StructureNode node) { } + + protected void postProcess(StructureNode node) { } + + public StructureNode process(StructureNode node) { + preProcess(node); + node.walk(this); + postProcess(node); + return node; + } +} diff --git a/asm/src/org/aspectj/asm/ProgramElementNode.java b/asm/src/org/aspectj/asm/ProgramElementNode.java new file mode 100644 index 000000000..06974bfd3 --- /dev/null +++ b/asm/src/org/aspectj/asm/ProgramElementNode.java @@ -0,0 +1,388 @@ +/* ******************************************************************* + * 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.util.*; +import java.io.*; + +import org.aspectj.bridge.ISourceLocation; + + +/** + * @author Mik Kersten + */ +public class ProgramElementNode extends StructureNode { + + private List modifiers = new ArrayList(); + private List relations = new ArrayList(); + + private Kind kind; + private Accessibility accessibility; + private String declaringType = ""; + private String formalComment = ""; + private String packageName = null; + private boolean runnable = false; + private boolean implementor = false; + private boolean overrider = false; + + private String bytecodeName; + private String bytecodeSignature; + + + /** + * Used during de-externalization. + */ + public ProgramElementNode() { } + + /** + * Use to create program element nodes that do not correspond to source locations. + */ + public ProgramElementNode( + String signature, + Kind kind, + List children) { + super(signature, kind.toString(), children); + this.kind = kind; + } + + public ProgramElementNode( + String signature, + ProgramElementNode.Kind kind, + ISourceLocation sourceLocation, + int modifiers, + String formalComment, + List children) + { + super(signature, kind.toString(), children); + super.sourceLocation = sourceLocation; + this.kind = kind; + this.formalComment = formalComment; + this.modifiers = genModifiers(modifiers); + this.accessibility = genAccessibility(modifiers); + } + + /** + * Use to create program element nodes that correspond to source locations. + */ + public ProgramElementNode( + String signature, + Kind kind, + List modifiers, + Accessibility accessibility, + String declaringType, + String packageName, + String formalComment, + ISourceLocation sourceLocation, + List relations, + List children, + boolean member) { + + super(signature, kind.toString(), children); + super.sourceLocation = sourceLocation; + this.kind = kind; + this.modifiers = modifiers; + this.accessibility = accessibility; + this.declaringType = declaringType; + this.packageName = packageName; + this.formalComment = formalComment; + this.relations = relations; + } + + public Kind getProgramElementKind() { + return kind; + } + + public List getModifiers() { + return modifiers; + } + + public Accessibility getAccessibility() { + return accessibility; + } + + public String getDeclaringType() { + return declaringType; + } + + public String getPackageName() { + if (kind == Kind.PACKAGE) return getSignature(); + if (getParent() == null || !(getParent() instanceof ProgramElementNode)) { + return ""; + } + return ((ProgramElementNode)getParent()).getPackageName(); + } + + public String getKind() { + return super.kind; + } + + public String getSignature() { + return super.name; + } + + public boolean isCode() { + return kind.equals(Kind.CODE); + } + + public boolean isMemberKind() { + return kind.isMemberKind(); + } + + public void setRunnable(boolean value) { + this.runnable = value; + } + + public boolean isRunnable() { + return runnable; + } + + public boolean isImplementor() { + return implementor; + } + + public void setImplementor(boolean value) { + this.implementor = value; + } + + public boolean isOverrider() { + return overrider; + } + + public void setOverrider(boolean value) { + this.overrider = value; + } + + public List getRelations() { + return relations; + } + + public void setRelations(List relations) { + if (relations.size() > 0) { + this.relations = relations; + } + } + + public String getFormalComment() { + return formalComment; + } + + public String toString() { + return super.name; + } + + public static List genModifiers(int modifiers) { + List modifiersList = new ArrayList(); + if ((modifiers & AccStatic) != 0) modifiersList.add(ProgramElementNode.Modifiers.STATIC); + if ((modifiers & AccFinal) != 0) modifiersList.add(ProgramElementNode.Modifiers.STATIC); + if ((modifiers & AccSynchronized) != 0) modifiersList.add(ProgramElementNode.Modifiers.STATIC); + if ((modifiers & AccVolatile) != 0) modifiersList.add(ProgramElementNode.Modifiers.STATIC); + if ((modifiers & AccTransient) != 0) modifiersList.add(ProgramElementNode.Modifiers.STATIC); + if ((modifiers & AccNative) != 0) modifiersList.add(ProgramElementNode.Modifiers.STATIC); + if ((modifiers & AccAbstract) != 0) modifiersList.add(ProgramElementNode.Modifiers.STATIC); + return modifiersList; + } + + public static ProgramElementNode.Accessibility genAccessibility(int modifiers) { + if ((modifiers & AccPublic) != 0) return ProgramElementNode.Accessibility.PUBLIC; + if ((modifiers & AccPrivate) != 0) return ProgramElementNode.Accessibility.PRIVATE; + if ((modifiers & AccProtected) != 0) return ProgramElementNode.Accessibility.PROTECTED; + if ((modifiers & AccPrivileged) != 0) return ProgramElementNode.Accessibility.PRIVILEGED; + else return ProgramElementNode.Accessibility.PACKAGE; + } + + /** + * Uses "typesafe enum" pattern. + */ + public static class Modifiers implements Serializable { + + public static final Modifiers STATIC = new Modifiers("static"); + public static final Modifiers FINAL = new Modifiers("final"); + public static final Modifiers ABSTRACT = new Modifiers("abstract"); + public static final Modifiers SYNCHRONIZED = new Modifiers("synchronized"); + public static final Modifiers VOLATILE = new Modifiers("volatile"); + public static final Modifiers STRICTFP = new Modifiers("strictfp"); + public static final Modifiers TRANSIENT = new Modifiers("transient"); + public static final Modifiers NATIVE = new Modifiers("native"); + public static final Modifiers[] ALL = { STATIC, FINAL, ABSTRACT, SYNCHRONIZED, TRANSIENT, VOLATILE, STRICTFP, NATIVE }; + private final String name; + + private Modifiers(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } + + /** + * Uses "typesafe enum" pattern. + */ + public static class Accessibility implements Serializable { + + public static final Accessibility PUBLIC = new Accessibility("public"); + public static final Accessibility PACKAGE = new Accessibility("package"); + public static final Accessibility PROTECTED = new Accessibility("protected"); + public static final Accessibility PRIVATE = new Accessibility("private"); + public static final Accessibility PRIVILEGED = new Accessibility("privileged"); + public static final Accessibility[] ALL = { PUBLIC, PACKAGE, PROTECTED, PRIVATE, PRIVILEGED }; + private final String name; + + private Accessibility(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } + + /** + * Uses "typesafe enum" pattern. + */ + public static class Kind implements Serializable { + + public static final Kind PROJECT = new Kind("project"); + public static final Kind PACKAGE = new Kind("package"); + public static final Kind FILE = new Kind("file"); + public static final Kind FILE_JAVA = new Kind("java source file"); + public static final Kind FILE_ASPECTJ = new Kind("aspect source file"); + public static final Kind FILE_LST = new Kind("build configuration file"); + public static final Kind CLASS = new Kind("class"); + public static final Kind INTERFACE = new Kind("interface"); + public static final Kind ASPECT = new Kind("aspect"); + public static final Kind INITIALIZER = new Kind("initializer"); + public static final Kind INTRODUCTION = new Kind("introduction"); + public static final Kind CONSTRUCTOR = new Kind("constructor"); + public static final Kind METHOD = new Kind("method"); + public static final Kind FIELD = new Kind("field"); + public static final Kind POINTCUT = new Kind("pointcut"); + public static final Kind ADVICE = new Kind("advice"); + public static final Kind DECLARE_PARENTS = new Kind("declare parents"); + public static final Kind DECLARE_WARNING = new Kind("declare warning"); + public static final Kind DECLARE_ERROR = new Kind("declare error"); + public static final Kind DECLARE_SOFT = new Kind("declare soft"); + public static final Kind CODE = new Kind("decBodyElement"); + 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, INTRODUCTION, CONSTRUCTOR, METHOD, FIELD, POINTCUT, ADVICE, + DECLARE_PARENTS, DECLARE_WARNING, DECLARE_ERROR, DECLARE_SOFT, CODE, ERROR }; + + public static Kind getKindForString(String kindString) { + for (int i = 0; i < ALL.length; i++) { + if (ALL[i].toString().equals(kindString)) return ALL[i]; + } + return ERROR; + } + + private final String name; + + private Kind(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + public static List getNonAJMemberKinds() { + List list = new ArrayList(); + list.add(METHOD); + list.add(FIELD); + list.add(CONSTRUCTOR); + return list; + } + + public boolean isMemberKind() { + return this == FIELD + || this == METHOD + || this == CONSTRUCTOR + || this == POINTCUT + || this == ADVICE; + } + + public boolean isTypeKind() { + return this == CLASS + || this == INTERFACE + || this == ASPECT; + } + + public boolean isSourceFileKind() { + return this == FILE_ASPECTJ + || this == FILE_JAVA; + } + + public boolean isDeclareKind() { + return name.startsWith("declare"); + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } + + // XXX these names and values are from org.eclipse.jdt.internal.compiler.env.IConstants + private static int AccPublic = 0x0001; + private static int AccPrivate = 0x0002; + private static int AccProtected = 0x0004; + private static int AccPrivileged = 0x0006; // XXX is this right? + private static int AccStatic = 0x0008; + private static int AccFinal = 0x0010; + private static int AccSynchronized = 0x0020; + private static int AccVolatile = 0x0040; + private static int AccTransient = 0x0080; + private static int AccNative = 0x0100; + private static int AccInterface = 0x0200; + private static int AccAbstract = 0x0400; + private static int AccStrictfp = 0x0800; + + + public String getBytecodeName() { + return bytecodeName; + } + + public String getBytecodeSignature() { + return bytecodeSignature; + } + + public void setBytecodeName(String bytecodeName) { + this.bytecodeName = bytecodeName; + } + + public void setBytecodeSignature(String bytecodeSignature) { + this.bytecodeSignature = bytecodeSignature; + } + +} + diff --git a/asm/src/org/aspectj/asm/ReferenceAssociation.java b/asm/src/org/aspectj/asm/ReferenceAssociation.java new file mode 100644 index 000000000..908f78d6e --- /dev/null +++ b/asm/src/org/aspectj/asm/ReferenceAssociation.java @@ -0,0 +1,153 @@ +/* ******************************************************************* + * 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.util.*; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class ReferenceAssociation implements Association { + public static final String NAME = "Reference"; + public static final Relation USES_POINTCUT_RELATION = new Relation("uses pointcut", "pointcut used by", NAME, true, true); + public static final Relation IMPORTS_RELATION = new Relation("imports", NAME, false); + //public static final Relation THROWS_RELATION = new Relation("throws", NAME, false); + //public static final Relation USES_TYPE_RELATION = new Relation("uses type", NAME, false); + + private List relations = new ArrayList(); + + public ReferenceAssociation() { + relations.add(USES_POINTCUT_RELATION); + relations.add(IMPORTS_RELATION); + //relations.add(THROWS_RELATION); + //relations.add(USES_TYPE_RELATION); + } + + public List getRelations() { + return relations; + } + + public List getRelationNodes() { + List relations = new ArrayList(); + List pointcutsUsed = new ArrayList(); + List pointcutUsedBy = new ArrayList(); + List throwsTypes = new ArrayList(); + List imports = new ArrayList(); + List usesType = new ArrayList(); +// Set forwardCorrs = StructureModelManager.correspondences.getAffects(astObject); +// Set backCorrs = StructureModelManager.correspondences.getAffectedBy(astObject); +// +// if (astObject instanceof AdviceDec) { +// for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) { +// ASTObject node = (ASTObject)it.next(); +// if (node instanceof PointcutDec) { +// pointcutsUsed.add(StructureNodeFactory.makeLink(node, false)); +// } +// } +// } else if (astObject instanceof PointcutDec) { +// for (Iterator it = backCorrs.iterator(); it.hasNext(); ) { +// ASTObject node = (ASTObject)it.next(); +// if (node instanceof PointcutDec || node instanceof AdviceDec) { +// pointcutUsedBy.add(StructureNodeFactory.makeLink(node, false)); +// } +// } +// for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) { +// ASTObject node = (ASTObject)it.next(); +// if (node instanceof PointcutDec) { +// pointcutsUsed.add(StructureNodeFactory.makeLink(node, false)); +// } +// } +// } else if (astObject instanceof MethodDec) { +// Method method = ((MethodDec)astObject).getMethod(); +// TypeDs throwsDs = method.getThrows(); +// if (throwsDs != null) { +// for (Iterator it = throwsDs.iterator(); it.hasNext(); ) { +// Object o = it.next(); +// if (o instanceof ResolvedTypeD) { +// ResolvedTypeD resolved = (ResolvedTypeD)o; +// if (resolved.getType().getCorrespondingDec() != null) { +// throwsTypes.add(StructureNodeFactory.makeLink(resolved.getType().getCorrespondingDec(), false)); +// } +// } +// } +// } +// if (!(method.getReturnType() instanceof PrimitiveType) && method.getReturnType().getCorrespondingDec() != null) { +// usesType.add(StructureNodeFactory.makeLink(method.getReturnType().getCorrespondingDec(), false)); +// } +// } else if (astObject instanceof FieldDec) { +// Field field = ((FieldDec)astObject).getField(); +// if (!(field.getFieldType() instanceof PrimitiveType) && field.getFieldType().getCorrespondingDec() != null) { +// usesType.add(StructureNodeFactory.makeLink(field.getFieldType().getCorrespondingDec(), false)); +// } +// } +// else if (astObject instanceof CompilationUnit) { +// CompilationUnit cu = (CompilationUnit)astObject; +// org.aspectj.compiler.base.ast.Imports cuImports = cu.getImports(); +// for (int i = 0; cuImports != null && i < cuImports.getChildCount(); i++) { +// Import imp = cuImports.get(i); +// if (!imp.getStar() && imp != null && imp.getType() != null) { +// Type type = imp.getType(); +// Dec dec = type.getCorrespondingDec(); +// if (dec != null) imports.add(StructureNodeFactory.makeLink(dec, true)); +// } +// } +// } +// +// if (!pointcutsUsed.isEmpty()) relations.add(new RelationNode(USES_POINTCUT_RELATION, USES_POINTCUT_RELATION.getForwardNavigationName(), pointcutsUsed)); +// if (!pointcutUsedBy.isEmpty()) relations.add(new RelationNode(USES_POINTCUT_RELATION, USES_POINTCUT_RELATION.getBackNavigationName(), pointcutUsedBy)); +// if (!imports.isEmpty()) relations.add(new RelationNode(IMPORTS_RELATION, IMPORTS_RELATION.getForwardNavigationName(), imports)); + return relations; + } + + public String getName() { + return NAME; + } +} + + +//public class JavadocSeeAlso { +// +// private static final String DOC = +// "<b>Relates:</b> a declaration to another by the @seeAlso tag<br>" + +// "<b>Symmetric: </b> yes"; +// +// public List makeLinks(ASTObject astObject, boolean forwardNavigation) { +// List linkList = new Vector(); +// org.aspectj.compiler.base.ast.Comment comment = astObject.getComment(); +// try { +// Object[] os = (Object[])comment.getClass().getMethod("seeTags", new Class[]{}).invoke(comment, new Object[]{}); +// for (int i = 0; i < os.length; i++) { +// Object o = os[i]; +// Dec docDec = null; +// TypeDec typeDec = (TypeDec)o.getClass().getMethod("referencedClass", new Class[]{}).invoke(o, new Object[]{}); +// Dec memberDec = (Dec)o.getClass().getMethod("referencedMember", new Class[]{}).invoke(o, new Object[]{}); +// if (memberDec != null) { +// docDec = memberDec; +// } else if (typeDec != null) { +// docDec = typeDec; +// } +// if (docDec != null) { +// linkList.add(StructureNodeFactory.makeLink(docDec, false)); +// +// } +// } +// } catch (Throwable t) { +// // ingore +// } +// return linkList; +// } + + diff --git a/asm/src/org/aspectj/asm/Relation.java b/asm/src/org/aspectj/asm/Relation.java new file mode 100644 index 000000000..31bfdc42f --- /dev/null +++ b/asm/src/org/aspectj/asm/Relation.java @@ -0,0 +1,89 @@ +/* ******************************************************************* + * 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.Serializable; + +/** + * @author Mik Kersten + */ +public class Relation implements Serializable { + + private String forwardNavigationName; + private String backNavigationName; + private String associationName; + private boolean symmetrical; + private boolean transitive; + + public Relation(String forwardNavigationName, + String backNavigationName, + String associationName, + boolean symmetrical, + boolean transitive) { + this.forwardNavigationName = forwardNavigationName; + this.backNavigationName = backNavigationName; + this.associationName = associationName; + this.symmetrical = symmetrical; + this.transitive = transitive; + } + + /** + * Constructor for asymetrical relations. + */ + public Relation(String forwardNavigationName, + String associationName, + boolean transitive) { + this(forwardNavigationName, "<no back navigation name>", associationName, false, transitive); + } + + public String getForwardNavigationName() { + return forwardNavigationName; + } + + public String getBackNavigationName() { + return backNavigationName; + } + + public String getAssociationName() { + return associationName; + } + + public boolean isSymmetrical() { + return symmetrical; + } + + public boolean isTransitive() { + return transitive; + } + + public boolean equals(Object o) { + if (!(o instanceof Relation)) return false; + Relation r = (Relation)o; + return forwardNavigationName.equals(r.getForwardNavigationName()) + && backNavigationName.equals(r.getBackNavigationName()) + && associationName.equals(r.getAssociationName()) + && (symmetrical == r.isSymmetrical()) + && (transitive == r.isTransitive()); + } + + public String toString() { + if (symmetrical) { + return forwardNavigationName + " / " + backNavigationName; + } else { + return forwardNavigationName; + } + } +} diff --git a/asm/src/org/aspectj/asm/RelationNode.java b/asm/src/org/aspectj/asm/RelationNode.java new file mode 100644 index 000000000..ec4c51357 --- /dev/null +++ b/asm/src/org/aspectj/asm/RelationNode.java @@ -0,0 +1,39 @@ +/* ******************************************************************* + * 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.util.List; + +/** + * @author Mik Kersten + */ +public class RelationNode extends StructureNode { + + private Relation relation; + + /** + * Used during de-externalization. + */ + public RelationNode() { } + + public RelationNode(Relation relation, String name, List children) { + super(name, relation.getAssociationName(), children); + this.relation = relation; + } + + public Relation getRelation() { + return relation; + } +} diff --git a/asm/src/org/aspectj/asm/StructureModel.java b/asm/src/org/aspectj/asm/StructureModel.java new file mode 100644 index 000000000..18f464b4f --- /dev/null +++ b/asm/src/org/aspectj/asm/StructureModel.java @@ -0,0 +1,180 @@ +/* ******************************************************************* + * 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.File; +import java.io.Serializable; +import java.util.*; + +import org.aspectj.bridge.SourceLocation; + +/** + * @author Mik Kersten + */ +public class StructureModel implements Serializable { + + protected StructureNode root = null; + protected String configFile = null; + private Map fileMap = null; + public static final ProgramElementNode NO_STRUCTURE = new ProgramElementNode("<build to view structure>", ProgramElementNode.Kind.ERROR, null); + + public StructureNode getRoot() { + return root; + } + + public void setRoot(StructureNode root) { + this.root = root; + } + + public Map getFileMap() { + return fileMap; + } + + + public void setFileMap(HashMap fileMap) { + this.fileMap = fileMap; + } + + + public boolean isValid() { + return root != null && fileMap != null; + } + + + /** + * @param packageName if null default package is searched + * @param className can't be null + */ + public ProgramElementNode findNodeForClass(String packageName, String className) { + StructureNode packageNode = null; + if (packageName == null) { + packageNode = root; + } else { + for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) { + StructureNode node = (StructureNode)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(); ) { + ProgramElementNode fileNode = (ProgramElementNode)it.next(); + for (Iterator j = fileNode.getChildren().iterator(); j.hasNext(); ) { + ProgramElementNode classNode = (ProgramElementNode)j.next(); + if (classNode instanceof ProgramElementNode && className.equals(classNode.getName())) { + return (ProgramElementNode)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 StructureNode findRootNodeForSourceFile(String sourceFilePath) { + if (!isValid() || sourceFilePath == null) { + return StructureModel.NO_STRUCTURE; + } else { + String correctedPath = sourceFilePath.replace('\\', '/'); + StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model); + if (node != null) { + return node; + } else { + return createFileStructureNode(sourceFilePath); + } + } + } + + /** + * Never returns null + * + * @param sourceFilePath modified to '/' delimited 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 StructureNode findNodeForSourceLine(String sourceFilePath, int lineNumber) { + String correctedPath = sourceFilePath.replace('\\', '/'); + StructureNode node = findNodeForSourceLineHelper(root, correctedPath, lineNumber); + if (node != null) { + return node; + } else { + return createFileStructureNode(sourceFilePath); + } + } + + private StructureNode createFileStructureNode(String sourceFilePath) { + String fileName = new File(sourceFilePath).getName(); + ProgramElementNode fileNode = new ProgramElementNode(fileName, ProgramElementNode.Kind.FILE_JAVA, null); + fileNode.setSourceLocation(new SourceLocation(new File(sourceFilePath), 1, 1)); + fileNode.addChild(NO_STRUCTURE); + return fileNode; + } + + + private StructureNode findNodeForSourceLineHelper(StructureNode 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(); ) { + StructureNode foundNode = findNodeForSourceLineHelper( + (StructureNode)it.next(), + sourceFilePath, + lineNumber); + if (foundNode != null) return foundNode; + } + } + + return null; + } + + private boolean matches(StructureNode node, String sourceFilePath, int lineNumber) { + return node != null + && node.getSourceLocation() != null + && node.getSourceLocation().getSourceFile().getAbsolutePath().equals(sourceFilePath) + && ((node.getSourceLocation().getLine() <= lineNumber + && node.getSourceLocation().getEndLine() >= lineNumber) + || + (lineNumber <= 1 + && node instanceof ProgramElementNode + && ((ProgramElementNode)node).getProgramElementKind().isSourceFileKind()) + ); + } + + private boolean hasMoreSpecificChild(StructureNode node, String sourceFilePath, int lineNumber) { + for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { + ProgramElementNode child = (ProgramElementNode)it.next(); + if (matches(child, sourceFilePath, lineNumber)) return true; + } + return false; + } + + public String getConfigFile() { + return configFile; + } + + public void setConfigFile(String configFile) { + this.configFile = configFile; + } + +} + diff --git a/asm/src/org/aspectj/asm/StructureModelListener.java b/asm/src/org/aspectj/asm/StructureModelListener.java new file mode 100644 index 000000000..eab786b64 --- /dev/null +++ b/asm/src/org/aspectj/asm/StructureModelListener.java @@ -0,0 +1,27 @@ +/* ******************************************************************* + * 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.util.EventListener; + +/** + * Compiler listeners get notified of structure model update events. + * + * @author Mik Kersten + */ +public interface StructureModelListener extends EventListener { + + public void modelUpdated(StructureModel rootNode); +} diff --git a/asm/src/org/aspectj/asm/StructureModelManager.java b/asm/src/org/aspectj/asm/StructureModelManager.java new file mode 100644 index 000000000..4a868d9fe --- /dev/null +++ b/asm/src/org/aspectj/asm/StructureModelManager.java @@ -0,0 +1,165 @@ +/* ******************************************************************* + * 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.util.*; +import java.io.*; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class StructureModelManager { + + /** + * Singleton instance. + */ + public static StructureModelManager INSTANCE = new StructureModelManager(); + private boolean shouldSaveModel = true; + protected StructureModel model = new StructureModel(); + private List structureListeners = new ArrayList(); + private List associations = new ArrayList(); + + protected StructureModelManager() { + associations.add(new AdviceAssociation()); + associations.add(new IntroductionAssociation()); + associations.add(new InheritanceAssociation()); + associations.add(new ReferenceAssociation()); + } + + public StructureModel getStructureModel() { + 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) { + + if (!model.isValid()) return null; + + HashMap annotations = new HashMap(); + StructureNode node = model.findRootNodeForSourceFile(sourceFile); + if (node == StructureModel.NO_STRUCTURE) { + return null; + } else { + ProgramElementNode fileNode = (ProgramElementNode)node; + ArrayList peNodes = new ArrayList(); + getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType); + for (Iterator it = peNodes.iterator(); it.hasNext(); ) { + ProgramElementNode peNode = (ProgramElementNode)it.next(); + List entries = new ArrayList(); + entries.add(peNode); + Integer hash = new Integer(peNode.getSourceLocation().getLine()); + List existingEntry = (List)annotations.get(hash); + if (existingEntry != null) { + entries.addAll(existingEntry); + } + annotations.put(hash, entries); + } + return annotations; + } + } + + private void getAllStructureChildren(ProgramElementNode node, List result, boolean showSubMember, boolean showMemberAndType) { + List children = node.getChildren(); + for (Iterator it = children.iterator(); it.hasNext(); ) { + StructureNode next = (StructureNode)it.next(); + if (next instanceof ProgramElementNode) { + ProgramElementNode pNode = (ProgramElementNode)next; + if (pNode != null + && ((pNode.isCode() && showSubMember) || (!pNode.isCode() && showMemberAndType)) + && pNode.getRelations() != null + && pNode.getRelations().size() > 0) { + result.add(next); + } + getAllStructureChildren((ProgramElementNode)next, result, showSubMember, showMemberAndType); + } + } + } + + public void addListener(StructureModelListener listener) { + structureListeners.add(listener); + } + + public void removeStructureListener(StructureModelListener listener) { + structureListeners.remove(listener); + } + + private void notifyListeners() { + for (Iterator it = structureListeners.iterator(); it.hasNext(); ) { + ((StructureModelListener)it.next()).modelUpdated(model); + } + } + + public List getAssociations() { + return associations; + } + + /** + * 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; + } +} + diff --git a/asm/src/org/aspectj/asm/StructureNode.java b/asm/src/org/aspectj/asm/StructureNode.java new file mode 100644 index 000000000..00b4f6f1d --- /dev/null +++ b/asm/src/org/aspectj/asm/StructureNode.java @@ -0,0 +1,259 @@ +/* ******************************************************************* + * 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.util.*; +import java.io.*; + +import org.aspectj.bridge.*; +import org.aspectj.bridge.IMessage; + +/** + * Children are non-repeating making the parent-child structure a strict + * tree. + * + * !!! relies on a java.io.Serializable implementation of ISourceLocation + * + * @author Mik Kersten + */ +public abstract class StructureNode implements Serializable, Comparable { + + protected StructureNode parent = null; + protected String name = ""; + protected String kind = ""; + protected List children = new ArrayList(); + protected IMessage message = null; + protected ISourceLocation sourceLocation = null; + + /** + * Used during serialization. + */ + public StructureNode() { } + + public StructureNode(String name, String kind, List children) { + this.name = name; + this.kind = kind; + if (children != null) { + this.children = children; + } + setParents(); + } + + public StructureNode(String name, String kind) { + this.name = name; + this.kind = kind; + } + + public String toLongString() { + final StringBuffer buffer = new StringBuffer(); + ModelWalker walker = new ModelWalker() { + private int depth = 0; + + public void preProcess(StructureNode node) { + for (int i = 0; i < depth; i++) buffer.append(' '); + buffer.append(node.toString()); + buffer.append('\n'); + depth += 2; + } + + public void postProcess(StructureNode node) { + depth -= 2; + } + }; + walker.process(this); + return buffer.toString(); + } + + public String toString() { + return name; + } + + public String getKind() { + return kind; + } + + public List getChildren() { + return children; + } + + public void addChild(StructureNode child) { + if (children == null) { + children = new ArrayList(); + } + children.add(child); + child.setParent(this); + } + + public void addChild(int position, StructureNode child) { + if (children == null) { + children = new ArrayList(); + } + children.add(position, child); + child.setParent(this); + } + + public boolean removeChild(StructureNode child) { + child.setParent(null); + return children.remove(child); + } + + public StructureNode walk(ModelWalker walker) { + for (Iterator it = children.iterator(); it.hasNext(); ) { + StructureNode child = (StructureNode)it.next(); + walker.process(child); + } + return this; + } + +// public boolean equals(Object o) { +// if (!(o instanceof StructureNode)) return false; +// StructureNode sn = (StructureNode)o; +// return objectEqual(sn.getName(), this.getName()) +// && objectEqual(sn.getKind(), this.getKind()) +// && objectEqual(sn.getChildren(), this.getChildren()); +// } +// +// protected boolean objectEqual(Object o1, Object o2) { +// return (o1 == null && o2 == null) || (o1 != null && o1.equals(o2)); +// } + + /** + * Comparison is string-name based only. + */ + public int compareTo(Object o) throws ClassCastException { + if (this == o) { + return 0; + } else { + StructureNode sn = (StructureNode)o; + return this.getName().compareTo(sn.getName()); + } + } + + public String getName() { + return name; + } + + public ISourceLocation getSourceLocation() { + return sourceLocation; + } + + public void setSourceLocation(ISourceLocation sourceLocation) { + this.sourceLocation = sourceLocation; + } + + public IMessage getMessage() { + return message; + } + + public void setMessage(IMessage message) { + this.message = message; + } + + public StructureNode getParent() { + return parent; + } + + public void setParent(StructureNode parent) { + this.parent = parent; + } + + private void setParents() { + if (children == null) return; + for (Iterator it = children.iterator(); it.hasNext(); ) { + ((StructureNode)it.next()).setParent(this); + } + } +// +// /** +// * Creates and returns a copy of this object. +// */ +// public Object clone() { +// List cloneChildren = new ArrayList(); +// for (Iterator it = children.iterator(); it.hasNext(); ) { +// cloneChildren.add(((StructureNode)it.next()).clone()); +// } +// StructureNode cloneNode = new StructureNode(name, kind, cloneChildren); +// return cloneNode; +// } +} + + +// private void writeObject(ObjectOutputStream s) throws IOException { +// s.defaultWriteObject(); +// // customized serialization code +// } +// +// private void readObject(ObjectInputStream s) throws IOException { +// s.defaultReadObject(); +// // customized deserialization code +// ... +// // followed by code to update the object, if necessary +// } + +// public void writeExternal(ObjectOutput out) throws IOException { +// if (this instanceof ProgramElementNode) { +// out.writeInt(1); +// writeString(name, out); +// writeString(kind, out); +// ((ProgramElementNode)this).writeExternal(out); +// } if (this instanceof RelationNode) { +// out.writeInt(1); +// writeString(name, out); +// writeString(kind, out); +// ((RelationNode)this).writeExternal(out); +// } if (this instanceof LinkNode) { +// out.writeInt(3); +// writeString(name, out); +// writeString(kind, out); +// ((LinkNode)this).writeExternal(out); +// } else { +// out.writeInt(0); +// writeString(name, out); +// writeString(kind, out); +// } +// } +// +// public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { +// int kindint = in.readInt(); +// name = readString(in); +// kind = readString(in); +// +// switch (kindint) { +// case 1: +// ((StructureNode)it.next()).readExternal(in); +// break; +// case 2: +// ((RelationNode)it.next()).readExternal(in); +// break; +// case 3: +// ((LinkNode)it.next()).readExternal(in); +// break; +// } +// } +// +// protected void writeString(String s, ObjectOutput out) throws IOException { +// out.writeInt(s.length()); +// out.write(s.getBytes()); +// } +// +// protected String readString(ObjectInput in) throws IOException { +// int length = in.readInt(); +// byte[] nameArray = new byte[length]; +// in.read(nameArray, 0, length); +// return new String(nameArray); +// } +// + + diff --git a/asm/src/org/aspectj/asm/StructureNodeFactory.java b/asm/src/org/aspectj/asm/StructureNodeFactory.java new file mode 100644 index 000000000..3e5257960 --- /dev/null +++ b/asm/src/org/aspectj/asm/StructureNodeFactory.java @@ -0,0 +1,299 @@ +/* ******************************************************************* + * 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.util.*; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class StructureNodeFactory { + + private static Hashtable programElementNodes = new Hashtable(); + + private static final ProgramElementNode UNRESOLVED_LINK_NODE = new ProgramElementNode("<error: unresolved link>", ProgramElementNode.Kind.ERROR, null, null, "", "", "", null, null, null, false); + + public static void clear() { + programElementNodes.clear(); + } + + public static ProgramElementNode makeNode(List relations, List children) { + return makeNode(relations, children, false); + } + + public static LinkNode makeLink(boolean terminal) { + ProgramElementNode peNode = null; + if (terminal) { + peNode = makeNode(null, null, false); + } else { + peNode = makeNode(null, null, true); + } + + if (peNode == null) { + return new LinkNode(UNRESOLVED_LINK_NODE); + } else { + return new LinkNode(peNode); + } + } + + private static ProgramElementNode makeNode(List relations, List children, boolean resolve) { +// if (resolve) { +// if (astObject instanceof InitializerDec) { +// InitializerDec initDec = (InitializerDec)astObject; +// return (ProgramElementNode)programElementNodes.get(initDec.getDeclaringType().getTypeDec()); +// } else if (astObject instanceof Decs) { +// Decs decs = (Decs)astObject; +// return (ProgramElementNode)programElementNodes.get(decs.getDeclaringType().getTypeDec()); +// } else { +// ProgramElementNode peNode = (ProgramElementNode)programElementNodes.get(astObject); +// if (peNode == null) { +// return makeNode(astObject, null, null, false); +// } else { +// return peNode; +// } +// } +// } else { +// String declaringType = ""; +// if (astObject.getDeclaringType() != null) { +// declaringType = astObject.getDeclaringType().toShortString(); +// } +// +// org.aspectj.asm.SourceLocation sourceLocation = new org.aspectj.asm.SourceLocation( +// astObject.getSourceLocation().getSourceFileName(), +// astObject.getSourceLocation().getBeginLine(), +// astObject.getSourceLocation().getEndLine(), +// astObject.getSourceLocation().getBeginColumn()); +// +// ProgramElementNode newNode = new ProgramElementNode( +// genSignature(astObject).trim(), +// genKind(astObject), +// genModifiers(astObject), +// genAccessibility(astObject), +// declaringType, +// genPackageName(astObject), +// genFormalComment(astObject), +// sourceLocation, +// relations, +// children, +// isMemberKind(astObject), +// astObject); +// programElementNodes.put(astObject, newNode); +// newNode.setRunnable(genIsRunnable(newNode)); +// setSpecifiers(astObject, newNode); +// +// return newNode; +// } + return null; + } + +// private static void setSpecifiers(ASTObject astObject, ProgramElementNode node) { +// if (astObject instanceof MethodDec) { +// Method method = ((MethodDec)astObject).getMethod(); +// for (Iterator it = method.getDeclaringType().getDirectSuperTypes().iterator(); it.hasNext(); ) { +// NameType type = (NameType)it.next(); +// SemanticObject so = type.findMatchingSemanticObject(method); +// +// if (so != null && so instanceof Method) { +// +// Method superMethod = (Method)so; +// if (so.isAbstract()) { +// node.setImplementor(true); +// } else { +// node.setOverrider(true); +// } +// } +// } +// } +// } +// +// private static boolean genIsRunnable(ProgramElementNode node) { +// if (node.getModifiers().contains(ProgramElementNode.Modifiers.STATIC) +// && node.getAccessibility().equals(ProgramElementNode.Accessibility.PUBLIC) +// && node.getSignature().equals("main(String[])")) { +// return true; +// } else { +// return false; +// } +// } +// +// private static boolean genIsStmntKind(ASTObject astObject) { +// return astObject instanceof CatchClause +// || astObject instanceof SOLink +// || astObject instanceof BasicAssignExpr; +// } +// +// private static List genModifiers(ASTObject astObject) { +// List modifiers = new ArrayList(); +// if (astObject instanceof Dec) { +// Dec dec = (Dec)astObject; +// if (dec.getModifiers().isStrict()) modifiers.add(ProgramElementNode.Modifiers.STRICTFP); +// if (dec.getModifiers().isAbstract()) modifiers.add(ProgramElementNode.Modifiers.ABSTRACT); +// if (dec.getModifiers().isSynchronized()) modifiers.add(ProgramElementNode.Modifiers.SYNCHRONIZED); +// if (dec.getModifiers().isNative()) modifiers.add(ProgramElementNode.Modifiers.NATIVE); +// if (dec.getModifiers().isFinal()) modifiers.add(ProgramElementNode.Modifiers.FINAL); +// if (dec.getModifiers().isTransient()) modifiers.add(ProgramElementNode.Modifiers.TRANSIENT); +// if (dec.getModifiers().isStatic()) modifiers.add(ProgramElementNode.Modifiers.STATIC); +// if (dec.getModifiers().isVolatile()) modifiers.add(ProgramElementNode.Modifiers.VOLATILE); +// } +// return modifiers; +// } +// +// private static ProgramElementNode.Accessibility genAccessibility(ASTObject astObject) { +// //List modifiers = new ArrayList(); +// if (astObject instanceof Dec) { +// Dec dec = (Dec)astObject; +// if (dec.getModifiers().isPublic()) return ProgramElementNode.Accessibility.PUBLIC; +// if (dec.getModifiers().isProtected()) return ProgramElementNode.Accessibility.PROTECTED; +// if (dec.getModifiers().isPrivileged()) return ProgramElementNode.Accessibility.PRIVILEGED; +// if (dec.getModifiers().isPackagePrivate()) return ProgramElementNode.Accessibility.PACKAGE; +// if (dec.getModifiers().isPrivate()) return ProgramElementNode.Accessibility.PRIVATE; +// } +// return ProgramElementNode.Accessibility.PUBLIC; +// } +// +// /** +// * @todo special cases should be fixes to AST nodes, this should have no instanceof tests. +// */ +// private static ProgramElementNode.Kind genKind(ASTObject astObject) { +// if (astObject instanceof CompilationUnit) { +// return ProgramElementNode.Kind.FILE_JAVA; +// } else if (genIsStmntKind(astObject)) { +// return ProgramElementNode.Kind.CODE; +// } else if (astObject instanceof Dec) { +// String kindString = ((Dec)astObject).getKind(); +// return ProgramElementNode.Kind.getKindForString(kindString); +// } else { +// return ProgramElementNode.Kind.ERROR; +// } +// } +// +// private static boolean isMemberKind(ASTObject astObject) { +// if (astObject instanceof Dec) { +// Dec dec = (Dec)astObject; +// return dec.getDeclaringType() != null && !dec.getDeclaringType().equals(dec.getName()); +// } else { +// return false; +// } +// } +// +// private static String genPackageName(ASTObject astObject) { +// if (astObject instanceof TypeDec) { +// return ((TypeDec)astObject).getPackageName(); +// } else if (astObject instanceof CompilationUnit) { +// return ((CompilationUnit)astObject).getPackageName(); +// } else if (astObject.getDeclaringType() != null) { +// return astObject.getDeclaringType().getPackageName(); +// } else { +// return ""; +// } +// } +// +// private static String genDeclaringType(ASTObject astObject) { +// if (astObject != null && astObject.getDeclaringType() != null) { +// return astObject.getDeclaringType().toShortString(); +// } else { +// return null; +// } +// } +// +// /** +// * Tries to return the ajdoc generated comment, otherwise returns the raw comment. +// */ +// private static String genFormalComment(ASTObject astObject) { +// try { +// return (String)astObject.getComment().getClass().getMethod("commentText", new Class[]{}).invoke(astObject.getComment(), new Object[]{}); +// } catch (Throwable t) { +// if (astObject != null) { +// return astObject.getFormalComment(); +// } else { +// return ""; +// } +// } +// } +// +// /** +// * Specialized signature generation for nodes in the structure model. +// * +// * @todo the compiler should generate these names, doing it this way is atrocious +// */ +// private static String genSignature(ASTObject astObject) { +// String name = ""; +// if (astObject instanceof CompilationUnit) { +// return astObject.getSourceFile().getName(); +// } else if (astObject instanceof MethodDec) { +// Method method = ((MethodDec)astObject).getMethod(); +// return method.getName() + method.getFormals().toShortString(); +// } else if (astObject instanceof TypeDec) { +// return ((TypeDec)astObject).getSourceExtendedId(); +// } else if (astObject instanceof FieldDec) { +// return ((FieldDec)astObject).getName(); +// } else if (astObject instanceof ConstructorDec) { +// ConstructorDec constructorDec = (ConstructorDec)astObject; +// return constructorDec.getDeclaringType().getSourceExtendedId() + constructorDec.getFormals().toShortString(); +// } else if (astObject instanceof IntroducedDec) { +// IntroducedDec introDec = (IntroducedDec)astObject; +// return introDec.getTargets().toShortString() + '.' + genSignature(introDec.getDec()); +//// introDec.toShortString(); +// } else if (astObject instanceof PointcutDec) { +// PointcutDec pointcutDec = (PointcutDec)astObject; +// return pointcutDec.getName() + pointcutDec.getFormals().toShortString(); +//// } else if (astObject instanceof CallExpr) { +//// CallExpr call = (CallExpr)astObject; +//// name = call.get; +// } else if (astObject instanceof ShowErrorDec) { +// ShowErrorDec errorDec = (ShowErrorDec)astObject; +// return errorDec.toShortString(); +// } else if (astObject instanceof SoftThrowableDec) { +// SoftThrowableDec softThrowableDec = (SoftThrowableDec)astObject; +// return softThrowableDec.toShortString(); +// } else if (astObject instanceof IntroducedSuperDec) { +// IntroducedSuperDec introducedSuperDec = (IntroducedSuperDec)astObject; +// return introducedSuperDec.toShortString(); +// } else if (astObject instanceof AdviceDec) { +// AdviceDec adviceDec = (AdviceDec)astObject; +// return adviceDec.toShortString(); +// } else if (astObject instanceof SOLink) { +// SOLink soLink = (SOLink)astObject; +// return genSignature(soLink.getTarget().getCorrespondingDec()); +// } else if (astObject instanceof CatchClause) { +// CatchClause catchClause = (CatchClause)astObject; +// return catchClause.getFormal().getType().getSourceExtendedId(); +// } else if (astObject instanceof BasicAssignExpr) { +// return astObject.unparse(); +//// } else if (genIsStmntKind(astObject)) { +//// name = astObject.unparse(); +//// name = name.replace('/', ' '); +//// name = name.replace('*', ' '); +//// name = name.replace('\n', ' '); +//// name.trim(); +//// java.util.StringTokenizer st = new java.util.StringTokenizer(name, " "); +//// String s = ""; +//// while (st.hasMoreElements()) { +//// s += ((String)st.nextElement()).trim() + " "; +//// } +//// name = s; +//// int endIndex = name.indexOf(')'); +//// if (endIndex != -1) { +//// name = name.substring(0, endIndex+1); +//// } +//// if (name.startsWith("this.")) { +//// name = name.substring(5); +//// } +// } else { +// return "? " + astObject.toShortString(); +// } +// } +} diff --git a/asm/testdata/simple-coverage/Foo.java b/asm/testdata/simple-coverage/Foo.java new file mode 100644 index 000000000..b89aa8cc1 --- /dev/null +++ b/asm/testdata/simple-coverage/Foo.java @@ -0,0 +1,13 @@ +public class Foo { +// int x = b; + static class Mumble { + String name; + + class Gumble { + int b; + } + } + //aspect MemberAspect { } + + interface MemberI { } +} diff --git a/asm/testdata/simple-coverage/Good.java b/asm/testdata/simple-coverage/Good.java new file mode 100644 index 000000000..d447300c2 --- /dev/null +++ b/asm/testdata/simple-coverage/Good.java @@ -0,0 +1,57 @@ + +import java.util.*; +import java.io.IOException; + +public class Good { + + public static String foo; + public int publicA = 1; + private int privateA = 2; + protected int protectedA = 3; + int packageA = 4; + + { publicA = 5; } + + static { foo = "hi"; } + + public Good() { } + + public void foo() { + int i = 0; + i += 1; + i += 2; + } + + { publicA = 6; } +} + +aspect A { + int pkg1.Bar.interTypeField = 0; + //void Good.interTypeMethod() { } + + int j; + + before(): execution(void Good.foo()) { + System.out.println(""); + } + + public void m() { } + + pointcut all(): call(* *(..)); + + after(): all() { System.out.println(""); } + + declare warning: call(* mumble*(..)): "warning"; + declare error: call(* gumble*(..)): "error"; +// declare parents: Point extends java.io.Serializable; +// declare parents: Point implements java.util.Observable; +// declare soft: Point: call(* *(..)); +} + +interface I { } + + +//privileged aspect PrivilegedAspect { } + + + diff --git a/asm/testdata/simple-coverage/pkg1/Bar.java b/asm/testdata/simple-coverage/pkg1/Bar.java new file mode 100644 index 000000000..13b71eecf --- /dev/null +++ b/asm/testdata/simple-coverage/pkg1/Bar.java @@ -0,0 +1,6 @@ + +package pkg1; + +public class Bar { +// int x = b; +} diff --git a/asm/testdata/simple-coverage/pkg1/subpkg/Bar.java b/asm/testdata/simple-coverage/pkg1/subpkg/Bar.java new file mode 100644 index 000000000..958343755 --- /dev/null +++ b/asm/testdata/simple-coverage/pkg1/subpkg/Bar.java @@ -0,0 +1,6 @@ + +package pkg1.subpkg; + +public class Bar { +// int x = b; +} diff --git a/asm/testsrc/AsmModuleTests.java b/asm/testsrc/AsmModuleTests.java new file mode 100644 index 000000000..e690cb536 --- /dev/null +++ b/asm/testsrc/AsmModuleTests.java @@ -0,0 +1,30 @@ +/* ******************************************************************* + * 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 + * ******************************************************************/ + + +// default package + +import junit.framework.*; + +public class AsmModuleTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(AsmModuleTests.class.getName()); + suite.addTestSuite(AsmModuleTests.class); + return suite; + } + + public AsmModuleTests(String name) { super(name); } + + public void testNothing() {} +} |