}
/**
- * 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();
}
/**
- * 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();
}
/**
- * 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
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("<init>") && 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
}
}
+ // 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("<init>") && object.getArgumentTypes().length == 0) {
+ toRemove = object;
+ }
+ }
+ if (toRemove != null) {
+ currentClass.removeMethodGen(toRemove);
+ }
+ }
+
currentClass.addMethodGen(mg);
// weaver.addLazyMethodGen(freshConstructor);