本文整理汇总了Java中javassist.bytecode.LocalVariableAttribute.tableLength方法的典型用法代码示例。如果您正苦于以下问题:Java LocalVariableAttribute.tableLength方法的具体用法?Java LocalVariableAttribute.tableLength怎么用?Java LocalVariableAttribute.tableLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.LocalVariableAttribute
的用法示例。
在下文中一共展示了LocalVariableAttribute.tableLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recordLocalVariables
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
/**
* Records local variables available at the specified program counter.
* If the LocalVariableAttribute is not available, this method does not
* record any local variable. It only returns false.
*
* @param pc program counter (>= 0)
* @return false if the CodeAttribute does not include a
* LocalVariableAttribute.
*/
public boolean recordLocalVariables(CodeAttribute ca, int pc)
throws CompileError
{
LocalVariableAttribute va
= (LocalVariableAttribute)
ca.getAttribute(LocalVariableAttribute.tag);
if (va == null)
return false;
int n = va.tableLength();
for (int i = 0; i < n; ++i) {
int start = va.startPc(i);
int len = va.codeLength(i);
if (start <= pc && pc < start + len)
gen.recordVariable(va.descriptor(i), va.variableName(i),
va.index(i), stable);
}
return true;
}
示例2: recordParamNames
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
/**
* Records parameter names if the LocalVariableAttribute is available.
* It returns false unless the LocalVariableAttribute is available.
*
* @param numOfLocalVars the number of local variables used
* for storing the parameters.
* @return false if the CodeAttribute does not include a
* LocalVariableAttribute.
*/
public boolean recordParamNames(CodeAttribute ca, int numOfLocalVars)
throws CompileError
{
LocalVariableAttribute va
= (LocalVariableAttribute)
ca.getAttribute(LocalVariableAttribute.tag);
if (va == null)
return false;
int n = va.tableLength();
for (int i = 0; i < n; ++i) {
int index = va.index(i);
if (index < numOfLocalVars)
gen.recordVariable(va.descriptor(i), va.variableName(i),
index, stable);
}
return true;
}
示例3: extractNameParameter
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
private Map<Integer, String> extractNameParameter(CtMethod m) throws NotFoundException {
Map<Integer, String> hashNameParam = new HashMap<Integer, String>();
CodeAttribute codeAttribute = (CodeAttribute) m.getMethodInfo().getAttribute("Code");
if (codeAttribute != null) {
LocalVariableAttribute localVariableAttribute = (LocalVariableAttribute) codeAttribute.getAttribute("LocalVariableTable");
if (localVariableAttribute != null && localVariableAttribute.tableLength() >= m.getParameterTypes().length) {
for (int i = 0; i < m.getParameterTypes().length + 2; i++) {
String name = localVariableAttribute.getConstPool().getUtf8Info(localVariableAttribute.nameIndex(i));
if (!name.equals("this")) {
hashNameParam.put(i, name);
}
}
}
}
return hashNameParam;
}
示例4: dump
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
private static void dump(LocalVariableAttribute lva) {
if (logger.isDebugEnabled()) {
StringBuilder buffer = new StringBuilder(1024);
for (int i = 0; i < lva.tableLength(); i++) {
buffer.append("\n");
buffer.append(i);
buffer.append(" start_pc:");
buffer.append(lva.startPc(i));
buffer.append(" index:");
buffer.append(lva.index(i));
buffer.append(" name:");
buffer.append(lva.variableName(i));
buffer.append(" nameIndex:");
buffer.append(lva.nameIndex(i));
}
logger.debug(buffer.toString());
}
}
示例5: getLocalVariableTable
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
@Override
public LocalVariableTable getLocalVariableTable(Signature methodSignature)
throws MethodNotFoundException, MethodCodeNotFoundException {
final CodeAttribute ca = getMethodCodeAttribute(methodSignature);
final LocalVariableAttribute lvtJA = (LocalVariableAttribute) ca.getAttribute("LocalVariableTable");
if (lvtJA == null) {
return this.defaultLocalVariableTable(methodSignature);
}
//builds the local variable table from the LocalVariableTable attribute
//information; this has always success
final LocalVariableTable lvt = new LocalVariableTable(ca.getMaxLocals());
for (int i = 0; i < lvtJA.tableLength(); ++i) {
lvt.setEntry(lvtJA.index(i), lvtJA.descriptor(i),
lvtJA.variableName(i), lvtJA.startPc(i), lvtJA.codeLength(i));
}
return lvt;
}
示例6: scan
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
@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<String> names = new ArrayList<String>(length - i);
while (i < length) names.add(((MethodInfo) method).getConstPool().getUtf8Info(table.nameIndex(i++)));
getStore().put(key, Joiner.on(", ").join(names));
}
}
}
}
示例7: parameterNameToIndex
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
/**
*
* @param reifiedMethod a method that has some parameters
* @param parameterName the name of the parameters
* @return the index of the parameters in the list of parameters (first parameter has index 1)
*/
private static int parameterNameToIndex(CtMethod reifiedMethod, String parameterName) {
CodeAttribute codeAttribute = (CodeAttribute) reifiedMethod.getMethodInfo().getAttribute(
CodeAttribute.tag);
LocalVariableAttribute localVariableAttribute = (LocalVariableAttribute) codeAttribute
.getAttribute(LocalVariableAttribute.tag);
for (int j = 0; j < localVariableAttribute.tableLength(); j++) {
String name = localVariableAttribute.getConstPool().getUtf8Info(
localVariableAttribute.nameIndex(j));
if (!name.equals("this")) {
if (name.equals(parameterName)) {
return j;
}
}
}
throw new RuntimeException("parameter " + parameterName + "not found in method " +
reifiedMethod.getLongName());
}
示例8: dumpTable
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void dumpTable(LocalVariableAttribute table) {
for (int i=0; i<table.tableLength(); i++) {
System.out.println(String.format("\t%d (%d): %s %s",
i, table.index(i), table.variableName(i), table.descriptor(i)
));
}
}
示例9: renameLVT
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table) {
// skip empty tables
if (table.tableLength() <= 0) {
return;
}
// where do we start counting variables?
int starti = 0;
if (table.variableName(0).equals("this")) {
// skip the "this" variable
starti = 1;
}
// rename method arguments first
int numArgs = 0;
if (behaviorEntry.getSignature() != null) {
numArgs = behaviorEntry.getSignature().getArgumentTypes().size();
for (int i=starti; i<starti + numArgs && i<table.tableLength(); i++) {
int argi = i - starti;
String argName = m_translator.translate(new ArgumentEntry(behaviorEntry, argi, ""));
if (argName == null) {
argName = "a" + (argi + 1);
}
renameVariable(table, i, constants.addUtf8Info(argName));
}
}
// then rename the rest of the args, if any
for (int i=starti + numArgs; i<table.tableLength(); i++) {
int firstIndex = table.index(starti + numArgs);
renameVariable(table, i, constants.addUtf8Info("v" + (table.index(i) - firstIndex + 1)));
}
}
示例10: getNameIndex
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
private int getNameIndex(LocalVariableAttribute table, int index) {
for (int i=0; i<table.tableLength(); i++) {
if (table.index(i) == index) {
return table.nameIndex(i);
}
}
return 0;
}
示例11: getParameterNames
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
/**
* 获取方法的参数名称.
*
* @param ctMethod
* @return
* @throws NotFoundException
*/
public static String[] getParameterNames(CtMethod ctMethod) throws NotFoundException {
MethodInfo methodInfo = ctMethod.getMethodInfo();
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
// logger.info("methodInfo.getConstPool().getSize():");
LocalVariableAttribute attribute = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
// String[] names = new String[attribute.tableLength() - 1];
String[] paramNames = new String[ctMethod.getParameterTypes().length];
int pos = 0;
if (true) {
int size = attribute.tableLength();
if (size > 0) {
String[] names = new String[size - 1];
for (int i = 0; i < names.length; i++) {
names[i] = attribute.variableName(i);
if ("this".equals(names[i])) {
pos = i + 1;
break;
}
}
// logger.info(methodInfo.getName() + " pos:" + pos + " allNames:" + StringUtils.join(names, ", "));
}
}
// logger.info(methodInfo.getName() + " pos:" + pos);
for (int i = 0; i < paramNames.length; i++) {
// paramNames[i] = attribute.variableName(i + 1);
try {
paramNames[i] = attribute.variableName(i + pos);
// logger.info("paramNames[" + i + "]:" + paramNames[i]);
}
catch (RuntimeException e) {
throw e;
}
}
// System.err.println("paramNames:" + StringUtils.join(paramNames));
return paramNames;
}
示例12: renameLVT
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants,
LocalVariableAttribute table)
{
// skip empty tables
if(table.tableLength() <= 0)
return;
// where do we start counting variables?
int starti = 0;
if(table.variableName(0).equals("this"))
// skip the "this" variable
starti = 1;
// rename method arguments first
int numArgs = 0;
if(behaviorEntry.getSignature() != null)
{
numArgs = behaviorEntry.getSignature().getArgumentTypes().size();
for(int i = starti; i < starti + numArgs && i < table.tableLength(); i++)
{
int argi = i - starti;
String argName =
m_translator.translate(new ArgumentEntry(behaviorEntry,
argi, ""));
if(argName == null)
argName = "a" + (argi + 1);
renameVariable(table, i, constants.addUtf8Info(argName));
}
}
// then rename the rest of the args, if any
for(int i = starti + numArgs; i < table.tableLength(); i++)
{
int firstIndex = table.index(starti + numArgs);
renameVariable(table, i,
constants.addUtf8Info("v" + (table.index(i) - firstIndex + 1)));
}
}
示例13: getNameIndex
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
private int getNameIndex(LocalVariableAttribute table, int index)
{
for(int i = 0; i < table.tableLength(); i++)
if(table.index(i) == index)
return table.nameIndex(i);
return 0;
}
示例14: lookupParameterNames
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
public static List<String> lookupParameterNames(Constructor constructor) {
try {
List<String> parameters = new ArrayList<String>();
ClassPool classPool = newClassPool();
CtClass ctClass = classPool.get(constructor.getDeclaringClass().getName());
CtClass[] cc = new CtClass[constructor.getParameterTypes().length];
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
cc[i] = classPool.get(constructor.getParameterTypes()[i].getName());
}
CtConstructor ctConstructor = ctClass.getDeclaredConstructor(cc);
// Signatures names
CodeAttribute codeAttribute = (CodeAttribute) ctConstructor.getMethodInfo().getAttribute("Code");
if (codeAttribute != null) {
LocalVariableAttribute localVariableAttribute = (LocalVariableAttribute) codeAttribute.getAttribute("LocalVariableTable");
if (localVariableAttribute != null && localVariableAttribute.tableLength() >= ctConstructor.getParameterTypes().length) {
for (int i = 0; i < ctConstructor.getParameterTypes().length + 1; i++) {
String name = localVariableAttribute.getConstPool().getUtf8Info(localVariableAttribute.nameIndex(i));
if (!name.equals("this")) {
parameters.add(name);
}
}
}
}
return parameters;
} catch (Exception e) {
throw new UnexpectedException("Cannot extract parameter names", e);
}
}
示例15: getParameterVariableName
import javassist.bytecode.LocalVariableAttribute; //导入方法依赖的package包/类
public static String[] getParameterVariableName(CtBehavior method, LocalVariableAttribute localVariableAttribute) {
// Inspired by
// http://www.jarvana.com/jarvana/view/org/jboss/weld/servlet/weld-servlet/1.0.1-Final/weld-servlet-1.0.1-Final-sources.jar!/org/slf4j/instrumentation/JavassistHelper.java?format=ok
// http://grepcode.com/file/repo1.maven.org/maven2/jp.objectfanatics/assertion-weaver/0.0.30/jp/objectfanatics/commons/javassist/JavassistUtils.java
if (localVariableAttribute == null) {
// null means that the class is not compiled with debug option.
return null;
}
dump(localVariableAttribute);
String[] parameterTypes = JavaAssistUtils.parseParameterSignature(method.getSignature());
if (parameterTypes.length == 0) {
return EMPTY_STRING_ARRAY;
}
String[] parameterVariableNames = new String[parameterTypes.length];
boolean thisExist = thisExist(method);
int paramIndex = 0;
for (int i = 0; i < localVariableAttribute.tableLength(); i++) {
// if start pc is not 0, it's not a parameter.
if (localVariableAttribute.startPc(i) != 0) {
continue;
}
int index = localVariableAttribute.index(i);
if (index == 0 && thisExist) {
// variable this. skip.
continue;
}
String variablename = localVariableAttribute.variableName(i);
parameterVariableNames[paramIndex++] = variablename;
if (paramIndex == parameterTypes.length) {
break;
}
}
return parameterVariableNames;
}