From 033e0ca5f01fb7a57220b56e547b1cc96db23bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Wed, 18 Sep 2024 09:41:24 +0200 Subject: [PATCH] [test] remove Java source level 1.5 workaround to avoid warnings in build output https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2975 --- .../jdt/core/tests/util/TestVerifier.java | 35 ++++--------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java index 471b84e994e..36c70d59d61 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java @@ -20,12 +20,12 @@ import java.io.*; import java.lang.ref.Cleaner; import java.net.*; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; /** * Verifies that the .class files resulting from a compilation can be loaded @@ -377,7 +377,7 @@ public String getExecutionError(){ * {@link #READ_VERIFY_TEST_FROM_FILE} after calling this method for the first time, the return value will not change * anymore. * - * @return {@link VerifyTests} source code, filtered by {@link #filterSourceCode(Stream)} + * @return {@link VerifyTests} source code */ String getVerifyTestsCode() { synchronized (verifyTestCodeLock) { @@ -387,8 +387,8 @@ String getVerifyTestsCode() { if (!new File(sourceFile).exists()) { sourceFile = PROJECT_BASE_DIR + "/org.eclipse.jdt.core.tests.compiler/" + sourceFile; } - try (BufferedReader reader = new BufferedReader(new FileReader(sourceFile))) { - verifyTestCode = filterSourceCode(reader.lines()); + try { + verifyTestCode=Files.readString(Path.of(sourceFile)); } catch (IOException e) { System.out.println("WARNING: Cannot read & filter VerifyTests source code from file, using default value"); @@ -397,35 +397,12 @@ String getVerifyTestsCode() { } } if (verifyTestCode == null) { - try (BufferedReader reader = new BufferedReader(new StringReader(VERIFY_TEST_CODE_DEFAULT))) { - verifyTestCode = filterSourceCode(reader.lines()); - } - catch (IOException e) { - System.out.println("WARNING: Cannot filter VerifyTests source code default value, using unfiltered value"); - System.out.println(" - exception: " + e); - verifyTestCode = VERIFY_TEST_CODE_DEFAULT; - } + verifyTestCode = VERIFY_TEST_CODE_DEFAULT; } return verifyTestCode; } } -/** - * Filter some elements incompatible with Java source level 1.5 from source code - *

- * This method cannot convert things like catch-with-resources or other language elements back to Java 1.5, you have to - * take care of keeping the source code backward compatible by yourself. But a few things you can still use in the - * source code, such as {@code @SuppressWarnings}, {@code @Override} in interfaces or single-line {@code assert}. - * - * @param sourceCodeLines stream of source code lines - * @return filtered source code file as a string - */ -private String filterSourceCode(Stream sourceCodeLines) { - return sourceCodeLines - .filter(s -> !(s.contains("@SuppressWarnings") || s.contains("@Override") || s.contains("assert "))) - .collect(Collectors.joining("\n")); -} - /** * Remove non-essential parts of the test JVM classpath *