summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoracolyer <acolyer>2006-06-24 11:36:59 +0000
committeracolyer <acolyer>2006-06-24 11:36:59 +0000
commitc9f311aeeb11fb1427ec8857c24cfe3ffa6c7c9d (patch)
tree7b504df238cfdb1e0d2352c97014816eb6535f35 /weaver
parent16d8120ef10e7934c658c5457fb46e67d4ed9b78 (diff)
downloadaspectj-c9f311aeeb11fb1427ec8857c24cfe3ffa6c7c9d.tar.gz
aspectj-c9f311aeeb11fb1427ec8857c24cfe3ffa6c7c9d.zip
tests and implementation for enh 147711 (use true synthetic attribute/flag for aj synthetic members).
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/NameMangler.java25
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java39
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java28
-rw-r--r--weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt6
-rw-r--r--weaver/testdata/StaticTjpBeforeHelloWorld.txt10
-rw-r--r--weaver/testdata/TjpAround2HelloWorld.txt10
-rw-r--r--weaver/testdata/TjpAroundHelloWorld.txt10
-rw-r--r--weaver/testdata/TjpBeforeHelloWorld.txt10
8 files changed, 111 insertions, 27 deletions
diff --git a/weaver/src/org/aspectj/weaver/NameMangler.java b/weaver/src/org/aspectj/weaver/NameMangler.java
index f7a4ca776..73d349fa6 100644
--- a/weaver/src/org/aspectj/weaver/NameMangler.java
+++ b/weaver/src/org/aspectj/weaver/NameMangler.java
@@ -54,6 +54,31 @@ public class NameMangler {
public static final String INITFAILURECAUSE_FIELD_NAME = PREFIX + "initFailureCause";
+ public static boolean isSyntheticMethod(String methodName, boolean declaredInAspect) {
+ if (methodName.startsWith(PREFIX)) {
+ // it's synthetic unless it is an advice method
+ if (methodName.startsWith("ajc$before") ||
+ methodName.startsWith("ajc$after")) {
+ return false;
+ } else if (methodName.startsWith("ajc$around")) {
+ // around advice method is not synthetic, but generated proceed is...
+ return (methodName.endsWith("proceed"));
+ } else if (methodName.startsWith("ajc$interMethod$")) {
+ return false; // body of an itd-m
+ }
+ return true;
+ }
+ else if (methodName.indexOf("_aroundBody") != -1) {
+ return true;
+ }
+ else if (declaredInAspect) {
+ if (methodName.equals("aspectOf") || methodName.equals("hasAspect")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public static String perObjectInterfaceGet(UnresolvedType aspectType) {
return makeName(aspectType.getNameAsIdentifier(), "perObjectGet");
}
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
index 69ea1812b..af7a4afee 100644
--- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
+++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
@@ -37,6 +37,7 @@ import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Signature;
+import org.aspectj.apache.bcel.classfile.Synthetic;
import org.aspectj.apache.bcel.classfile.Unknown;
import org.aspectj.apache.bcel.classfile.annotation.Annotation;
import org.aspectj.apache.bcel.generic.BasicType;
@@ -80,6 +81,8 @@ import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
*/
public final class LazyClassGen {
+ private static final int ACC_SYNTHETIC = 0x1000;
+
int highestLineNumber = 0; // ---- JSR 45 info
private SortedMap /* <String, InlinedSourceFileInfo> */ inlinedFiles = new TreeMap();
@@ -1230,8 +1233,44 @@ public final class LazyClassGen {
private void addField(Field field) {
myGen.addField(field);
+ makeSyntheticAndTransientIfNeeded(field);
+ }
+
+ private void makeSyntheticAndTransientIfNeeded(Field field) {
+ if (field.getName().startsWith(NameMangler.PREFIX)) {
+ // it's an aj added field
+ // first do transient
+ if (!field.isStatic()) {
+ field.setModifiers(field.getModifiers() | Constants.ACC_TRANSIENT);
+ }
+ // then do synthetic
+ if (getWorld().isInJava5Mode()) {
+ // add the synthetic modifier flag
+ field.setModifiers(field.getModifiers() | ACC_SYNTHETIC);
+ }
+ if (!hasSyntheticAttribute(field.getAttributes())) {
+ // belt and braces, do the attribute even on Java 5 in addition to the modifier flag
+ Attribute[] oldAttrs = field.getAttributes();
+ Attribute[] newAttrs = new Attribute[oldAttrs.length + 1];
+ System.arraycopy(oldAttrs, 0, newAttrs, 0, oldAttrs.length);
+ ConstantPoolGen cpg = myGen.getConstantPool();
+ int index = cpg.addUtf8("Synthetic");
+ Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg.getConstantPool());
+ newAttrs[newAttrs.length - 1] = synthetic;
+ field.setAttributes(newAttrs);
+ }
+ }
}
+ private boolean hasSyntheticAttribute(Attribute[] attributes) {
+ for (int i = 0; i < attributes.length; i++) {
+ if (attributes[i].getName().equals("Synthetic")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public void replaceField(Field oldF, Field newF){
myGen.removeField(oldF);
myGen.addField(newF);
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
index 07ebbe3a1..d377cf509 100644
--- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
+++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
@@ -63,6 +63,7 @@ import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.MemberImpl;
+import org.aspectj.weaver.NameMangler;
import org.aspectj.weaver.ResolvedMember;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.Shadow;
@@ -86,6 +87,8 @@ import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
*/
public final class LazyMethodGen {
+ private static final int ACC_SYNTHETIC = 0x1000;
+
private int accessFlags;
private Type returnType;
private final String name;
@@ -918,6 +921,8 @@ public final class LazyMethodGen {
// ---- packing!
public MethodGen pack() {
+ forceSyntheticForAjcMagicMembers();
+
//killNops();
int flags = getAccessFlags();
if (enclosingClass.getWorld().isJoinpointSynchronizationEnabled()) {
@@ -957,9 +962,13 @@ public final class LazyMethodGen {
}
if (isSynthetic) {
- ConstantPoolGen cpg = gen.getConstantPool();
- int index = cpg.addUtf8("Synthetic");
- gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg.getConstantPool()));
+ if (enclosingClass.getWorld().isInJava5Mode()) {
+ gen.setModifiers(gen.getModifiers() | ACC_SYNTHETIC);
+ }
+ // belt and braces, do the attribute even on Java 5 in addition to the modifier flag
+ ConstantPoolGen cpg = gen.getConstantPool();
+ int index = cpg.addUtf8("Synthetic");
+ gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg.getConstantPool()));
}
if (hasBody()) {
@@ -972,7 +981,18 @@ public final class LazyMethodGen {
return gen;
}
- public void makeSynthetic() {
+ private void forceSyntheticForAjcMagicMembers() {
+ if (NameMangler.isSyntheticMethod(getName(), inAspect())) {
+ makeSynthetic();
+ }
+ }
+
+ private boolean inAspect() {
+ BcelObjectType objectType = enclosingClass.getBcelObjectType();
+ return (objectType == null ? false : objectType.isAspect());
+ }
+
+ public void makeSynthetic() {
isSynthetic = true;
}
diff --git a/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt b/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt
index d0d4f15e1..fc806f810 100644
--- a/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt
+++ b/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt
@@ -1,8 +1,8 @@
public class HelloWorld extends java.lang.Object:
- private static final org.aspectj.lang.JoinPoint$EnclosingStaticPart ajc$tjp_0
- private static final org.aspectj.lang.JoinPoint$EnclosingStaticPart ajc$tjp_1
+ private static final org.aspectj.lang.JoinPoint$EnclosingStaticPart ajc$tjp_0 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$EnclosingStaticPart ajc$tjp_1 [Synthetic]
public void <init>():
- ALOAD_0 // HelloWorld this (line 5)
+ ALOAD_0 // LHelloWorld; this (line 5)
INVOKESPECIAL java.lang.Object.<init> ()V
constructor-execution(void HelloWorld.<init>())
| GETSTATIC HelloWorld.ajc$tjp_0 Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart;
diff --git a/weaver/testdata/StaticTjpBeforeHelloWorld.txt b/weaver/testdata/StaticTjpBeforeHelloWorld.txt
index 6f38203d2..6bc961dab 100644
--- a/weaver/testdata/StaticTjpBeforeHelloWorld.txt
+++ b/weaver/testdata/StaticTjpBeforeHelloWorld.txt
@@ -1,10 +1,10 @@
public class HelloWorld extends java.lang.Object:
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3 [Synthetic]
public void <init>():
- ALOAD_0 // HelloWorld this (line 5)
+ ALOAD_0 // LHelloWorld; this (line 5)
INVOKESPECIAL java.lang.Object.<init> ()V
constructor-execution(void HelloWorld.<init>())
| GETSTATIC HelloWorld.ajc$tjp_0 Lorg/aspectj/lang/JoinPoint$StaticPart;
diff --git a/weaver/testdata/TjpAround2HelloWorld.txt b/weaver/testdata/TjpAround2HelloWorld.txt
index 05cd14d22..a267a3351 100644
--- a/weaver/testdata/TjpAround2HelloWorld.txt
+++ b/weaver/testdata/TjpAround2HelloWorld.txt
@@ -1,10 +1,10 @@
public class HelloWorld extends java.lang.Object:
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3 [Synthetic]
public void <init>():
- ALOAD_0 // HelloWorld this (line 5)
+ ALOAD_0 // LHelloWorld; this (line 5)
INVOKESPECIAL java.lang.Object.<init> ()V
GETSTATIC HelloWorld.ajc$tjp_0 Lorg/aspectj/lang/JoinPoint$StaticPart;
ALOAD_0
diff --git a/weaver/testdata/TjpAroundHelloWorld.txt b/weaver/testdata/TjpAroundHelloWorld.txt
index 6cb8f4544..4c8654948 100644
--- a/weaver/testdata/TjpAroundHelloWorld.txt
+++ b/weaver/testdata/TjpAroundHelloWorld.txt
@@ -1,10 +1,10 @@
public class HelloWorld extends java.lang.Object:
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3 [Synthetic]
public void <init>():
- ALOAD_0 // HelloWorld this (line 5)
+ ALOAD_0 // LHelloWorld; this (line 5)
INVOKESPECIAL java.lang.Object.<init> ()V
GETSTATIC HelloWorld.ajc$tjp_0 Lorg/aspectj/lang/JoinPoint$StaticPart;
ALOAD_0
diff --git a/weaver/testdata/TjpBeforeHelloWorld.txt b/weaver/testdata/TjpBeforeHelloWorld.txt
index 38b3766ed..910465ee1 100644
--- a/weaver/testdata/TjpBeforeHelloWorld.txt
+++ b/weaver/testdata/TjpBeforeHelloWorld.txt
@@ -1,10 +1,10 @@
public class HelloWorld extends java.lang.Object:
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2
- private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_1 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_2 [Synthetic]
+ private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_3 [Synthetic]
public void <init>():
- ALOAD_0 // HelloWorld this (line 5)
+ ALOAD_0 // LHelloWorld; this (line 5)
INVOKESPECIAL java.lang.Object.<init> ()V
GETSTATIC HelloWorld.ajc$tjp_0 Lorg/aspectj/lang/JoinPoint$StaticPart;
ALOAD_0