You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
biz code:
public String buildWord(){
List users = new ArrayList();
List names = users.stream()
//.filter(e -> e.isCool() &&e.getName().equals(""))
.filter(User::isCool)
.map(User::getName)
.collect(Collectors.toList());
return names.toString();
}
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(Collections.singletonList(ClasspathHelper.forClass(UsageTest.class)))
.setScanners(new MemberUsageScanner()));
Method[] methods = User.class.getDeclaredMethods();
for (Method method : methods) {
Collection members = reflections.getMemberUsage(method);
System.out.println("method:"+method+",members:"+members);
}
members return null.
The text was updated successfully, but these errors were encountered:
or simple use like this;
ByteCodeCollector collector = new ByteCodeCollector();
List list = collector.buildInstructions(member);
for (Instruction instruction : list) {
if (instruction instanceof InvokeInstruction) {
InvokeInstruction invokeInstruction = (InvokeInstruction) instruction;
MethodIdentifier methodIdentifier = invokeInstruction.getIdentifier();
System.out.println("methodIdentifier:" + methodIdentifier);
}
if (instruction instanceof InvokeDynamicInstruction) {
InvokeDynamicInstruction invokeDynamicInstruction = (InvokeDynamicInstruction) instruction;
MethodIdentifier methodIdentifier = invokeDynamicInstruction.getIdentifier();
System.out.println("methodIdentifier:" + methodIdentifier);
}
}
or if you like ,you can update MemberUsageScanner like this( I do not test them,copy from up.)
MethodInfo methodInfo = member.getMethodInfo();
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
ConstPool pool = methodInfo.getConstPool();
CodeIterator codeIterator = codeAttribute.iterator();
final int lambdaIndex = pool.getInvokeDynamicNameAndType(index);
final String lambdaSignature = pool.getUtf8Info(pool.getNameAndTypeDescriptor(lambdaIndex));
final String lambdaMethodName = pool.getUtf8Info(pool.getNameAndTypeName(lambdaIndex));
final SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(lambdaSignature);
SignatureAttribute.Type lambdaReturnType = methodSignature.getReturnType();
SignatureAttribute.Type[] lambdaParameters = methodSignature.getParameterTypes();
final CtClass ctClass;
try {
ctClass = ClassPool.getDefault().get(pool.getClassName());
} catch (NotFoundException e) {
throw new IllegalStateException("Could not analyze bytecode");
}
final BootstrapMethodsAttribute bootstrapMethods = (BootstrapMethodsAttribute) ctClass.getClassFile().getAttribute("BOOTSTRAP_ATTRIBUTE_NAME");
final int bootstrapIndex = pool.getInvokeDynamicBootstrap(index);
final int actualMethodIndex = bootstrapMethods.getMethods()[bootstrapIndex].arguments[1];
final int actualMethodRefIndex = pool.getMethodHandleIndex(actualMethodIndex);
final boolean actualMethodStatic = pool.getMethodHandleKind(actualMethodIndex) == ConstPool.REF_invokeStatic;
biz code:
public String buildWord(){
List users = new ArrayList();
List names = users.stream()
//.filter(e -> e.isCool() &&e.getName().equals(""))
.filter(User::isCool)
.map(User::getName)
.collect(Collectors.toList());
return names.toString();
}
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(Collections.singletonList(ClasspathHelper.forClass(UsageTest.class)))
.setScanners(new MemberUsageScanner()));
Method[] methods = User.class.getDeclaredMethods();
for (Method method : methods) {
Collection members = reflections.getMemberUsage(method);
System.out.println("method:"+method+",members:"+members);
}
members return null.
The text was updated successfully, but these errors were encountered: