From: aclement Date: Tue, 5 May 2009 23:41:43 +0000 (+0000) Subject: 275032: test and fix: itd of no-arg constructor should overwrite a generated default... X-Git-Tag: V1_6_5~46 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0d29499117e53b919ba65eb8aedbd6dd2c1983a9;p=aspectj.git 275032: test and fix: itd of no-arg constructor should overwrite a generated default constructor --- diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java index 2b07291fd..ae6df8f0b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java @@ -459,9 +459,8 @@ class BcelMethod extends ResolvedMemberImpl { } /** - * A method can be parameterized if it has one or more generic parameters. A - * generic parameter (type variable parameter) is identified by the prefix - * "T" + * A method can be parameterized if it has one or more generic parameters. A generic parameter (type variable parameter) is + * identified by the prefix "T" */ public boolean canBeParameterized() { unpackGenericSignature(); @@ -474,8 +473,7 @@ class BcelMethod extends ResolvedMemberImpl { } /** - * Return the parameterized/generic return type or the normal return type if - * the method is not generic. + * Return the parameterized/generic return type or the normal return type if the method is not generic. */ public UnresolvedType getGenericReturnType() { unpackGenericSignature(); @@ -607,9 +605,8 @@ class BcelMethod extends ResolvedMemberImpl { } /** - * Returns whether or not the given object is equivalent to the current one. - * Returns true if getMethod().getCode().getCodeString() are equal. Allows - * for different line number tables. + * Returns whether or not the given object is equivalent to the current one. Returns true if + * getMethod().getCode().getCodeString() are equal. Allows for different line number tables. */ // bug 154054: is similar to equals(Object) however // doesn't require implementing equals in Method and Code @@ -623,4 +620,21 @@ class BcelMethod extends ResolvedMemberImpl { return getMethod().getCode().getCodeString().equals(o.getMethod().getCode().getCodeString()); } + /** + * Return true if the method represents the default constructor. Hard to determine this from bytecode, but the existence of the + * MethodDeclarationLineNumber attribute should tell us. + * + * @return true if this BcelMethod represents the default constructor + */ + public boolean isDefaultConstructor() { + boolean mightBe = !hasDeclarationLineNumberInfo() && name.equals("") && parameterTypes.length == 0; + if (mightBe) { + // TODO would be nice to do a check to see if the file was compiled with javac or ajc? + // maybe by checking the constant pool for aspectj strings? + return true; + } else { + return false; + } + } + } \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index c6c54d516..ddab8e9c5 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -1563,6 +1563,22 @@ public class BcelTypeMunger extends ConcreteTypeMunger { } } + // Might have to remove the default constructor - b275032 + // TODO could have tagged the type munger when the fact we needed to do this was detected earlier + if (mg.getArgumentTypes().length == 0) { + LazyMethodGen toRemove = null; + List existingMethods = currentClass.getMethodGens(); + for (Iterator iterator = existingMethods.iterator(); iterator.hasNext() && toRemove == null;) { + LazyMethodGen object = (LazyMethodGen) iterator.next(); + if (object.getName().equals("") && object.getArgumentTypes().length == 0) { + toRemove = object; + } + } + if (toRemove != null) { + currentClass.removeMethodGen(toRemove); + } + } + currentClass.addMethodGen(mg); // weaver.addLazyMethodGen(freshConstructor);