new relationships (such as the example in the sandbox that adds additional declared-parents relationships). There is no structural change to the compiler or weaver. The AsmRelationshipProvider is now accessed by getDefault() instead of statically, and its instance can be reset to be a subtype.tags/V1_2_1
@@ -10,5 +10,6 @@ | |||
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/> | |||
<classpathentry kind="lib" path="/org.aspectj.ajdt.core/out/lib.jar"/> | |||
<classpathentry kind="src" path="/org.eclipse.jdt.core"/> | |||
<classpathentry kind="src" path="/weaver"/> | |||
<classpathentry kind="output" path=""/> | |||
</classpath> |
@@ -0,0 +1,88 @@ | |||
package org.aspectj.samples; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import org.aspectj.ajde.AjdeTestCase; | |||
import org.aspectj.asm.*; | |||
import org.aspectj.asm.internal.ProgramElement; | |||
import org.aspectj.bridge.ISourceLocation; | |||
import org.aspectj.weaver.AsmRelationshipProvider; | |||
import org.aspectj.weaver.ResolvedTypeX; | |||
/** | |||
* @author Mik Kersten | |||
*/ | |||
public class AsmRelationshipMapExtensionTest extends AjdeTestCase { | |||
public void testDeclares() { | |||
System.out.println("----------------------------------"); | |||
System.out.println("Parents declared by declare parents statements: "); | |||
HierarchyWalker walker = new HierarchyWalker() { | |||
public void preProcess(IProgramElement node) { | |||
if (node.getKind().equals(IProgramElement.Kind.DECLARE_PARENTS)) { | |||
System.out.println(node); | |||
List relations = AsmManager.getDefault().getRelationshipMap().get(node); | |||
if (relations != null) { | |||
for (Iterator it = relations.iterator(); it.hasNext();) { | |||
IRelationship relationship = (IRelationship) it.next(); | |||
List targets = relationship.getTargets(); | |||
for (Iterator iter = targets.iterator(); iter.hasNext();) { | |||
IProgramElement currElt = AsmManager | |||
.getDefault().getHierarchy() | |||
.getElement((String) iter.next()); | |||
System.out.println("--> " + relationship.getName() + ": " + currElt); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
}; | |||
AsmManager.getDefault().getHierarchy().getRoot().walk(walker); | |||
} | |||
protected void setUp() throws Exception { | |||
AsmRelationshipProvider.setDefault(new DeclareInfoProvider()); | |||
super.setUp("examples"); | |||
assertTrue("build success", | |||
doSynchronousBuild("../examples/coverage/coverage.lst")); | |||
} | |||
} | |||
class DeclareInfoProvider extends AsmRelationshipProvider { | |||
public void addDeclareParentsRelationship(ISourceLocation decp, | |||
ResolvedTypeX targetType, List newParents) { | |||
super.addDeclareParentsRelationship(decp, targetType, newParents); | |||
for (Iterator it = newParents.iterator(); it.hasNext();) { | |||
ResolvedTypeX superType = (ResolvedTypeX) it.next(); | |||
String sourceHandle = ProgramElement.createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn()); | |||
IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle); | |||
String superHandle = ProgramElement.createHandleIdentifier( | |||
superType.getSourceLocation().getSourceFile(), | |||
superType.getSourceLocation().getLine(), | |||
superType.getSourceLocation().getColumn()); | |||
if (sourceHandle != null && superHandle != null) { | |||
IRelationship foreward = AsmManager.getDefault().getRelationshipMap().get( | |||
sourceHandle, | |||
IRelationship.Kind.DECLARE, | |||
"super types declared", | |||
false, | |||
true); | |||
foreward.addTarget(superHandle); | |||
IRelationship back = AsmManager.getDefault().getRelationshipMap().get( | |||
superHandle, IRelationship.Kind.DECLARE, | |||
"declared as super type by", | |||
false, | |||
true); | |||
back.addTarget(sourceHandle); | |||
} | |||
} | |||
} | |||
} |
@@ -329,7 +329,7 @@ public class AjLookupEnvironment extends LookupEnvironment { | |||
// (When done at weave time, it is done by invoking addRelationship() on | |||
// AsmRelationshipProvider (see BCELTypeMunger) | |||
if (!ResolvedTypeMunger.persistSourceLocation) // Do it up front if we bloody have to | |||
AsmInterTypeRelationshipProvider.addRelationship(onType, munger); | |||
AsmInterTypeRelationshipProvider.getDefault().addRelationship(onType, munger); | |||
} | |||
} | |||
@@ -362,7 +362,7 @@ public class AjLookupEnvironment extends LookupEnvironment { | |||
onType + ": " + dangerousInterfaces.get(parent), | |||
onType.getSourceLocation(), null); | |||
} | |||
AsmRelationshipProvider.addDeclareParentsRelationship(declareParents.getSourceLocation(),factory.fromEclipse(sourceType)); | |||
AsmRelationshipProvider.getDefault().addDeclareParentsRelationship(declareParents.getSourceLocation(),factory.fromEclipse(sourceType), newParents); | |||
addParent(sourceType, parent); | |||
} | |||
} |
@@ -19,14 +19,18 @@ import org.aspectj.asm.internal.ProgramElement; | |||
import org.aspectj.weaver.*; | |||
/** | |||
* !!! is this class still being used? | |||
* | |||
* @author Mik Kersten | |||
*/ | |||
public class AsmInterTypeRelationshipProvider { | |||
protected static AsmInterTypeRelationshipProvider INSTANCE = new AsmInterTypeRelationshipProvider(); | |||
public static final String INTER_TYPE_DECLARES = "declared on"; | |||
public static final String INTER_TYPE_DECLARED_BY = "aspect declarations"; | |||
public static void addRelationship( | |||
public void addRelationship( | |||
ResolvedTypeX onType, | |||
EclipseTypeMunger munger) { | |||
@@ -63,4 +67,16 @@ public class AsmInterTypeRelationshipProvider { | |||
} | |||
} | |||
} | |||
public static AsmInterTypeRelationshipProvider getDefault() { | |||
return INSTANCE; | |||
} | |||
/** | |||
* Reset the instance of this class, intended for extensibility. | |||
* This enables a subclass to become used as the default instance. | |||
*/ | |||
public static void setDefault(AsmInterTypeRelationshipProvider instance) { | |||
INSTANCE = instance; | |||
} | |||
} |
@@ -13,6 +13,7 @@ | |||
package org.aspectj.weaver; | |||
import java.util.*; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
@@ -28,6 +29,8 @@ import org.aspectj.weaver.bcel.BcelAdvice; | |||
public class AsmRelationshipProvider { | |||
protected static AsmRelationshipProvider INSTANCE = new AsmRelationshipProvider(); | |||
public static final String ADVISES = "advises"; | |||
public static final String ADVISED_BY = "advised by"; | |||
public static final String DECLARES_ON = "declares on"; | |||
@@ -36,8 +39,8 @@ public class AsmRelationshipProvider { | |||
public static final String MATCHES_DECLARE = "matches declare"; | |||
public static final String INTER_TYPE_DECLARES = "declared on"; | |||
public static final String INTER_TYPE_DECLARED_BY = "aspect declarations"; | |||
public static void checkerMunger(IHierarchy model, Shadow shadow, Checker checker) { | |||
public void checkerMunger(IHierarchy model, Shadow shadow, Checker checker) { | |||
if (shadow.getSourceLocation() == null || checker.getSourceLocation() == null) return; | |||
String sourceHandle = ProgramElement.createHandleIdentifier( | |||
@@ -65,7 +68,7 @@ public class AsmRelationshipProvider { | |||
} | |||
// For ITDs | |||
public static void addRelationship( | |||
public void addRelationship( | |||
ResolvedTypeX onType, | |||
ResolvedTypeMunger munger, | |||
ResolvedTypeX originatingAspect) { | |||
@@ -102,7 +105,7 @@ public class AsmRelationshipProvider { | |||
} | |||
} | |||
public static void addDeclareParentsRelationship(ISourceLocation decp,ResolvedTypeX targetType) { | |||
public void addDeclareParentsRelationship(ISourceLocation decp,ResolvedTypeX targetType, List newParents) { | |||
String sourceHandle = ProgramElement.createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn()); | |||
@@ -125,7 +128,7 @@ public class AsmRelationshipProvider { | |||
} | |||
public static void adviceMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) { | |||
public void adviceMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) { | |||
if (munger instanceof Advice) { | |||
Advice advice = (Advice)munger; | |||
@@ -168,7 +171,7 @@ public class AsmRelationshipProvider { | |||
} | |||
} | |||
private static IProgramElement getNode(IHierarchy model, Shadow shadow) { | |||
private IProgramElement getNode(IHierarchy model, Shadow shadow) { | |||
Member enclosingMember = shadow.getEnclosingCodeSignature(); | |||
IProgramElement enclosingNode = lookupMember(model, enclosingMember); | |||
@@ -189,13 +192,13 @@ public class AsmRelationshipProvider { | |||
} | |||
} | |||
private static boolean sourceLinesMatch(ISourceLocation loc1,ISourceLocation loc2) { | |||
private boolean sourceLinesMatch(ISourceLocation loc1,ISourceLocation loc2) { | |||
if (loc1.getLine()!=loc2.getLine()) return false; | |||
return true; | |||
} | |||
private static IProgramElement findOrCreateCodeNode(IProgramElement enclosingNode, Member shadowSig, Shadow shadow) | |||
private IProgramElement findOrCreateCodeNode(IProgramElement enclosingNode, Member shadowSig, Shadow shadow) | |||
{ | |||
for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext(); ) { | |||
IProgramElement node = (IProgramElement)it.next(); | |||
@@ -224,14 +227,14 @@ public class AsmRelationshipProvider { | |||
return peNode; | |||
} | |||
private static IProgramElement lookupMember(IHierarchy model, Member member) { | |||
private IProgramElement lookupMember(IHierarchy model, Member member) { | |||
TypeX declaringType = member.getDeclaringType(); | |||
IProgramElement classNode = | |||
model.findElementForType(declaringType.getPackageName(), declaringType.getClassName()); | |||
return findMemberInClass(classNode, member); | |||
} | |||
private static IProgramElement findMemberInClass( | |||
private IProgramElement findMemberInClass( | |||
IProgramElement classNode, | |||
Member member) | |||
{ | |||
@@ -275,4 +278,16 @@ public class AsmRelationshipProvider { | |||
// } | |||
// } | |||
public static AsmRelationshipProvider getDefault() { | |||
return INSTANCE; | |||
} | |||
/** | |||
* Reset the instance of this class, intended for extensibility. | |||
* This enables a subclass to become used as the default instance. | |||
*/ | |||
public static void setDefault(AsmRelationshipProvider instance) { | |||
INSTANCE = instance; | |||
} | |||
} |
@@ -66,7 +66,7 @@ public class Checker extends ShadowMunger { | |||
} | |||
if (world.getModel() != null) { | |||
AsmRelationshipProvider.checkerMunger(world.getModel(), shadow, this); | |||
AsmRelationshipProvider.getDefault().checkerMunger(world.getModel(), shadow, this); | |||
} | |||
} | |||
return false; |
@@ -458,7 +458,7 @@ public abstract class Shadow { | |||
if (world.getModel() != null) { | |||
//System.err.println("munger: " + munger + " on " + this); | |||
AsmRelationshipProvider.adviceMunger(world.getModel(), this, munger); | |||
AsmRelationshipProvider.getDefault().adviceMunger(world.getModel(), this, munger); | |||
} | |||
} | |||
} |
@@ -87,9 +87,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger { | |||
if (ResolvedTypeMunger.persistSourceLocation) { | |||
if (changed) { | |||
if (munger.getKind().equals(ResolvedTypeMunger.Parent)) { | |||
AsmRelationshipProvider.addRelationship(weaver.getLazyClassGen().getType(), munger,getAspectType()); | |||
AsmRelationshipProvider.getDefault().addRelationship(weaver.getLazyClassGen().getType(), munger,getAspectType()); | |||
} else { | |||
AsmRelationshipProvider.addRelationship(weaver.getLazyClassGen().getType(), munger,getAspectType()); | |||
AsmRelationshipProvider.getDefault().addRelationship(weaver.getLazyClassGen().getType(), munger,getAspectType()); | |||
} | |||
} | |||
} |