Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.TreePath;
import java.util.List;
import javax.lang.model.SourceVersion;
import org.netbeans.api.java.queries.CompilerOptionsQuery;
import org.netbeans.api.java.source.CompilationInfo;
import org.netbeans.modules.java.hints.errors.Utilities;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.Fix;
import org.netbeans.spi.java.hints.ConstraintVariableType;
Expand All @@ -45,10 +47,12 @@
})
public class ConvertToTextBlock {

private static final int TEXT_BLOCK_PREVIEW_JDK_VERSION = 14;

@TriggerTreeKind(Kind.PLUS)
@Messages("ERR_ConvertToTextBlock=Can be converted to text block")
public static ErrorDescription computeWarning(HintContext ctx) {
if (!CompilerOptionsQuery.getOptions(ctx.getInfo().getFileObject()).getArguments().contains("--enable-preview"))
if (Utilities.isJDKVersionLower(TEXT_BLOCK_PREVIEW_JDK_VERSION) && !CompilerOptionsQuery.getOptions(ctx.getInfo().getFileObject()).getArguments().contains("--enable-preview"))
return null;
if (ctx.getPath().getParentPath() != null && getTextOrNull(ctx.getPath().getParentPath()) != null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ConvertToTextBlockTest {
@Test
public void testFixWorking() throws Exception {
try {
SourceVersion.valueOf("RELEASE_13");
SourceVersion.valueOf("RELEASE_15");
} catch (IllegalArgumentException ex) {
//OK, skip test
return ;
Expand All @@ -42,7 +42,6 @@ public void testFixWorking() throws Exception {
" }\n" +
"}\n")
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertToTextBlock.class)
.findWarning("3:30-3:37:verifier:" + Bundle.ERR_ConvertToTextBlock())
.applyFix()
Expand All @@ -62,7 +61,7 @@ public void testFixWorking() throws Exception {
@Test
public void testNewLineAtEnd() throws Exception {
try {
SourceVersion.valueOf("RELEASE_13");
SourceVersion.valueOf("RELEASE_15");
} catch (IllegalArgumentException ex) {
//OK, skip test
return ;
Expand All @@ -77,7 +76,6 @@ public void testNewLineAtEnd() throws Exception {
" }\n" +
"}\n")
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertToTextBlock.class)
.findWarning("3:30-3:37:verifier:" + Bundle.ERR_ConvertToTextBlock())
.applyFix()
Expand All @@ -98,7 +96,7 @@ public void testNewLineAtEnd() throws Exception {
@Test
public void testNewLinesAtEnd() throws Exception {
try {
SourceVersion.valueOf("RELEASE_13");
SourceVersion.valueOf("RELEASE_15");
} catch (IllegalArgumentException ex) {
//OK, skip test
return ;
Expand All @@ -113,7 +111,6 @@ public void testNewLinesAtEnd() throws Exception {
" }\n" +
"}\n")
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertToTextBlock.class)
.findWarning("3:30-3:37:verifier:" + Bundle.ERR_ConvertToTextBlock())
.applyFix()
Expand All @@ -134,7 +131,7 @@ public void testNewLinesAtEnd() throws Exception {
@Test
public void testOnlyLiterals() throws Exception {
try {
SourceVersion.valueOf("RELEASE_13");
SourceVersion.valueOf("RELEASE_15");
} catch (IllegalArgumentException ex) {
//OK, skip test
return ;
Expand All @@ -148,7 +145,6 @@ public void testOnlyLiterals() throws Exception {
" private int c() { return 0; }\n" +
"}\n")
.sourceLevel(SourceVersion.latest().name())
.options("--enable-preview")
.run(ConvertToTextBlock.class)
.assertWarnings();
}
Expand Down