Skip to content

Commit

Permalink
sm command print method with Descriptor. close #504
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Feb 13, 2019
1 parent f181877 commit b0877cc
Showing 1 changed file with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package com.taobao.arthas.core.command.klass100;

import static com.taobao.text.Decoration.bold;
import static com.taobao.text.ui.Element.label;
import static java.lang.String.format;

import java.lang.instrument.Instrumentation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Set;

import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.cli.CliToken;
import com.taobao.arthas.core.shell.cli.Completion;
import com.taobao.arthas.core.shell.cli.CompletionUtils;
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
import com.taobao.arthas.core.shell.command.CommandProcess;
import com.taobao.arthas.core.util.matcher.Matcher;
import com.taobao.arthas.core.util.matcher.RegexMatcher;
import com.taobao.arthas.core.util.matcher.WildcardMatcher;
import com.taobao.arthas.core.util.SearchUtils;
import com.taobao.arthas.core.util.StringUtils;
import com.taobao.arthas.core.util.TypeRenderUtils;
import com.taobao.arthas.core.util.affect.RowAffect;
import com.taobao.arthas.core.util.matcher.Matcher;
import com.taobao.arthas.core.util.matcher.RegexMatcher;
import com.taobao.arthas.core.util.matcher.WildcardMatcher;
import com.taobao.middleware.cli.annotations.Argument;
import com.taobao.middleware.cli.annotations.Description;
import com.taobao.middleware.cli.annotations.Name;
Expand All @@ -22,21 +30,11 @@
import com.taobao.text.ui.TableElement;
import com.taobao.text.util.RenderUtil;

import java.lang.instrument.Instrumentation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static com.taobao.text.Decoration.bold;
import static com.taobao.text.ui.Element.label;
import static java.lang.String.format;

/**
* 展示方法信息
*
* @author vlinux
* @author hengyunabc 2019-02-13
*/
@Name("sm")
@Summary("Search the method of classes loaded by JVM")
Expand Down Expand Up @@ -87,38 +85,31 @@ public void process(CommandProcess process) {
Set<Class<?>> matchedClasses = SearchUtils.searchClass(inst, classPattern, isRegEx);

for (Class<?> clazz : matchedClasses) {
Set<String> methodNames = new HashSet<String>();
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(constructor).toString();
if (!methodNameMatcher.matching("<init>")) {
continue;
}

if (isDetail) {
process.write(RenderUtil.render(renderConstructor(constructor), process.width()) + "\n");
} else {
if (methodNames.contains("<init>")) {
continue;
}
methodNames.add("<init>");
String line = format("%s->%s%n", clazz.getName(), "<init>");
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
process.write(line);
}
affect.rCnt(1);
}

for (Method method : clazz.getDeclaredMethods()) {
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(method).toString();
if (!methodNameMatcher.matching(method.getName())) {
continue;
}

if (isDetail) {
process.write(RenderUtil.render(renderMethod(method), process.width()) + "\n");
} else {
if (methodNames.contains(method.getName())) {
continue;
}
methodNames.add(method.getName());
String line = format("%s->%s%n", clazz.getName(), method.getName());
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
process.write(line);
}
affect.rCnt(1);
Expand Down

0 comments on commit b0877cc

Please sign in to comment.