From 5ed98e6eb9d8fe7b8b67fcd0cce6d35891c90f4b Mon Sep 17 00:00:00 2001 From: Georgii Ustinov Date: Thu, 13 Jun 2024 12:03:32 +0300 Subject: [PATCH] [Java. Code Formatting] Add javadoc to the TypeAnnotationUtil IDEA-353192 GitOrigin-RevId: 8394fec995a17c625c14ce548b92278dba1d4fd4 --- .../psi/formatter/java/TypeAnnotationUtil.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/TypeAnnotationUtil.kt b/java/java-impl/src/com/intellij/psi/formatter/java/TypeAnnotationUtil.kt index c2abd4cb16f4..db076fe30fd7 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/TypeAnnotationUtil.kt +++ b/java/java-impl/src/com/intellij/psi/formatter/java/TypeAnnotationUtil.kt @@ -4,20 +4,34 @@ package com.intellij.psi.formatter.java import com.intellij.lang.ASTNode import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.* +import com.intellij.psi.formatter.java.TypeAnnotationUtil.KNOWN_TYPE_ANNOTATIONS +import com.intellij.psi.formatter.java.TypeAnnotationUtil.isTypeAnnotation import com.intellij.psi.util.CachedValueProvider import com.intellij.psi.util.CachedValuesManager import com.intellij.psi.util.PsiModificationTracker import com.intellij.psi.util.PsiTreeUtil +/** + * This class was designed to handle detection of type annotation during building blocks phase of Java formatter. + * As there is no resolving available, it relies on local import table and known type annotations. + * @see KNOWN_TYPE_ANNOTATIONS + * @see isTypeAnnotation + */ internal object TypeAnnotationUtil { private val KNOWN_TYPE_ANNOTATIONS: Set = setOf( "org.jetbrains.annotations.NotNull", "org.jetbrains.annotations.Nullable" ) + /** + * Checks if the given ASTNode represents a type annotation. + * + * @param annotation the ASTNode to check if it is a type annotation or not. + * @return true if the ASTNode represents a type annotation, false otherwise + */ @JvmStatic - fun isTypeAnnotation(child: ASTNode): Boolean { - val node = child.psi as? PsiAnnotation ?: return false + fun isTypeAnnotation(annotation: ASTNode): Boolean { + val node = annotation.psi as? PsiAnnotation ?: return false val next = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace::class.java, PsiAnnotation::class.java) if (next is PsiKeyword) return false val psiReference: PsiJavaCodeReferenceElement = node.nameReferenceElement ?: return false