aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten <mkersten>2003-08-06 12:26:34 +0000
committermkersten <mkersten>2003-08-06 12:26:34 +0000
commit1508de05e2a9c9c8e1d2c429e8b5d0415ce0a1a5 (patch)
tree823d0b0baa65f7a5b1a3c0b710372391663817d9
parent511b6634ddd4554f30b4104d493ea7244a79d97b (diff)
downloadaspectj-1508de05e2a9c9c8e1d2c429e8b5d0415ce0a1a5.tar.gz
aspectj-1508de05e2a9c9c8e1d2c429e8b5d0415ce0a1a5.zip
Improved generation of advice and pointcut names in the ASM.
-rw-r--r--ajde/testdata/examples/coverage/ModelCoverage.java5
-rw-r--r--ajde/testdata/examples/coverage/coverage.ajsymbin19080 -> 20658 bytes
-rw-r--r--ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java56
-rw-r--r--asm/src/org/aspectj/asm/ProgramElementNode.java4
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java89
5 files changed, 125 insertions, 29 deletions
diff --git a/ajde/testdata/examples/coverage/ModelCoverage.java b/ajde/testdata/examples/coverage/ModelCoverage.java
index 6fa3255d6..6d09ba59d 100644
--- a/ajde/testdata/examples/coverage/ModelCoverage.java
+++ b/ajde/testdata/examples/coverage/ModelCoverage.java
@@ -65,9 +65,14 @@ aspect AdviceNamingCoverage {
int around(int i) throws SizeException: namedWithOneArg(i) { return proceed(i); }
before(): named() { }
+ before(int i): call(* *.mumble()) && named() && namedWithOneArg(i) { }
+ before(int i): named() && call(* *.mumble()) && namedWithOneArg(i) { }
before(): call(* *.mumble()) { }
+}
+abstract aspect AbstractAspect {
+ abstract pointcut abPtct();
}
aspect InterTypeDecCoverage {
diff --git a/ajde/testdata/examples/coverage/coverage.ajsym b/ajde/testdata/examples/coverage/coverage.ajsym
index 324199378..25bc2b070 100644
--- a/ajde/testdata/examples/coverage/coverage.ajsym
+++ b/ajde/testdata/examples/coverage/coverage.ajsym
Binary files differ
diff --git a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
index 4f2a82bbe..81f054f6b 100644
--- a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
+++ b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
@@ -18,6 +18,7 @@ import org.aspectj.asm.*;
import org.aspectj.asm.ProgramElementNode.Kind;
+// TODO: check for return types
public class AsmDeclarationsTest extends AjdeTestCase {
private StructureModel model = null;
@@ -35,12 +36,12 @@ public class AsmDeclarationsTest extends AjdeTestCase {
ProgramElementNode aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "InterTypeDecCoverage");
assertNotNull(aspect);
- String decErrMessage = "declare error: Illegal construct..";
+ String decErrMessage = "declare error: \"Illegal construct..\"";
ProgramElementNode decErrNode = model.findNode(aspect, ProgramElementNode.Kind.DECLARE_ERROR, decErrMessage);
assertNotNull(decErrNode);
assertEquals(decErrNode.getName(), decErrMessage);
- String decWarnMessage = "declare warning: Illegal construct..";
+ String decWarnMessage = "declare warning: \"Illegal construct..\"";
ProgramElementNode decWarnNode = model.findNode(aspect, ProgramElementNode.Kind.DECLARE_WARNING, decWarnMessage);
assertNotNull(decWarnNode);
assertEquals(decWarnNode.getName(), decWarnMessage);
@@ -115,6 +116,19 @@ public class AsmDeclarationsTest extends AjdeTestCase {
}
+ public void testAbstract() {
+ ProgramElementNode node = (ProgramElementNode)model.getRoot();
+ assertNotNull(node);
+
+ ProgramElementNode aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "AbstractAspect");
+ assertNotNull(aspect);
+
+ String abst = "abPtct()";
+ ProgramElementNode abstNode = model.findNode(aspect, ProgramElementNode.Kind.POINTCUT, abst);
+ assertNotNull(abstNode);
+ assertEquals(abstNode.getName(), abst);
+ }
+
public void testAdvice() {
ProgramElementNode node = (ProgramElementNode)model.getRoot();
assertNotNull(node);
@@ -122,10 +136,40 @@ public class AsmDeclarationsTest extends AjdeTestCase {
ProgramElementNode aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "AdviceNamingCoverage");
assertNotNull(aspect);
-// String anon = "<anonymous pointcut>";
-// ProgramElementNode anonNode = model.findNode(aspect, ProgramElementNode.Kind.POINTCUT, anon);
-// assertNotNull(anonNode);
-// assertEquals(anonNode.getName(), anon);
+ String anon = "before(): <anonymous pointcut>";
+ ProgramElementNode anonNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, anon);
+ assertNotNull(anonNode);
+ assertEquals(anonNode.getName(), anon);
+
+ String named = "before(): named..";
+ ProgramElementNode namedNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, named);
+ assertNotNull(namedNode);
+ assertEquals(namedNode.getName(), named);
+
+ String namedWithOneArg = "around(int): namedWithOneArg..";
+ ProgramElementNode namedWithOneArgNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, namedWithOneArg);
+ assertNotNull(namedWithOneArgNode);
+ assertEquals(namedWithOneArgNode.getName(), namedWithOneArg);
+
+ String afterReturning = "afterReturning(int, int): namedWithArgs..";
+ ProgramElementNode afterReturningNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, afterReturning);
+ assertNotNull(afterReturningNode);
+ assertEquals(afterReturningNode.getName(), afterReturning);
+
+ String around = "around(int): namedWithOneArg..";
+ ProgramElementNode aroundNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, around);
+ assertNotNull(aroundNode);
+ assertEquals(aroundNode.getName(), around);
+
+ String compAnon = "before(int): <anonymous pointcut>..";
+ ProgramElementNode compAnonNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, compAnon);
+ assertNotNull(compAnonNode);
+ assertEquals(compAnonNode.getName(), compAnon);
+
+ String compNamed = "before(int): named()..";
+ ProgramElementNode compNamedNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, compNamed);
+ assertNotNull(compNamedNode);
+ assertEquals(compNamedNode.getName(), compNamed);
}
protected void setUp() throws Exception {
diff --git a/asm/src/org/aspectj/asm/ProgramElementNode.java b/asm/src/org/aspectj/asm/ProgramElementNode.java
index 7cacd890e..37861a48f 100644
--- a/asm/src/org/aspectj/asm/ProgramElementNode.java
+++ b/asm/src/org/aspectj/asm/ProgramElementNode.java
@@ -405,5 +405,9 @@ public class ProgramElementNode extends StructureNode {
this.returnType = returnType;
}
+ public String getReturnType() {
+ return returnType;
+ }
+
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java
index eef14d7fd..b7425d426 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java
@@ -20,14 +20,55 @@ import org.eclipse.jdt.internal.compiler.ast.*;
public class AsmNodeFormatter {
+ public static final String DECLARE_PRECEDENCE = "precedence: ";
+ public static final String DECLARE_SOFT = "soft: ";
+ public static final String DECLARE_PARENTS = "parents: ";
+ public static final String DECLARE_WARNING = "warning: ";
+ public static final String DECLARE_ERROR = "error: ";
+ public static final String DECLARE_UNKNONWN = "<unknown declare>";
+ public static final String POINTCUT_ABSTRACT = "<abstract pointcut>";
+ public static final String POINTCUT_ANONYMOUS = "<anonymous pointcut>";
public static final int MAX_MESSAGE_LENGTH = 18;
public static final String DEC_LABEL = "declare";
public void genLabelAndKind(MethodDeclaration methodDeclaration, ProgramElementNode node) {
if (methodDeclaration instanceof AdviceDeclaration) {
+ AdviceDeclaration ad = (AdviceDeclaration)methodDeclaration;
node.setKind( ProgramElementNode.Kind.ADVICE);
- node.setName(translateAdviceName(new String(methodDeclaration.selector)));
-
+ String label = "";
+ label += ad.kind.toString();
+ label += "(" + genArguments(ad) + "): ";
+
+ if (ad.kind == AdviceKind.Around) {
+ node.setReturnType(ad.returnTypeToString(0));
+ }
+
+ if (ad.pointcutDesignator != null) {
+ if (ad.pointcutDesignator.getPointcut() instanceof ReferencePointcut) {
+ ReferencePointcut rp = (ReferencePointcut)ad.pointcutDesignator.getPointcut();
+ label += rp.name + "..";
+ } else if (ad.pointcutDesignator.getPointcut() instanceof AndPointcut) {
+ AndPointcut ap = (AndPointcut)ad.pointcutDesignator.getPointcut();
+ if (ap.getLeft() instanceof ReferencePointcut) {
+ label += ap.getLeft().toString() + "..";
+ } else {
+ label += POINTCUT_ANONYMOUS + "..";
+ }
+ } else if (ad.pointcutDesignator.getPointcut() instanceof OrPointcut) {
+ OrPointcut op = (OrPointcut)ad.pointcutDesignator.getPointcut();
+ if (op.getLeft() instanceof ReferencePointcut) {
+ label += op.getLeft().toString() + "..";
+ } else {
+ label += POINTCUT_ANONYMOUS + "..";
+ }
+ } else {
+ label += POINTCUT_ANONYMOUS;
+ }
+ } else {
+ label += POINTCUT_ABSTRACT;
+ }
+ node.setName(label);
+
} else if (methodDeclaration instanceof PointcutDeclaration) {
PointcutDeclaration pd = (PointcutDeclaration)methodDeclaration;
node.setKind( ProgramElementNode.Kind.POINTCUT);
@@ -43,29 +84,29 @@ public class AsmNodeFormatter {
if (deow.isError()) {
node.setKind( ProgramElementNode.Kind.DECLARE_ERROR);
- label += "error: ";
+ label += DECLARE_ERROR;
} else {
node.setKind( ProgramElementNode.Kind.DECLARE_WARNING);
- label += "warning: ";
+ label += DECLARE_WARNING;
}
- node.setName(label + genDeclareMessage(deow.getMessage())) ;
+ node.setName(label + "\"" + genDeclareMessage(deow.getMessage()) + "\"") ;
} else if (declare.declare instanceof DeclareParents) {
node.setKind( ProgramElementNode.Kind.DECLARE_PARENTS);
DeclareParents dp = (DeclareParents)declare.declare;
- node.setName(label + "parents: " + genTypePatternLabel(dp.getChild()));
+ node.setName(label + DECLARE_PARENTS + genTypePatternLabel(dp.getChild()));
} else if (declare.declare instanceof DeclareSoft) {
node.setKind( ProgramElementNode.Kind.DECLARE_SOFT);
DeclareSoft ds = (DeclareSoft)declare.declare;
- node.setName(label + "soft: " + genTypePatternLabel(ds.getException()));
+ node.setName(label + DECLARE_SOFT + genTypePatternLabel(ds.getException()));
} else if (declare.declare instanceof DeclarePrecedence) {
node.setKind( ProgramElementNode.Kind.DECLARE_PRECEDENCE);
DeclarePrecedence ds = (DeclarePrecedence)declare.declare;
- node.setName(label + "precedence: " + genPrecedenceListLabel(ds.getPatterns()));
+ node.setName(label + DECLARE_PRECEDENCE + genPrecedenceListLabel(ds.getPatterns()));
} else {
node.setKind( ProgramElementNode.Kind.ERROR);
- node.setName("<unknown declare>");
+ node.setName(DECLARE_UNKNONWN);
}
} else if (methodDeclaration instanceof InterTypeDeclaration) {
@@ -83,11 +124,9 @@ public class AsmNodeFormatter {
} else {
node.setKind(ProgramElementNode.Kind.ERROR);
}
-
node.setName(label);
node.setReturnType(itd.returnType.toString());
-
} else {
node.setKind(ProgramElementNode.Kind.METHOD);
node.setName(new String(methodDeclaration.selector));
@@ -112,11 +151,15 @@ public class AsmNodeFormatter {
String argName = new String(argArray[i].name);
String argType = argArray[i].type.toString();
// TODO: fix this way of determing ajc-added arguments, make subtype of Argument with extra info
- if (!argName.startsWith("ajc$this_")) {
- args += argType;
- if (i < argArray.length-1) args += ", ";
- }
+ if (!argName.startsWith("ajc$this_")
+ && !argType.equals("org.aspectj.lang.JoinPoint.StaticPart")
+ && !argType.equals("org.aspectj.lang.JoinPoint")
+ && !argType.equals("org.aspectj.runtime.internal.AroundClosure")) {
+ args += argType + ", ";
+ }
}
+ int lastSepIndex = args.lastIndexOf(',');
+ if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex);
return args;
}
@@ -144,14 +187,14 @@ public class AsmNodeFormatter {
}
}
- // !!! move or replace
- private String translateAdviceName(String label) {
- if (label.indexOf("before") != -1) return "before";
- if (label.indexOf("returning") != -1) return "after returning";
- if (label.indexOf("after") != -1) return "after";
- if (label.indexOf("around") != -1) return "around";
- else return "<advice>";
- }
+// // TODO:
+// private String translateAdviceName(String label) {
+// if (label.indexOf("before") != -1) return "before";
+// if (label.indexOf("returning") != -1) return "after returning";
+// if (label.indexOf("after") != -1) return "after";
+// if (label.indexOf("around") != -1) return "around";
+// else return "<advice>";
+// }
// // !!! move or replace
// private String translateDeclareName(String name) {