public TransformCall(Transformer next, CtMethod origMethod, CtMethod substMethod) { this(next, origMethod.getName(), substMethod); classname = origMethod.getDeclaringClass().getName(); }
/** * get method desc. * "do(I)I", "do()V", "do(Ljava/lang/String;Z)V" * * @param m method. * @return desc. */ public static String getDesc(final CtMethod m) throws NotFoundException { StringBuilder ret = new StringBuilder(m.getName()).append('('); CtClass[] parameterTypes = m.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { ret.append(getDesc(parameterTypes[i])); } ret.append(')').append(getDesc(m.getReturnType())); return ret.toString(); }
/** * get method desc. * "do(I)I", "do()V", "do(Ljava/lang/String;Z)V" * * @param m method. * @return desc. */ public static String getDesc(final CtMethod m) throws NotFoundException { StringBuilder ret = new StringBuilder(m.getName()).append('('); CtClass[] parameterTypes = m.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { ret.append(getDesc(parameterTypes[i])); } ret.append(')').append(getDesc(m.getReturnType())); return ret.toString(); }
public TransformCall(Transformer next, CtMethod origMethod, CtMethod substMethod) { this(next, origMethod.getName(), substMethod); classname = origMethod.getDeclaringClass().getName(); }
private CtMethod findOriginal(CtMethod m, boolean dontSearch) throws NotFoundException { if (dontSearch) return m; String name = m.getName(); CtMethod[] ms = m.getDeclaringClass().getDeclaredMethods(); for (int i = 0; i < ms.length; ++i) { String orgName = ms[i].getName(); if (orgName.endsWith(name) && orgName.startsWith(ClassMetaobject.methodPrefix) && ms[i].getSignature().equals(m.getSignature())) return ms[i]; } return m; }
public static String getJavaMethodSignure(CtMethod ctMethod) throws NotFoundException { StringBuilder methodSignure = new StringBuilder(); methodSignure.append(ctMethod.getName()); methodSignure.append("("); for (int i = 0; i < ctMethod.getParameterTypes().length; i++) { methodSignure.append(ctMethod.getParameterTypes()[i].getName()); if (i != ctMethod.getParameterTypes().length - 1) { methodSignure.append(","); } } methodSignure.append(")"); return methodSignure.toString(); }
private static boolean isDefaultMethod(Class<?> intf, CtMethod intfMethod) throws Exception { List<Class<?>> paramTypes = new ArrayList<>(); for (CtClass pt : intfMethod.getParameterTypes()) { paramTypes.add(toJavaClass(pt)); } return intf.getDeclaredMethod(intfMethod.getName(), paramTypes.toArray(new Class[0])).toString().contains("default "); }
/** * 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()); }
private static void checkSignature(CtMethod wrappedBody, String descriptor) throws CannotCompileException { if (!descriptor.equals(wrappedBody.getMethodInfo2().getDescriptor())) throw new CannotCompileException( "wrapped method with a bad signature: " + wrappedBody.getDeclaringClass().getName() + '.' + wrappedBody.getName()); }
protected String methodDescription(CtMethod method) { return method.getDeclaringClass().getName() + "|" + method.getName() + "|" + method.getSignature(); }
private String getMethodString(CtMethod method) { try { return Modifier.toString(method.getModifiers()) + " " + method.getReturnType().getName() + " " + method.getName() + Descriptor.toString(method.getSignature()) + ";"; } catch (NotFoundException e) { throw new RuntimeException(e); } }
/** * Returns the method name followed by parameter types * such as <code>javassist.CtMethod.setBody(String)</code>. * * @since 3.5 */ @Override public String getLongName() { return getDeclaringClass().getName() + "." + getName() + Descriptor.toString(getSignature()); }
public TransformCall(Transformer next, String oldMethodName, CtMethod substMethod) { super(next); methodname = oldMethodName; methodDescriptor = substMethod.getMethodInfo2().getDescriptor(); classname = newClassname = substMethod.getDeclaringClass().getName(); newMethodname = substMethod.getName(); constPool = null; newMethodIsPrivate = Modifier.isPrivate(substMethod.getModifiers()); }
private static void checkSignature(CtMethod wrappedBody, String descriptor) throws CannotCompileException { if (!descriptor.equals(wrappedBody.getMethodInfo2().getDescriptor())) throw new CannotCompileException( "wrapped method with a bad signature: " + wrappedBody.getDeclaringClass().getName() + '.' + wrappedBody.getName()); }
public static int addMethod(ConstPool cPool, CtMethod method) { return cPool.addMethodrefInfo( cPool.getThisClassInfo(), method.getName(), method.getSignature() ); }
private String getMethodString(CtMethod method) { try { return Modifier.toString(method.getModifiers()) + " " + method.getReturnType().getName() + " " + method.getName() + Descriptor.toString(method.getSignature()) + ";"; } catch (NotFoundException e) { throw new RuntimeException(e); } }
public TransformCall(Transformer next, String oldMethodName, CtMethod substMethod) { super(next); methodname = oldMethodName; methodDescriptor = substMethod.getMethodInfo2().getDescriptor(); classname = newClassname = substMethod.getDeclaringClass().getName(); newMethodname = substMethod.getName(); constPool = null; newMethodIsPrivate = Modifier.isPrivate(substMethod.getModifiers()); }
/** * Constructs an annotation that can be accessed through the interface * represented by <code>clazz</code>. The values of the members are * not specified. * * @param cp the constant pool table. * @param clazz the interface. * @throws NotFoundException when the clazz is not found */ public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException { // todo Enums are not supported right now. this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp); if (!clazz.isInterface()) throw new RuntimeException( "Only interfaces are allowed for Annotation creation."); CtMethod methods[] = clazz.getDeclaredMethods(); if (methods.length > 0) { members = new LinkedHashMap(); } for (int i = 0; i < methods.length; i++) { CtClass returnType = methods[i].getReturnType(); addMemberValue(methods[i].getName(), createMemberValue(cp, returnType)); } }