From eb12f56518d08c54fc17047749a5d2d66b3c4181 Mon Sep 17 00:00:00 2001 From: mkersten Date: Sat, 16 Aug 2003 03:14:36 +0000 Subject: [PATCH] Added spacewar project for testing. --- .../examples/coverage/ModelCoverage.java | 2 +- .../org/aspectj/ajde/AsmDeclarationsTest.java | 2 +- .../aspectj/ajde/AsmRelationshipsTest.java | 27 ++++++++++++++ .../AsmInterTypeRelationshipProvider.java | 1 - ...ider.java => AsmRelationshipProvider.java} | 35 +++++++++++++++---- weaver/src/org/aspectj/weaver/Shadow.java | 2 +- 6 files changed, 59 insertions(+), 10 deletions(-) rename weaver/src/org/aspectj/weaver/{AsmAdviceRelationshipProvider.java => AsmRelationshipProvider.java} (81%) diff --git a/ajde/testdata/examples/coverage/ModelCoverage.java b/ajde/testdata/examples/coverage/ModelCoverage.java index bb977e36c..51fb54b89 100644 --- a/ajde/testdata/examples/coverage/ModelCoverage.java +++ b/ajde/testdata/examples/coverage/ModelCoverage.java @@ -107,7 +107,7 @@ aspect DeclareCoverage { pointcut illegalNewFigElt(): call(Point.new(..)) && !withincode(* *.doIt(..)); declare error: illegalNewFigElt(): "Illegal constructor call."; - declare warning: illegalNewFigElt(): "Illegal constructor call."; + declare warning: call(* Point.setX(..)): "Illegal call."; declare parents: Point extends java.io.Serializable; declare parents: Point+ implements java.util.Observable; diff --git a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java index 9d7bdf79c..028d84140 100644 --- a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java +++ b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java @@ -55,7 +55,7 @@ public class AsmDeclarationsTest extends AjdeTestCase { assertNotNull(decErrNode); assertEquals(decErrNode.toLabelString(), label); - String decWarnMessage = "declare warning: \"Illegal construct..\""; + String decWarnMessage = "declare warning: \"Illegal call.\""; IProgramElement decWarnNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_WARNING, "declare warning"); assertNotNull(decWarnNode); assertEquals(decWarnNode.toLabelString(), decWarnMessage); diff --git a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java index 85df30d08..f4b41a846 100644 --- a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java +++ b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java @@ -24,6 +24,11 @@ public class AsmRelationshipsTest extends AjdeTestCase { public AsmRelationshipsTest(String name) { super(name); } + + public void testDeclareWarningAndError() { + checkDeclareMapping("DeclareCoverage", "Point", "declare warning: \"Illegal call.\"", + "method-call(void Point.setX(int))", "matched by", "matches declare", IProgramElement.Kind.DECLARE_WARNING); + } public void testInterTypeDeclarations() { checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point", @@ -41,6 +46,28 @@ public class AsmRelationshipsTest extends AjdeTestCase { "field-set(int Point.x)", "advises"); } + private void checkDeclareMapping(String fromType, String toType, String from, String to, + String forwardRelName, String backRelName, IProgramElement.Kind kind) { + + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType); + assertNotNull(aspect); + String beforeExec = from; + IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, kind, beforeExec); + assertNotNull(beforeExecNode); + IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.DECLARE, forwardRelName); + String handle = (String)rel.getTargets().get(0); + assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to); + + IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType); + assertNotNull(clazz); + String set = to; + IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.CODE, set); + assertNotNull(setNode); + IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.DECLARE, backRelName); + String handle2 = (String)rel2.getTargets().get(0); + assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from); + } + private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java index 46a155204..88a9e1953 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java @@ -53,7 +53,6 @@ public class AsmInterTypeRelationshipProvider { onType.getSourceLocation().getLine(), onType.getSourceLocation().getColumn()); -// System.err.println(">> putting: " + sourceHandle + ", to " + targetHandle); IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap(); if (sourceHandle != null && targetHandle != null) { IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARES); diff --git a/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java similarity index 81% rename from weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java rename to weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java index 59f65ed8d..b6ce56445 100644 --- a/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java +++ b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java @@ -13,24 +13,47 @@ package org.aspectj.weaver; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; import org.aspectj.asm.*; import org.aspectj.asm.internal.ProgramElement; -import org.aspectj.bridge.*; +import org.aspectj.bridge.ISourceLocation; +import org.aspectj.bridge.SourceLocation; -public class AsmAdviceRelationshipProvider { +public class AsmRelationshipProvider { public static final String ADVISES = "advises"; public static final String ADVISED_BY = "advised by"; public static final String DECLARES_ON = "declares on"; public static final String DECLAREDY_BY = "declared by"; + public static final String MATCHED_BY = "matched by"; + public static final String MATCHES_DECLARE = "matches declare"; - public static void checkerMunger(IHierarchy model, Shadow shadow) { -// System.err.println("> " + shadow.getThisVar() + " to " + shadow.getTargetVar()); + public static void checkerMunger(IHierarchy model, Shadow shadow, Checker checker) { + if (shadow.getSourceLocation() == null || checker == null) return; + + String sourceHandle = ProgramElement.createHandleIdentifier( + checker.getSourceLocation().getSourceFile(), + checker.getSourceLocation().getLine(), + checker.getSourceLocation().getColumn()); + + String targetHandle = ProgramElement.createHandleIdentifier( + shadow.getSourceLocation().getSourceFile(), + shadow.getSourceLocation().getLine(), + shadow.getSourceLocation().getColumn()); + + IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap(); + if (sourceHandle != null && targetHandle != null) { + IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE, MATCHED_BY); + foreward.getTargets().add(targetHandle); + + IRelationship back = mapper.get(targetHandle, IRelationship.Kind.DECLARE, MATCHES_DECLARE); + back.getTargets().add(sourceHandle); + } } - public static void nodeMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) { + public static void adviceMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) { if (munger instanceof Advice) { Advice advice = (Advice)munger; if (advice.getKind().isPerEntry() || advice.getKind().isCflow()) { diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index a8a1ebd94..029a16d69 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -341,7 +341,7 @@ public abstract class Shadow { munger.implementOn(this); if (world.getModel() != null) { //System.err.println("munger: " + munger + " on " + this); - AsmAdviceRelationshipProvider.nodeMunger(world.getModel(), this, munger); + AsmRelationshipProvider.adviceMunger(world.getModel(), this, munger); } } } -- 2.39.5