diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java index c08dd190c52..bfc0663aca0 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java @@ -248,7 +248,7 @@ private static Optional getConstantSourceCode( StringBuilder source = new StringBuilder(); for (ExpressionTree sourceLine : sourceLines) { - if (!source.isEmpty()) { + if (source.length() > 0) { source.append('\n'); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java index c14b5b14097..f0dac86b80d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java @@ -25,7 +25,9 @@ private SourceCode() {} */ // XXX: Add tests! public static boolean isTextBlockSupported(VisitorState state) { - return Target.instance(state.context).compareTo(Target.JDK1_15) >= 0; + // XXX: String comparison is for JDK 11 compatibility. Is there a better way? + return Target.instance(state.context).toString().compareTo("JDK1_15") >= 0; + // return Target.instance(state.context).compareTo(Target.JDK1_15) >= 0; } /** diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java index 10865a061d6..ae7c61d6356 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java @@ -4,6 +4,8 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledForJreRange; +import org.junit.jupiter.api.condition.JRE; final class ErrorProneTestHelperSourceFormatTest { private final CompilationTestHelper compilationTestHelper = @@ -19,6 +21,10 @@ final class ErrorProneTestHelperSourceFormatTest { ErrorProneTestHelperSourceFormat.class, getClass()) .setArgs("-XepOpt:ErrorProneTestHelperSourceFormat:AvoidTextBlocks=true"); + // XXX: Consider reducing the `@DisabledForJreRange(max = JRE.JAVA_14)` test scope by moving the + // text blocks to smaller test methods. + + @DisabledForJreRange(max = JRE.JAVA_14) @Test void identification() { compilationTestHelper @@ -86,6 +92,7 @@ class B {} .doTest(); } + @DisabledForJreRange(max = JRE.JAVA_14) @Test void identificationAvoidTextBlocks() { avoidTextBlocksCompilationTestHelper