[Java. Code Formatting] IDEA-168035 Treat jspecify annotations as type annotations in formatter

- Add module import for jetbrains annotations

GitOrigin-RevId: c42016573959a8e9815b479d4517b3143a9bc2b2
This commit is contained in:
Georgii Ustinov
2025-09-02 11:47:03 +03:00
committed by intellij-monorepo-bot
parent 718d7187f3
commit 8fb486f0c9
4 changed files with 54 additions and 1 deletions

View File

@@ -31,9 +31,10 @@ object DumbAwareAnnotationUtil {
/**
* Represents a mapping from a fully qualified name of a module to a set of fully qualified names of annotations
* that are treated as a type annotations and located in this module
* that are treated as type annotations and located in this module
*/
private val KNOWN_MODULE_TO_ANNOTATIONS_MAP = mapOf(
"org.jetbrains.annotations" to setOf(AnnotationUtil.NOT_NULL, AnnotationUtil.NULLABLE, AnnotationUtil.NON_NLS),
"org.jspecify" to setOf(AnnotationUtil.J_SPECIFY_NON_NULL, AnnotationUtil.J_SPECIFY_NULLABLE)
)

View File

@@ -0,0 +1,26 @@
package org.example;
import module org.jetbrains.annotations;
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,21 @@
package org.example;
import module org.jetbrains.annotations;
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

@@ -60,6 +60,11 @@ class TypeAnnotationFormatterTest : LightJavaCodeInsightFixtureTestCase() {
doTest()
}
fun testModuleImport() {
IdeaTestUtil.setModuleLanguageLevel(myFixture.module, LanguageLevel.JDK_25)
doTest()
}
private fun doTest() {
val testName = getTestName(false)
myFixture.configureByFile("$testName.java")