Skip to content

Commit

Permalink
Java 21 string template tests (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 authored Dec 9, 2023
1 parent bc23f82 commit ea3c2ad
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def testJavaRuntimes = [:]
languageVersion = JavaLanguageVersion.of(runtimeVersion)
}
}
[16, 17, 19].forEach { version -> createJavaTestDataSet(version, "Preview", ["--enable-preview"]) }
[16, 17, 19, 21].forEach { version -> createJavaTestDataSet(version, "Preview", ["--enable-preview"]) }
[8, 16].forEach { version -> createJavaTestDataSet(version, "NoDebug", ["-g:none"])}

task compileTestDataJasm(type: JasmCompile) {
Expand Down
4 changes: 4 additions & 0 deletions test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ private void registerDefault() {
register(JAVA_8, "TestTrySplit");
register(JAVA_8, "TestWhileForeach");
register(JAVA_21, "TestRecordPatterns1");
register(JAVA_21_PREVIEW, "TestStrProcessor");
register(JAVA_21_PREVIEW, "TestRawProcessor");
register(JAVA_21_PREVIEW, "TestFmtProcessor");
register(JAVA_21_PREVIEW, "TestCustomProcessor");
}

private void registerEntireClassPath() {
Expand Down
56 changes: 56 additions & 0 deletions testData/results/pkg/TestCustomProcessor.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package pkg;

import java.lang.StringTemplate.Processor;
import java.lang.runtime.TemplateRuntime;

public class TestCustomProcessor {
static Processor<Object, Error> processor;

public void test() {
String s = "Hello";// 7
int i = 42;// 8
double d = 3.14159;// 9
Object result = processor.process(TemplateRuntime.newStringTemplate<"process","Text: "," "," ","">(s, i, d));// 11
}// 12
}

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

Lines mapping:
7 <-> 10
8 <-> 11
9 <-> 12
11 <-> 13
12 <-> 14
43 changes: 43 additions & 0 deletions testData/results/pkg/TestRawProcessor.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pkg;

import java.lang.runtime.TemplateRuntime;

public class TestRawProcessor {
public void test() {
String s = "Hello";// 7
int i = 42;// 8
Object o = null;// 9
StringTemplate template = TemplateRuntime.newStringTemplate<"process","Text: "," "," ","">(s, i, o);// 11
}// 12
}

class 'pkg/TestRawProcessor' {
method 'test ()V' {
0 6
1 6
2 6
3 7
4 7
5 7
6 8
7 8
8 9
9 9
a 9
b 9
c 9
d 9
e 9
f 9
10 9
11 9
12 10
}
}

Lines mapping:
7 <-> 7
8 <-> 8
9 <-> 9
11 <-> 10
12 <-> 11
45 changes: 45 additions & 0 deletions testData/results/pkg/TestStrProcessor.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package pkg;

public class TestStrProcessor {
public void test() {
String s = "Hello";// 5
int i = 42;// 6
Object o = null;// 7
System.out.println("Text: " + s + " " + i + " " + o);// 8
}// 9
}

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

Lines mapping:
5 <-> 5
6 <-> 6
7 <-> 7
8 <-> 8
9 <-> 9
13 changes: 13 additions & 0 deletions testData/src/java21preview/pkg/TestCustomProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pkg;

public class TestCustomProcessor {
static StringTemplate.Processor<Object, Error> processor;

public void test() {
String s = "Hello";
int i = 42;
double d = 3.14159;

Object result = processor."Text: \{s} \{i} \{d}";
}
}
13 changes: 13 additions & 0 deletions testData/src/java21preview/pkg/TestFmtProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pkg;

import static java.util.FormatProcessor.FMT;

public class TestFmtProcessor {
public void test() {
String s = "Hello";
int i = 42;
double d = 3.14159;

System.out.println(FMT."Text: %s\{s} %4d\{i} %.2f\{d}");
}
}
13 changes: 13 additions & 0 deletions testData/src/java21preview/pkg/TestRawProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pkg;

import static java.lang.StringTemplate.RAW;

public class TestRawProcessor {
public void test() {
String s = "Hello";
int i = 42;
Object o = null;

StringTemplate template = RAW."Text: \{s} \{i} \{o}";
}
}
10 changes: 10 additions & 0 deletions testData/src/java21preview/pkg/TestStrProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pkg;

public class TestStrProcessor {
public void test() {
String s = "Hello";
int i = 42;
Object o = null;
System.out.println(STR."Text: \{s} \{i} \{o}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public enum Version {
JAVA_17_PREVIEW(17, "preview", "Preview"),
JAVA_19_PREVIEW(19, "preview", "Preview"),
JAVA_21(21),
JAVA_21_PREVIEW(21, "preview", "Preview"),
GROOVY("groovy", "Groovy"),
KOTLIN("kt", "Kotlin"),
SCALA("scala", "Scala"),
Expand Down

0 comments on commit ea3c2ad

Please sign in to comment.