From 44f0c78482f011b87910964b279e43b753068abe Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Sun, 6 Jul 2025 10:44:02 +0200 Subject: [PATCH] Records (final) are a JDK 16+ feature. Reflecting this in the tests - moving into the JDk 16 completion tests, using the appropriate source level. --- .../1.8/typesRecordStaticMembersAndVars.pass | 6 -- .../14/typesRecordStaticMembersAndVars.pass | 1 + .../JavaCompletionTask114FeaturesTest.java | 98 +------------------ .../JavaCompletionTask116FeaturesTest.java | 40 ++++++++ 4 files changed, 42 insertions(+), 103 deletions(-) delete mode 100644 java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/typesRecordStaticMembersAndVars.pass diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/typesRecordStaticMembersAndVars.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/typesRecordStaticMembersAndVars.pass deleted file mode 100644 index 65b2f9a0b521..000000000000 --- a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/typesRecordStaticMembersAndVars.pass +++ /dev/null @@ -1,6 +0,0 @@ -Readable -ReflectiveOperationException -Runnable -Runtime -RuntimeException -RuntimePermission \ No newline at end of file diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/14/typesRecordStaticMembersAndVars.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/14/typesRecordStaticMembersAndVars.pass index 6acc0acae2a4..8a48b456e93b 100644 --- a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/14/typesRecordStaticMembersAndVars.pass +++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/14/typesRecordStaticMembersAndVars.pass @@ -1,5 +1,6 @@ Readable Record +Records ReflectiveOperationException Runnable Runtime diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask114FeaturesTest.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask114FeaturesTest.java index db69f2904789..10cf9db98141 100644 --- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask114FeaturesTest.java +++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask114FeaturesTest.java @@ -18,16 +18,8 @@ */ package org.netbeans.modules.java.completion; -import java.util.ArrayList; -import java.util.List; -import javax.lang.model.SourceVersion; -import javax.swing.event.ChangeListener; -import org.junit.Ignore; -import org.netbeans.junit.NbTestSuite; import org.netbeans.modules.java.source.parsing.JavacParser; -import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation; -import org.openide.filesystems.FileObject; -import org.openide.util.lookup.ServiceProvider; + /** * * @author arusinha @@ -40,100 +32,12 @@ public JavaCompletionTask114FeaturesTest(String testName) { super(testName); } - public static NbTestSuite suite() { - NbTestSuite suite = new NbTestSuite(); - try { - SourceVersion.valueOf("RELEASE_14"); //NOI18N - suite.addTestSuite(JavaCompletionTask114FeaturesTest.class); - } catch (IllegalArgumentException ex) { - //OK, no RELEASE_13, skip tests - suite.addTest(new JavaCompletionTask114FeaturesTest("noop")); //NOI18N - } - return suite; - } - public void testBindingUse() throws Exception { performTest("GenericMethodInvocation", 1231, "boolean b = argO instanceof String str && st", "BindingUse.pass", SOURCE_LEVEL); } - - public void testBeforeLeftRecordBraces() throws Exception { - TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview"); - performTest("Records", 896, null, "implementsKeyword.pass", getLatestSource()); - } - - public void testBeforeRecParamsLeftParen() throws Exception { - TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview"); - performTest("Records", 892, null, "empty.pass", getLatestSource()); - } - - public void testAfterTypeParamInRecParam() throws Exception { - performTest("Records", 890, null, "extendsKeyword.pass", SOURCE_LEVEL); - } - - // TODO "compact source file" feature wraps the compilation unit into additional "final class Test"? - @Ignore - public void testInsideRecAfterStaticKeyWord() throws Exception { - performTest("Records", 918, "R", "typesRecordStaticMembersAndVars.pass", SOURCE_LEVEL); - } - - public void testAnnotationInRecordParam() throws Exception { - performTest("Records", 999, null, "override.pass", SOURCE_LEVEL); - } - - public void testRecordKeywordInsideMethod() throws Exception { - performTest("Records", 1014, "rec", "record.pass", SOURCE_LEVEL); - } - - public void testRecordKeywordInsideClass() throws Exception { - performTest("Records", 844, "rec", "record.pass", SOURCE_LEVEL); - } - - public void testRecordKeywordInsideMethodIfPrefixDoesntMatch() throws Exception { - performTest("Records", 1014, "someprefix", "empty.pass", SOURCE_LEVEL); - } - - public void testRecordKeywordInsideClassIfPrefixDoesntMatch() throws Exception { - performTest("Records", 844, "someprefix", "empty.pass", SOURCE_LEVEL); - } - - public void testVariableNameSuggestion() throws Exception { - TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview"); - performTest("Records", 1071, null, "recordVariableSuggestion.pass", getLatestSource()); - } - - public void noop() { - } - static { JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true; } - private String getLatestSource(){ - return SourceVersion.latest().name().substring(SourceVersion.latest().name().indexOf("_")+1); - } - @ServiceProvider(service = CompilerOptionsQueryImplementation.class, position = 100) - public static class TestCompilerOptionsQueryImplementation implements CompilerOptionsQueryImplementation { - - private static final List EXTRA_OPTIONS = new ArrayList<>(); - - @Override - public CompilerOptionsQueryImplementation.Result getOptions(FileObject file) { - return new CompilerOptionsQueryImplementation.Result() { - @Override - public List getArguments() { - return EXTRA_OPTIONS; - } - - @Override - public void addChangeListener(ChangeListener listener) { - } - - @Override - public void removeChangeListener(ChangeListener listener) { - } - }; - } - - } } diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask116FeaturesTest.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask116FeaturesTest.java index 00fbe2ae9bc7..f9493def699e 100644 --- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask116FeaturesTest.java +++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask116FeaturesTest.java @@ -41,6 +41,46 @@ public void testInstanceofPatternCompletion_3() throws Exception { performTest("InstanceofPattern", 926, null, "stringContent.pass", SOURCE_LEVEL); } + public void testBeforeLeftRecordBraces() throws Exception { + performTest("Records", 896, null, "implementsKeyword.pass", SOURCE_LEVEL); + } + + public void testBeforeRecParamsLeftParen() throws Exception { + performTest("Records", 892, null, "empty.pass", SOURCE_LEVEL); + } + + public void testAfterTypeParamInRecParam() throws Exception { + performTest("Records", 890, null, "extendsKeyword.pass", SOURCE_LEVEL); + } + + public void testInsideRecAfterStaticKeyWord() throws Exception { + performTest("Records", 918, "R", "typesRecordStaticMembersAndVars.pass", SOURCE_LEVEL); + } + + public void testAnnotationInRecordParam() throws Exception { + performTest("Records", 999, null, "override.pass", SOURCE_LEVEL); + } + + public void testRecordKeywordInsideMethod() throws Exception { + performTest("Records", 1014, "rec", "record.pass", SOURCE_LEVEL); + } + + public void testRecordKeywordInsideClass() throws Exception { + performTest("Records", 844, "rec", "record.pass", SOURCE_LEVEL); + } + + public void testRecordKeywordInsideMethodIfPrefixDoesntMatch() throws Exception { + performTest("Records", 1014, "someprefix", "empty.pass", SOURCE_LEVEL); + } + + public void testRecordKeywordInsideClassIfPrefixDoesntMatch() throws Exception { + performTest("Records", 844, "someprefix", "empty.pass", SOURCE_LEVEL); + } + + public void testVariableNameSuggestion() throws Exception { + performTest("Records", 1071, null, "recordVariableSuggestion.pass", SOURCE_LEVEL); + } + static { JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true; }