From f05e07fbdd07acc31c7c49b595da0fe3d32f0c79 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 19 Apr 2006 11:48:22 +0000 Subject: [PATCH] fix for 137479: better isSynthetic() logic --- .../aspectj/weaver/ResolvedMemberImpl.java | 3 +- .../org/aspectj/weaver/bcel/BcelMethod.java | 29 +++++++++++++++++++ .../aspectj/weaver/bcel/LazyMethodGen.java | 6 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java index dad942f6c..2049b554c 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java @@ -333,7 +333,8 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno } public boolean isSynthetic() { - return false; + // See Bcelmethod.isSynthetic() which takes account of preJava5 Synthetic modifier + return (modifiers & 4096)!=0; // do we know better? } public void write(DataOutputStream s) throws IOException { diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java index ac8aef227..a9129fd62 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java @@ -22,6 +22,7 @@ import java.util.List; import org.aspectj.apache.bcel.classfile.Attribute; import org.aspectj.apache.bcel.classfile.ExceptionTable; import org.aspectj.apache.bcel.classfile.GenericSignatureParser; +import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.LocalVariable; import org.aspectj.apache.bcel.classfile.LocalVariableTable; import org.aspectj.apache.bcel.classfile.Method; @@ -47,6 +48,8 @@ final class BcelMethod extends ResolvedMemberImpl { private Method method; private boolean isAjSynthetic; + private boolean isSynthetic; + private boolean knowIfSynthetic = false; private ShadowMunger associatedShadowMunger; private ResolvedPointcutDefinition preResolvedPointcut; // used when ajc has pre-resolved the pointcut of some @Advice @@ -395,4 +398,30 @@ final class BcelMethod extends ResolvedMemberImpl { method = null; } } + + public boolean isSynthetic() { + if (!knowIfSynthetic) workOutIfSynthetic(); + return isSynthetic; + } + + // Pre Java5 synthetic is an attribute 'Synthetic', post Java5 it is a modifier (4096 or 0x1000) + private void workOutIfSynthetic() { + knowIfSynthetic=true; + JavaClass jc = bcelObjectType.getJavaClass(); + isSynthetic=false; + if (jc==null) return; // what the hell has gone wrong? + if (jc.getMajor()<49/*Java5*/) { + // synthetic is an attribute + String[] synthetics = getAttributeNames(false); + if (synthetics!=null) { + for (int i = 0; i < synthetics.length; i++) { + if (synthetics[i].equals("Synthetic")) {isSynthetic=true;break;} + } + } + } else { + // synthetic is a modifier (4096) + isSynthetic = (modifiers&4096)!=0; + } + } + } diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java index b5122899a..2c8219356 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -1464,6 +1464,12 @@ public final class LazyMethodGen { return memberView.isAjSynthetic(); } + + boolean isSynthetic() { + if (memberView == null) return false; + return memberView.isSynthetic(); + } + public ISourceLocation getSourceLocation() { if (memberView!=null) return memberView.getSourceLocation(); return null; -- 2.39.5