diff options
author | chibash <chiba@javassist.org> | 2014-06-09 19:34:43 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2014-06-09 19:34:43 +0900 |
commit | a0bcbe95df30f33259c5bd12b842ef6ea02bb8fb (patch) | |
tree | f48374158d9a04940139b78a7c4fba396090c2da | |
parent | 37b27e12d46d7aedcd7c5c671fc8b895e626b100 (diff) | |
download | javassist-a0bcbe95df30f33259c5bd12b842ef6ea02bb8fb.tar.gz javassist-a0bcbe95df30f33259c5bd12b842ef6ea02bb8fb.zip |
JIRA JASSIST-224
-rw-r--r-- | src/main/javassist/bytecode/MethodParametersAttribute.java | 87 | ||||
-rw-r--r-- | src/test/test4/MethodParamTest.java | 5 |
2 files changed, 92 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/MethodParametersAttribute.java b/src/main/javassist/bytecode/MethodParametersAttribute.java new file mode 100644 index 00000000..b67a0f54 --- /dev/null +++ b/src/main/javassist/bytecode/MethodParametersAttribute.java @@ -0,0 +1,87 @@ +package javassist.bytecode; + +import java.io.DataInputStream; +import java.io.IOException; +import java.util.Map; + +/** + * <code>MethodParameters_attribute</code>. + */ +public class MethodParametersAttribute extends AttributeInfo { + /** + * The name of this attribute <code>"MethodParameters"</code>. + */ + public static final String tag = "MethodParameters"; + + MethodParametersAttribute(ConstPool cp, int n, DataInputStream in) + throws IOException + { + super(cp, n, in); + } + + /** + * Constructs an attribute. + * + * @param cp a constant pool table. + * @param names an array of parameter names. + * The i-th element is the name of the i-th parameter. + * @param flags an array of parameter access flags. + */ + public MethodParametersAttribute(ConstPool cp, String[] names, int[] flags) { + super(cp, tag); + byte[] data = new byte[names.length * 4 + 1]; + data[0] = (byte)names.length; + for (int i = 0; i < names.length; i++) { + ByteArray.write16bit(cp.addUtf8Info(names[i]), data, i * 4 + 1); + ByteArray.write16bit(flags[i], data, i * 4 + 3); + } + + set(data); + } + + /** + * Returns <code>parameters_count</code>, which is the number of + * parameters. + */ + public int size() { + return info[0] & 0xff; + } + + /** + * Returns the value of <code>name_index</code> of the i-th element of <code>parameters</code>. + * + * @param i the position of the parameter. + */ + public int name(int i) { + return ByteArray.readU16bit(info, i * 4 + 1); + } + + /** + * Returns the value of <code>access_flags</code> of the i-th element of <code>parameters</code>. + * + * @param i the position of the parameter. + * @see AccessFlag + */ + public int accessFlags(int i) { + return ByteArray.readU16bit(info, i * 4 + 3); + } + + /** + * Makes a copy. + * + * @param newCp the constant pool table used by the new copy. + * @param classnames ignored. + */ + public AttributeInfo copy(ConstPool newCp, Map classnames) { + int s = size(); + ConstPool cp = getConstPool(); + String[] names = new String[s]; + int[] flags = new int[s]; + for (int i = 0; i < s; i++) { + names[i] = cp.getUtf8Info(name(i)); + flags[i] = accessFlags(i); + } + + return new MethodParametersAttribute(newCp, names, flags); + } +} diff --git a/src/test/test4/MethodParamTest.java b/src/test/test4/MethodParamTest.java new file mode 100644 index 00000000..9f64e15e --- /dev/null +++ b/src/test/test4/MethodParamTest.java @@ -0,0 +1,5 @@ +package test4; + +public class MethodParamTest { + public void test(int i, String s) {} +} |