<h2>Changes</h2>
+<p>-version 3.5
+
<p>-version 3.4 on November 17, 2006
<ul>
<li>A bug in CodeConverter#replaceFieldRead() and CodeConverter#replaceFieldWrite()
String d1 = origMethod.getMethodInfo2().getDescriptor();
String d2 = substMethod.getMethodInfo2().getDescriptor();
if (!d1.equals(d2))
- throw new CannotCompileException("signature mismatch");
+ throw new CannotCompileException("signature mismatch: "
+ + substMethod.getLongName());
int mod1 = origMethod.getModifiers();
int mod2 = substMethod.getModifiers();
|| (Modifier.isPrivate(mod1) && !Modifier.isPrivate(mod2))
|| origMethod.getDeclaringClass().isInterface()
!= substMethod.getDeclaringClass().isInterface())
- throw new CannotCompileException("invoke-type mismatch");
+ throw new CannotCompileException("invoke-type mismatch "
+ + substMethod.getLongName());
transformers = new TransformCall(transformers, origMethod,
substMethod);
buffer.append(methodInfo.getDescriptor());
}
+ /**
+ * Returns the method or constructor name followed by parameter types
+ * such as <code>javassist.CtBehavior.stBody(String)</code>.
+ *
+ * @since 3.5
+ */
+ public abstract String getLongName();
+
/**
* Returns the MethodInfo representing this method/constructor in the
* class file.
/**
* The version number of this release.
*/
- public static final String version = "3.4";
+ public static final String version = "3.5unstable";
/**
* Prints the version number and the copyright notice.
return methodInfo.isStaticInitializer();
}
+ /**
+ * Returns the constructor name followed by parameter types
+ * such as <code>javassist.CtConstructor(CtClass[],CtClass)</code>.
+ *
+ * @since 3.5
+ */
+ public String getLongName() {
+ return getDeclaringClass().getName()
+ + (isConstructor() ? Descriptor.toString(getSignature())
+ : ("." + MethodInfo.nameClinit + "()"));
+ }
+
/**
* Obtains the name of this constructor.
* It is the same as the simple name of the class declaring this
&& ((CtMethod)obj).getStringRep().equals(getStringRep());
}
+ /**
+ * Returns the method name followed by parameter types
+ * such as <code>javassist.CtMethod.setBody(String)</code>.
+ *
+ * @since 3.5
+ */
+ public String getLongName() {
+ return getDeclaringClass().getName() + "."
+ + getName() + Descriptor.toString(getSignature());
+ }
+
/**
* Obtains the name of this method.
*/
return n;
}
+ /**
+ * Returns a human-readable representation of the
+ * given descriptor. For example, <code>Ljava/lang/Object;</code>
+ * is converted into <code>java.lang.Object</code>.
+ * <code>(I[I)V</code> is converted into <code>(int, int[])</code>
+ * (the return type is ignored).
+ */
+ public static String toString(String desc) {
+ return PrettyPrinter.toString(desc);
+ }
+
+ static class PrettyPrinter {
+ static String toString(String desc) {
+ StringBuffer sbuf = new StringBuffer();
+ if (desc.charAt(0) == '(') {
+ int pos = 1;
+ sbuf.append('(');
+ while (desc.charAt(pos) != ')') {
+ if (pos > 1)
+ sbuf.append(',');
+
+ pos = readType(sbuf, pos, desc);
+ }
+
+ sbuf.append(')');
+ }
+ else
+ readType(sbuf, 0, desc);
+
+ return sbuf.toString();
+ }
+
+ static int readType(StringBuffer sbuf, int pos, String desc) {
+ char c = desc.charAt(pos);
+ int arrayDim = 0;
+ while (c == '[') {
+ arrayDim++;
+ c = desc.charAt(++pos);
+ }
+
+ if (c == 'L')
+ while (true) {
+ c = desc.charAt(++pos);
+ if (c == ';')
+ break;
+
+ if (c == '/')
+ c = '.';
+
+ sbuf.append(c);
+ }
+ else {
+ CtClass t = toPrimitiveClass(c);
+ sbuf.append(t.getName());
+ }
+
+ while (arrayDim-- > 0)
+ sbuf.append("[]");
+
+ return pos + 1;
+ }
+ }
+
/**
* An Iterator over a descriptor.
*/