Skip to content

Commit

Permalink
Add new record pattern test, fix FMT processor ref
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Dec 9, 2023
1 parent ea3c2ad commit 950c78c
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ private void initConstant() {
if (type == CONSTANT_Methodref ||
type == CONSTANT_InterfaceMethodref ||
type == CONSTANT_InvokeDynamic ||
(type == CONSTANT_MethodHandle && index1 != CONSTANT_MethodHandle_REF_getField && index1 != CONSTANT_MethodHandle_REF_putField)) {
(type == CONSTANT_MethodHandle && index1 != CONSTANT_MethodHandle_REF_getField && index1 != CONSTANT_MethodHandle_REF_putField
&& index1 != CONSTANT_MethodHandle_REF_getStatic && index1 != CONSTANT_MethodHandle_REF_putStatic)) {
int parenth = descriptor.indexOf(')');
if (descriptor.length() < 2 || parenth < 0 || descriptor.charAt(0) != '(') {
throw new IllegalArgumentException("Invalid descriptor: " + descriptor +
"; type = " + type + "; classname = " + classname + "; elementname = " + elementname);
"; type = " + type + "; classname = " + classname + "; elementname = " + elementname + "; kind = " + index1);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ private void registerDefault() {
register(JAVA_8, "TestTrySplit");
register(JAVA_8, "TestWhileForeach");
register(JAVA_21, "TestRecordPatterns1");
register(JAVA_21, "TestRecordPatterns2");
register(JAVA_21_PREVIEW, "TestStrProcessor");
register(JAVA_21_PREVIEW, "TestRawProcessor");
register(JAVA_21_PREVIEW, "TestFmtProcessor");
Expand Down
53 changes: 53 additions & 0 deletions testData/results/pkg/TestFmtProcessor.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package pkg;

import java.lang.runtime.TemplateRuntime;
import java.util.FormatProcessor;

public class TestFmtProcessor {
public void test() {
String s = "Hello";// 7
int i = 42;// 8
double d = 3.14159;// 9
System.out.println(TemplateRuntime.processStringTemplate<"process",FormatProcessor::FMT,"Text: %s"," %4d"," %.2f","">(FormatProcessor.FMT, s, i, d));// 11
}// 12
}

class 'pkg/TestFmtProcessor' {
method 'test ()V' {
0 7
1 7
2 7
3 8
4 8
5 8
6 9
7 9
8 9
9 9
a 10
b 10
c 10
d 10
e 10
f 10
10 10
11 10
12 10
13 10
14 10
15 10
16 10
17 10
18 10
19 10
1a 10
1b 11
}
}

Lines mapping:
7 <-> 8
8 <-> 9
9 <-> 10
11 <-> 11
12 <-> 12
86 changes: 85 additions & 1 deletion testData/results/pkg/TestRecordPatterns1.dec
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,44 @@ public class TestRecordPatterns1 {
}
}// 25

// $VF: Inserted dummy exception handlers to handle obfuscated exceptions
public void test4(TestRecordPatterns1.R r) {
if (r instanceof TestRecordPatterns1.R) {
TestRecordPatterns1.R var10000 = r;

int var5;
label29: {
label34: {
try {
var10 = var10000.i();
} catch (Throwable var7) {
var9 = var7;
boolean var10001 = false;
break label34;
}

var5 = var10;
var10000 = r;

try {
var12 = var10000.o();
break label29;
} catch (Throwable var6) {
var9 = var6;
boolean var13 = false;
}
}

Throwable var2 = var9;// 28
throw new MatchException(var2.toString(), var2);
}

Object var8 = var12;
System.out.println(var5);// 29
System.out.println(var8);// 30
}
}// 32

static record R(int i, Object o) {
}
}
Expand Down Expand Up @@ -259,6 +297,48 @@ class 'pkg/TestRecordPatterns1' {
50 109
51 117
}

method 'test4 (Lpkg/TestRecordPatterns1$R;)V' {
0 121
1 121
2 121
3 121
4 121
7 122
9 122
a 128
d 135
e 135
f 152
10 152
12 136
13 139
16 151
17 151
18 153
19 153
1c 152
1d 152
1e 152
1f 152
20 152
21 152
22 152
23 153
24 153
25 153
26 153
27 153
28 153
2e 147
33 148
34 148
35 148
36 148
37 148
3b 148
3c 155
}
}

Lines mapping:
Expand All @@ -273,4 +353,8 @@ Lines mapping:
21 <-> 109
22 <-> 114
23 <-> 115
25 <-> 118
25 <-> 118
28 <-> 148
29 <-> 153
30 <-> 154
32 <-> 156
56 changes: 56 additions & 0 deletions testData/results/pkg/TestRecordPatterns2.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package pkg;

public class TestRecordPatterns2 {
public void test1(TestRecordPatterns2.R r) {
if (r instanceof TestRecordPatterns2.R) {
TestRecordPatterns2.R var10000 = r;

try {
var6 = var10000.x();
} catch (Throwable var5) {// 9
throw new MatchException(var5.toString(), var5);
}

int var4 = var6;
System.out.println(var4);// 10
}
}// 12

static record R(int x) {
}
}

class 'pkg/TestRecordPatterns2' {
method 'test1 (Lpkg/TestRecordPatterns2$R;)V' {
0 4
1 4
2 4
3 4
4 4
7 5
9 5
a 8
d 13
e 13
f 14
10 14
12 14
13 14
14 14
15 14
16 14
1c 9
21 10
22 10
23 10
24 10
25 10
29 10
2a 16
}
}

Lines mapping:
9 <-> 10
10 <-> 15
12 <-> 17
7 changes: 7 additions & 0 deletions testData/src/java21/pkg/TestRecordPatterns1.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ public void test3(R r) {
System.out.println(s);
}
}

public void test4(R r) {
if (r instanceof R(int x, var v)) {
System.out.println(x);
System.out.println(v);
}
}
}
13 changes: 13 additions & 0 deletions testData/src/java21/pkg/TestRecordPatterns2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pkg;

public class TestRecordPatterns2 {
record R(int x) {

}

public void test1(R r) {
if (r instanceof R(int z)) {
System.out.println(z);
}
}
}

0 comments on commit 950c78c

Please sign in to comment.