org.reflections.scanners.MethodParameterNamesScanner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-all Show documentation
Show all versions of swagger-all Show documentation
swagger-all is a rebundled verison of Swagger as one OSGi bundle.
package org.reflections.scanners;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import javassist.bytecode.LocalVariableAttribute;
import javassist.bytecode.MethodInfo;
import org.reflections.adapters.MetadataAdapter;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
/** scans methods/constructors and indexes parameter names */
@SuppressWarnings("unchecked")
public class MethodParameterNamesScanner extends AbstractScanner {
@Override
public void scan(Object cls) {
final MetadataAdapter md = getMetadataAdapter();
for (Object method : md.getMethods(cls)) {
String key = md.getMethodFullKey(cls, method);
if (acceptResult(key)) {
LocalVariableAttribute table = (LocalVariableAttribute) ((MethodInfo) method).getCodeAttribute().getAttribute(LocalVariableAttribute.tag);
int length = table.tableLength();
int i = Modifier.isStatic(((MethodInfo) method).getAccessFlags()) ? 0 : 1; //skip this
if (i < length) {
List names = new ArrayList(length - i);
while (i < length) names.add(((MethodInfo) method).getConstPool().getUtf8Info(table.nameIndex(i++)));
getStore().put(key, Joiner.on(", ").join(names));
}
}
}
}
}