public static String getParameterSignure(CtMethod ctMethod) { StringBuilder methodSignure = new StringBuilder(); try { for (int i = 0; i < ctMethod.getParameterTypes().length; i++) { methodSignure.append(ctMethod.getParameterTypes()[i].getName()); methodSignure.append(" var" + i); if (i != ctMethod.getParameterTypes().length - 1) { methodSignure.append(","); } } } catch (Exception e) { e.printStackTrace(); } return methodSignure.toString(); }
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(); }
/** * get method desc. * "(I)I", "()V", "(Ljava/lang/String;Z)V". * * @param m method. * @return desc. */ public static String getDescWithoutMethodName(final CtMethod m) throws NotFoundException { StringBuilder ret = new StringBuilder(); ret.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. * "(I)I", "()V", "(Ljava/lang/String;Z)V". * * @param m method. * @return desc. */ public static String getDescWithoutMethodName(final CtMethod m) throws NotFoundException { StringBuilder ret = new StringBuilder(); ret.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(); }
private String getParametersClassType(CtMethod method) throws NotFoundException { if (method.getParameterTypes().length == 0) { return " null "; } StringBuilder parameterType = new StringBuilder(); parameterType.append("new Class[]{"); for (CtClass paramterClass : method.getParameterTypes()) { parameterType.append(paramterClass.getName()).append(".class,"); } //remove last ',' if (',' == parameterType.charAt(parameterType.length() - 1)) parameterType.deleteCharAt(parameterType.length() - 1); parameterType.append("}"); return parameterType.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(); }
/** * 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 TransformBefore(Transformer next, CtMethod origMethod, CtMethod beforeMethod) throws NotFoundException { super(next, origMethod, beforeMethod); // override methodDescriptor = origMethod.getMethodInfo2().getDescriptor(); parameterTypes = origMethod.getParameterTypes(); locals = 0; maxLocals = 0; saveCode = loadCode = null; }
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 "); }
try { if ( method.isEmpty() || method.getParameterTypes().length != 0 ) { continue;
public TransformBefore(Transformer next, CtMethod origMethod, CtMethod beforeMethod) throws NotFoundException { super(next, origMethod, beforeMethod); // override methodDescriptor = origMethod.getMethodInfo2().getDescriptor(); parameterTypes = origMethod.getParameterTypes(); locals = 0; maxLocals = 0; saveCode = loadCode = null; }
public void defineStructSetCAS(FSTClazzInfo.FSTFieldInfo casAcc, FSTClazzInfo clInfo, CtMethod method) { int off = casAcc.getStructOffset(); try { if ( method.getParameterTypes().length != 2 ) { throw new RuntimeException("CAS setter requires expected and newValue args"); } } catch (NotFoundException e) { e.printStackTrace(); } try { if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapInt("+off+"+___offset,$1,$2);"); } else if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapLong("+off+"+___offset,$1,$2);"); } else { throw new RuntimeException("CAS access only applicable to int and long."); } } catch (CannotCompileException e) { throw new RuntimeException(e); } }
public void defineStructSetCAS(FSTClazzInfo.FSTFieldInfo casAcc, FSTClazzInfo clInfo, CtMethod method) { int off = casAcc.getStructOffset(); try { if ( method.getParameterTypes().length != 2 ) { throw new RuntimeException("CAS setter requires expected and newValue args"); } } catch (NotFoundException e) { e.printStackTrace(); } try { if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapInt("+off+"+___offset,$1,$2);"); } else if ( casAcc.getType() == int.class ) { method.setBody("return ___bytes.compareAndSwapLong("+off+"+___offset,$1,$2);"); } else { throw new RuntimeException("CAS access only applicable to int and long."); } } catch (CannotCompileException e) { throw new RuntimeException(e); } }
@Override public void defineArrayPointer(FSTClazzInfo.FSTFieldInfo indexfi, FSTClazzInfo clInfo, CtMethod method) { int index = indexfi.getStructOffset(); CtClass[] parameterTypes = new CtClass[0]; try { parameterTypes = method.getParameterTypes(); } catch (NotFoundException e) { e.printStackTrace(); } if ( parameterTypes != null && parameterTypes.length ==1 ) { try { if (indexfi.isIntegral()) { method.setBody("{ ___fac.fillPrimitiveArrayBasePointer($1,___bytes, ___offset, "+index+"); }"); } else { method.setBody("{ ___fac.fillTypedArrayBasePointer($1,___bytes, ___offset, "+index+"); }"); } } catch (CannotCompileException e) { throw new RuntimeException(e); } } else { try { if (indexfi.isIntegral()) { method.setBody("{ return (org.nustaq.offheap.structs.FSTStruct)___fac.createPrimitiveArrayBasePointer(___bytes, ___offset, "+index+"); }"); } else method.setBody("{ return ("+indexfi.getArrayType().getName()+")___fac.createTypedArrayBasePointer(___bytes, ___offset, "+index+"); }"); } catch (CannotCompileException e) { throw new RuntimeException(e); } } }
public static List<Method> getDeclaredMethods(Class<?> clazz) { ClassPool cp = new ClassPool(); cp.insertClassPath(new ClassClassPath(clazz)); CtClass cc; try { cc = cp.get(clazz.getName()); } catch (NotFoundException e) { throw U.rte("Cannot find the target class!", e); } List<Method> methods = U.list(); for (CtMethod m : cc.getDeclaredMethods()) { try { methods.add(getMethod(clazz, m.getName(), ctTypes(m.getParameterTypes()))); } catch (Exception e) { throw U.rte(e); } } return methods; }
m.getParameterTypes(), m.getExceptionTypes(), body, ConstParameter.integer(identifier), clazz);
CtClass retType; try { params = getParameterTypes(); retType = getReturnType();
CtClass retType; try { params = getParameterTypes(); retType = getReturnType();
boolean isStatic = Modifier.isStatic(delegate.getModifiers()); CtClass deleClass = delegate.getDeclaringClass(); CtClass[] params = delegate.getParameterTypes(); int s; if (isStatic) {
boolean isStatic = Modifier.isStatic(delegate.getModifiers()); CtClass deleClass = delegate.getDeclaringClass(); CtClass[] params = delegate.getParameterTypes(); int s; if (isStatic) {