Skip to content

Commit 61291af

Browse files
committed
Use the right index for writing type annotations
1 parent aaee2ab commit 61291af

File tree

3 files changed

+126
-25
lines changed

3 files changed

+126
-25
lines changed

src/org/jetbrains/java/decompiler/main/ClassWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ else if (methodWrapper.varproc.getVarFinal(new VarVersionPair(index, 0)) == VarT
14091409
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
14101410
typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
14111411
}
1412-
var annos = getTypeAnnotations(mt, TypeAnnotation.METHOD_PARAMETER, i);
1412+
var annos = getTypeAnnotations(mt, TypeAnnotation.METHOD_PARAMETER, paramCount);
14131413
if (!annos.isEmpty()) {
14141414
VarType tempParam = parameterType;
14151415
// Undo varargs change

testData/results/pkg/TestTypeAnnotations.dec

Lines changed: 107 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,46 @@ public class TestTypeAnnotations {
3333
public TestTypeAnnotations.G2<String, @TestTypeAnnotations.Anno Integer> x;
3434

3535
public @TestTypeAnnotations.Anno TestTypeAnnotations.Inner a() {
36-
return null;// 93
36+
return null;// 97
3737
}
3838

3939
public [email protected] Inner b() {
40-
return null;// 97
40+
return null;// 101
4141
}
4242

4343
public [email protected] InnerStatic c() {
44-
return null;// 101
44+
return null;// 105
4545
}
4646

4747
public @TestTypeAnnotations.Anno TestTypeAnnotations[] d() {
48-
return null;// 105
48+
return null;// 109
4949
}
5050

5151
public TestTypeAnnotations @TestTypeAnnotations.Anno [] e() {
52-
return null;// 109
52+
return null;// 113
5353
}
5454

5555
public byte @TestTypeAnnotations.Anno [] ary(byte @TestTypeAnnotations.Anno [] ary) {
56-
return ary;// 113
56+
return ary;// 117
5757
}
5858

5959
public void varargs(@TestTypeAnnotations.Anno Object... args) {
60-
}// 118
60+
}// 122
6161

6262
public void varargs(int v, @TestTypeAnnotations.Anno Object... args) {
63-
}// 122
63+
}// 126
6464

6565
public void varargs2(Object @TestTypeAnnotations.Anno ... args) {
66-
}// 126
66+
}// 130
6767

6868
public void varargs2(int v, Object @TestTypeAnnotations.Anno ... args) {
69-
}// 130
69+
}// 134
7070

7171
public void varargs3a(Object[] @TestTypeAnnotations.Anno ... args) {
72-
}// 134
72+
}// 138
7373

7474
public void varargs3b(Object @TestTypeAnnotations.Anno []... args) {
75-
}// 138
75+
}// 142
7676

7777
@Target(ElementType.TYPE_USE)
7878
public @interface Anno {
@@ -91,6 +91,9 @@ public class TestTypeAnnotations {
9191
public [email protected] Inner.InnerInner ad;
9292
public [email protected] InnerInner ae;
9393

94+
public Inner(@TestTypeAnnotations.Anno String s, Object o, @TestTypeAnnotations.Anno String s2) {
95+
}// 22
96+
9497
public class InnerInner {
9598
}
9699

@@ -120,6 +123,20 @@ public class TestTypeAnnotations {
120123
public static class Inner2Static {
121124
}
122125
}
126+
127+
public enum TestEnum {
128+
A("a"),// 145
129+
B("b"),// 146
130+
C("c");// 147
131+
132+
TestEnum(@TestTypeAnnotations.Anno String name) {
133+
this(name, name.charAt(0), 0, null);// 150
134+
}// 151
135+
136+
TestEnum(@TestTypeAnnotations.Anno String name, char c, int i, @TestTypeAnnotations.Anno Object o) {
137+
System.out.println(name + " " + c + i + " " + o);// 154
138+
}// 155
139+
}
123140
}
124141

125142
class 'pkg/TestTypeAnnotations' {
@@ -178,16 +195,82 @@ class 'pkg/TestTypeAnnotations' {
178195
}
179196
}
180197

198+
class 'pkg/TestTypeAnnotations$Inner' {
199+
method '<init> (Lpkg/TestTypeAnnotations;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V' {
200+
4 94
201+
}
202+
}
203+
204+
class 'pkg/TestTypeAnnotations$TestEnum' {
205+
method '<clinit> ()V' {
206+
7 127
207+
8 127
208+
16 128
209+
17 128
210+
25 129
211+
26 129
212+
}
213+
214+
method '<init> (Ljava/lang/String;ILjava/lang/String;)V' {
215+
3 132
216+
4 132
217+
5 132
218+
6 132
219+
7 132
220+
8 132
221+
9 132
222+
a 132
223+
b 132
224+
c 132
225+
d 132
226+
e 133
227+
}
228+
229+
method '<init> (Ljava/lang/String;ILjava/lang/String;CILjava/lang/Object;)V' {
230+
6 136
231+
7 136
232+
8 136
233+
9 136
234+
a 136
235+
b 136
236+
c 136
237+
d 136
238+
e 136
239+
f 136
240+
13 136
241+
14 136
242+
15 136
243+
16 136
244+
17 136
245+
18 136
246+
19 136
247+
1a 136
248+
1b 137
249+
}
250+
}
251+
181252
Lines mapping:
182-
93 <-> 36
183-
97 <-> 40
184-
101 <-> 44
185-
105 <-> 48
186-
109 <-> 52
187-
113 <-> 56
188-
118 <-> 60
189-
122 <-> 63
190-
126 <-> 66
191-
130 <-> 69
192-
134 <-> 72
193-
138 <-> 75
253+
22 <-> 95
254+
97 <-> 36
255+
101 <-> 40
256+
105 <-> 44
257+
109 <-> 48
258+
113 <-> 52
259+
117 <-> 56
260+
122 <-> 60
261+
126 <-> 63
262+
130 <-> 66
263+
134 <-> 69
264+
138 <-> 72
265+
142 <-> 75
266+
145 <-> 128
267+
146 <-> 129
268+
147 <-> 130
269+
150 <-> 133
270+
151 <-> 134
271+
154 <-> 137
272+
155 <-> 138
273+
Not mapped:
274+
20
275+
144
276+
153

testData/src/java21/pkg/TestTypeAnnotations.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class Inner {
1717
public TestTypeAnnotations.@Anno Inner.InnerInner ad;
1818
public TestTypeAnnotations.Inner. @Anno InnerInner ae;
1919

20+
public Inner(@Anno String s, Object o, @Anno String s2) {
21+
22+
}
23+
2024
public record InnerRec() {
2125
public static TestTypeAnnotations.Inner.@Anno InnerRec.A ba;
2226
public static TestTypeAnnotations.Inner.InnerRec.@Anno A bb;
@@ -136,4 +140,18 @@ public void varargs3a(Object[] @Anno ... args) {
136140
public void varargs3b(Object @Anno []... args) {
137141

138142
}
143+
144+
public enum TestEnum {
145+
A("a"),
146+
B("b"),
147+
C("c");
148+
149+
TestEnum(@Anno String name) {
150+
this(name, name.charAt(0), 0, null);
151+
}
152+
153+
TestEnum(@Anno String name, char c, int i, @Anno Object o) {
154+
System.out.println(name + " " + c + i + " " + o);
155+
}
156+
}
139157
}

0 commit comments

Comments
 (0)