diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlock.java b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlock.java index 35f09179b120..cda4485edbd8 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlock.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlock.java @@ -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; @@ -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; diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java index 91749bdcad25..9289ec2ec40b 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java @@ -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 ; @@ -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() @@ -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 ; @@ -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() @@ -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 ; @@ -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() @@ -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 ; @@ -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(); }