use of javassist.CtBehavior in project ratpack by ratpack.
the class DescribingHandlers method describeTo.
public static void describeTo(Handler handler, StringBuilder stringBuilder) {
Class<? extends Handler> clazz = handler.getClass();
if (clazz.isAnonymousClass()) {
ClassPool pool = ClassPool.getDefault();
CtClass ctClass;
try {
ctClass = pool.get(clazz.getName());
CtBehavior[] behaviors = ctClass.getDeclaredBehaviors();
List<CtBehavior> withLineNumber = Arrays.asList(behaviors).stream().filter(input -> input.getMethodInfo().getLineNumber(0) > 0).sorted((o1, o2) -> Integer.valueOf(o1.getMethodInfo().getLineNumber(0)).compareTo(o2.getMethodInfo().getLineNumber(0))).collect(Collectors.toList());
if (!withLineNumber.isEmpty()) {
CtBehavior method = withLineNumber.get(0);
int lineNumber = method.getMethodInfo().getLineNumber(0);
ClassFile classFile = ctClass.getClassFile();
String sourceFile = classFile.getSourceFile();
if (lineNumber != -1 && sourceFile != null) {
stringBuilder.append("anonymous class ").append(clazz.getName()).append(" at approximately line ").append(lineNumber).append(" of ").append(sourceFile);
return;
}
}
} catch (NotFoundException ignore) {
// fall through
}
}
stringBuilder.append(clazz.getName());
}
use of javassist.CtBehavior in project pinpoint by naver.
the class JavassistClass method hasEnclosingMethod.
@Override
public boolean hasEnclosingMethod(String methodName, String... parameterTypes) {
CtBehavior behavior;
try {
behavior = ctClass.getEnclosingBehavior();
} catch (NotFoundException ignored) {
return false;
}
if (behavior == null) {
return false;
}
final MethodInfo methodInfo = behavior.getMethodInfo2();
if (!methodInfo.getName().equals(methodName)) {
return false;
}
final String jvmSignature = JavaAssistUtils.javaTypeToJvmSignature(parameterTypes);
if (methodInfo.getDescriptor().startsWith(jvmSignature)) {
return true;
}
return false;
}
Aggregations