]> source.dussan.org Git - javassist.git/commitdiff
add unit tests for LocalVariableAttribute.variableNameByIndex and MethodParametersAtt... 357/head
authoreshizhan <eshizhan@126.com>
Fri, 29 Jan 2021 04:34:08 +0000 (12:34 +0800)
committereshizhan <eshizhan@126.com>
Fri, 29 Jan 2021 04:34:08 +0000 (12:34 +0800)
src/main/javassist/bytecode/LocalVariableAttribute.java
src/test/javassist/JvstTest4.java
src/test/javassist/bytecode/BytecodeTest.java

index c1106be1735b3a6c8f242aa860da929c6249c94e..dcee79654c228e34506c4f5b333fd13df88479a6 100644 (file)
@@ -227,7 +227,7 @@ public class LocalVariableAttribute extends AttributeInfo {
     public String variableNameByIndex(int index) {
         for (int i = 0; i < tableLength(); i++) {
             if (index(i) == index) {
-                return getConstPool().getUtf8Info(nameIndex(i));
+                return variableName(i);
             }
         }
         throw new ArrayIndexOutOfBoundsException();
index d53148bd0d3f93925ce12919140eaf56077d4f62..259451b9935aea5e9fb38e70c34d5255a3127d65 100644 (file)
@@ -1019,11 +1019,15 @@ public class JvstTest4 extends JvstTestRoot {
         assertEquals(2, attr.size());
         assertEquals("i", cp.getUtf8Info(attr.name(0)));
         assertEquals("s", cp.getUtf8Info(attr.name(1)));
+        assertEquals("i", attr.parameterName(0));
+        assertEquals("s", attr.parameterName(1));
 
         attr = (MethodParametersAttribute)attr.copy(cp, null);
         assertEquals(2, attr.size());
         assertEquals("i", cp.getUtf8Info(attr.name(0)));
         assertEquals("s", cp.getUtf8Info(attr.name(1)));
+        assertEquals("i", attr.parameterName(0));
+        assertEquals("s", attr.parameterName(1));
     }
 
     // JIRA JASSIST-220
index 5ddf5d5bdea6ddaa986c03dbe0f9796ff2208424..7aef1cce67816d25581192d31232c5f6c2ed2674 100644 (file)
@@ -354,6 +354,9 @@ public class BytecodeTest extends TestCase {
                 assertEquals("I", ainfo2.descriptor(i));
         }
         print("**** end ***");
+
+        assertEquals("this", ainfo2.variableNameByIndex(0));
+        assertEquals("i", ainfo2.variableNameByIndex(1));
     }
 
     public void testAnnotations() throws Exception {