Skip to content

Commit

Permalink
8321182: SourceExample.SOURCE_14 comment should refer to 'switch expr…
Browse files Browse the repository at this point in the history
…essions' instead of 'text blocks'

Reviewed-by: darcy
  • Loading branch information
eirbjo authored and jddarcy committed Dec 1, 2023
1 parent 3a09a05 commit 2f299e4
Showing 1 changed file with 23 additions and 32 deletions.
55 changes: 23 additions & 32 deletions test/langtools/tools/javac/versions/Versions.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
import javax.tools.StandardJavaFileManager;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/*
Expand Down Expand Up @@ -240,16 +238,8 @@ protected void check(String major) {

protected void check(String major, List<String> args) {
printargs("check", args);
List<String> jcargs = new ArrayList<>();
jcargs.add("-Xlint:-options");

// add in args conforming to List requrements of JavaCompiler
for (String onearg : args) {
String[] fields = onearg.split(" ");
for (String onefield : fields) {
jcargs.add(onefield);
}
}
List<String> jcargs = javaCompilerOptions(args);

boolean creturn = compile("Base.java", jcargs);
if (!creturn) {
Expand All @@ -264,6 +254,25 @@ protected void check(String major, List<String> args) {
}
}

/**
* Create a list of options suitable for use with {@link JavaCompiler}
* @param args a list of space-delimited options, such as "-source 11"
* @return a list of arguments suitable for use with {@link JavaCompiler}
*/
private static List<String> javaCompilerOptions(List<String> args) {
List<String> jcargs = new ArrayList<>();
jcargs.add("-Xlint:-options");

// add in args conforming to List requirements of JavaCompiler
for (String onearg : args) {
String[] fields = onearg.split(" ");
for (String onefield : fields) {
jcargs.add(onefield);
}
}
return jcargs;
}

/**
* The BASE source example is expected to compile on all source
* levels. Otherwise, an example is expected to compile on its
Expand Down Expand Up @@ -311,7 +320,7 @@ void m(String name) {
"""),

SOURCE_14(14, "New14.java",
// New feature in 14: text blocks
// New feature in 14: switch expressions
"""
public class New14 {
static {
Expand Down Expand Up @@ -427,16 +436,7 @@ protected void expectedFail(List<String> args, List<String> fileNames) {
protected void pass(List<String> args) {
printargs("pass", args);

List<String> jcargs = new ArrayList<>();
jcargs.add("-Xlint:-options");

// add in args conforming to List requrements of JavaCompiler
for (String onearg : args) {
String[] fields = onearg.split(" ");
for (String onefield : fields) {
jcargs.add(onefield);
}
}
List<String> jcargs = javaCompilerOptions(args);

// empty list is error
if (jcargs.isEmpty()) {
Expand Down Expand Up @@ -464,16 +464,7 @@ protected void pass(List<String> args) {
protected void fail(List<String> args) {
printargs("fail", args);

List<String> jcargs = new ArrayList<>();
jcargs.add("-Xlint:-options");

// add in args conforming to List requrements of JavaCompiler
for (String onearg : args) {
String[] fields = onearg.split(" ");
for (String onefield : fields) {
jcargs.add(onefield);
}
}
List<String> jcargs = javaCompilerOptions(args);

// empty list is error
if (jcargs.isEmpty()) {
Expand Down

0 comments on commit 2f299e4

Please sign in to comment.