[Java. Code Formatting] Add check to TypeAnnotationUtil that language level is at least 8

IDEA-353192

GitOrigin-RevId: e8d2d8270dbc1c39300d5a2d55ef993e433ccdbc
This commit is contained in:
Georgii Ustinov
2024-06-20 11:57:57 +03:00
committed by intellij-monorepo-bot
parent 7fe1e933e6
commit 41cf8f6fe3
6 changed files with 72 additions and 3 deletions

View File

@@ -6,7 +6,8 @@ public interface MyTestClass {
}
public class MyRealTestClass implements MyTestClass {
@NotNull String implementMe(String arg) {
@NotNull
String implementMe(String arg) {
}
}

View File

@@ -0,0 +1,24 @@
package org.example;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Formatter {
@NotNull @Nullable String breakLineBetweenAnnotations() {
return "";
}
@Nullable
@NotNull String breakLineBetweenTypeAndAnnotations() {
return null;
}
@Nullable <T> String breakLineBetweenTypeParameterAndAnnotation() {
return null;
}
@Nullable
@NotNull <T> String breakLineMixed() {
return null;
}
}

View File

@@ -0,0 +1,29 @@
package org.example;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Formatter {
@NotNull
@Nullable
String breakLineBetweenAnnotations() {
return "";
}
@Nullable
@NotNull
String breakLineBetweenTypeAndAnnotations() {
return null;
}
@Nullable
<T> String breakLineBetweenTypeParameterAndAnnotation() {
return null;
}
@Nullable
@NotNull
<T> String breakLineMixed() {
return null;
}
}

View File

@@ -6,9 +6,11 @@ import com.intellij.application.options.CodeStyle
import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.pom.java.LanguageLevel
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.WRAP_ALWAYS
import com.intellij.testFramework.IdeaTestUtil
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
@@ -22,6 +24,7 @@ class TypeAnnotationFormatterTest : LightJavaCodeInsightFixtureTestCase() {
super.setUp()
commonSettings.KEEP_LINE_BREAKS = false
commonSettings.METHOD_ANNOTATION_WRAP = WRAP_ALWAYS
IdeaTestUtil.setProjectLanguageLevel(myFixture.project, LanguageLevel.JDK_1_8)
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotations)
}
@@ -52,6 +55,11 @@ class TypeAnnotationFormatterTest : LightJavaCodeInsightFixtureTestCase() {
doTest()
}
fun testLowLanguageLevel() {
IdeaTestUtil.setProjectLanguageLevel(myFixture.project, LanguageLevel.JDK_1_7)
doTest()
}
private fun doTest() {
val testName = getTestName(false)
myFixture.configureByFile("$testName.java")