diff options
author | eshizhan <eshizhan@126.com> | 2021-01-26 17:39:20 +0800 |
---|---|---|
committer | eshizhan <eshizhan@126.com> | 2021-01-26 17:39:20 +0800 |
commit | 084c8e89b5d40bb739b7a6dee61a89452d679c1c (patch) | |
tree | d6d25ddc1f082d3575c1e8c6b3873a18a7287d99 /src | |
parent | 1c4e31b9677d020a1e89aeebc6686396f9e6c68a (diff) | |
download | javassist-084c8e89b5d40bb739b7a6dee61a89452d679c1c.tar.gz javassist-084c8e89b5d40bb739b7a6dee61a89452d679c1c.zip |
add functions for getting the parameter names of method
Diffstat (limited to 'src')
-rw-r--r-- | src/main/javassist/bytecode/LocalVariableAttribute.java | 16 | ||||
-rw-r--r-- | src/main/javassist/bytecode/MethodParametersAttribute.java | 8 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/LocalVariableAttribute.java b/src/main/javassist/bytecode/LocalVariableAttribute.java index a0a62cc3..c1106be1 100644 --- a/src/main/javassist/bytecode/LocalVariableAttribute.java +++ b/src/main/javassist/bytecode/LocalVariableAttribute.java @@ -218,6 +218,22 @@ public class LocalVariableAttribute extends AttributeInfo { } /** + * Returns the name of the local variable with given index. + * If you want get the parameter name of method with correct order, + * should using this method. + * + * @param index the index of the local variable. + */ + public String variableNameByIndex(int index) { + for (int i = 0; i < tableLength(); i++) { + if (index(i) == index) { + return getConstPool().getUtf8Info(nameIndex(i)); + } + } + throw new ArrayIndexOutOfBoundsException(); + } + + /** * Returns the value of * <code>local_variable_table[i].descriptor_index</code>. * This represents the type descriptor of the local variable. diff --git a/src/main/javassist/bytecode/MethodParametersAttribute.java b/src/main/javassist/bytecode/MethodParametersAttribute.java index 12521095..b9c252a9 100644 --- a/src/main/javassist/bytecode/MethodParametersAttribute.java +++ b/src/main/javassist/bytecode/MethodParametersAttribute.java @@ -57,6 +57,14 @@ public class MethodParametersAttribute extends AttributeInfo { } /** + * Returns the name of the i-th element of <code>parameters</code>. + * @param i the position of the parameter. + */ + public String parameterName(int i) { + return getConstPool().getUtf8Info(name(i)); + } + + /** * Returns the value of <code>access_flags</code> of the i-th element of <code>parameters</code>. * * @param i the position of the parameter. |