forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#3228 from mbien/contains
fixed class modifier auto completion for sealed classes.
- Loading branch information
Showing
8 changed files
with
171 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...nfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/afterAbstract.pass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class | ||
enum | ||
interface | ||
non-sealed | ||
record | ||
sealed |
4 changes: 4 additions & 0 deletions
4
...denfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/afterSealed.pass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class | ||
enum | ||
interface | ||
record |
3 changes: 3 additions & 0 deletions
3
...org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/afterSealedClassName.pass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extends | ||
implements | ||
permits |
4 changes: 4 additions & 0 deletions
4
...ldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/finalClass.pass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class | ||
enum | ||
interface | ||
record |
24 changes: 24 additions & 0 deletions
24
java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/Sealed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package test; | ||
|
||
public abstract sealed class Shape permits Circle, Rectangle { | ||
|
||
} |
107 changes: 107 additions & 0 deletions
107
...test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask115FeaturesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
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.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 mbien | ||
*/ | ||
public class JavaCompletionTask115FeaturesTest extends CompletionTestBase { | ||
|
||
private static final String SOURCE_LEVEL = "15"; | ||
|
||
static { | ||
JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true; | ||
} | ||
|
||
public JavaCompletionTask115FeaturesTest(String testName) { | ||
super(testName); | ||
} | ||
|
||
public static NbTestSuite suite() { | ||
NbTestSuite suite = new NbTestSuite(); | ||
try { | ||
SourceVersion.valueOf("RELEASE_"+SOURCE_LEVEL); | ||
suite.addTestSuite(JavaCompletionTask115FeaturesTest.class); | ||
} catch (IllegalArgumentException ex) { | ||
suite.addTest(new JavaCompletionTask115FeaturesTest("noop")); | ||
} | ||
return suite; | ||
} | ||
|
||
public void noop() { } | ||
|
||
|
||
public void testFinalCantBeSealed() throws Exception { | ||
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview"); | ||
performTest("Sealed", 831, "final ", "finalClass.pass", getLatestSource()); | ||
} | ||
|
||
public void testAbstractCanBeSealed() throws Exception { | ||
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview"); | ||
performTest("Sealed", 840, null, "afterAbstract.pass", getLatestSource()); | ||
} | ||
|
||
public void testAfterSealed() throws Exception { | ||
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview"); | ||
performTest("Sealed", 847, null, "afterSealed.pass", getLatestSource()); | ||
} | ||
|
||
public void testPermitsAfterSealedClassName() throws Exception { | ||
TestCompilerOptionsQueryImplementation.EXTRA_OPTIONS.add("--enable-preview"); | ||
performTest("Sealed", 859, null, "afterSealedClassName.pass", getLatestSource()); | ||
} | ||
|
||
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<String> EXTRA_OPTIONS = new ArrayList<>(); | ||
|
||
@Override | ||
public CompilerOptionsQueryImplementation.Result getOptions(FileObject file) { | ||
return new CompilerOptionsQueryImplementation.Result() { | ||
@Override | ||
public List<? extends String> getArguments() { | ||
return EXTRA_OPTIONS; | ||
} | ||
|
||
@Override | ||
public void addChangeListener(ChangeListener listener) {} | ||
|
||
@Override | ||
public void removeChangeListener(ChangeListener listener) {} | ||
}; | ||
} | ||
} | ||
} |