[uast-java] Don't show type annotations on methods

#IDEA-336319 Fixed

GitOrigin-RevId: ce7aa689c95e379f0013899822550c78c51f2309
This commit is contained in:
Bart van Helvert
2024-01-22 12:37:26 +01:00
committed by intellij-monorepo-bot
parent 0e6d7df032
commit 559ba08c10
5 changed files with 53 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
package org.jetbrains.uast.java
import com.intellij.codeInsight.AnnotationTargetUtil
import com.intellij.psi.*
import com.intellij.psi.impl.light.LightElement
import com.intellij.psi.impl.light.LightRecordCanonicalConstructor
@@ -37,7 +38,12 @@ open class JavaUMethod(
}
override val uAnnotations: List<UAnnotation>
get() = uAnnotationsPart.getOrBuild { javaPsi.annotations.map { JavaUAnnotation(it, this) } }
get() = uAnnotationsPart.getOrBuild {
javaPsi.annotations.mapNotNull {
if (AnnotationTargetUtil.findAnnotationTarget(it, PsiAnnotation.TargetType.METHOD) == null) return@mapNotNull null
JavaUAnnotation(it, this)
}
}
override val uastParameters: List<UParameter>
get() = uastParametersPart.getOrBuild {

View File

@@ -0,0 +1,10 @@
package test.pkg;
@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE)
public @interface A {}
public class Foo {
public @A int foo1() {}
public @A String foo2() {}
public @A <T> T foo3() {}
}

View File

@@ -0,0 +1,20 @@
UFile (package = test.pkg)
UClass (name = A)
UAnnotation (fqName = java.lang.annotation.Target)
UNamedExpression (name = null)
UQualifiedReferenceExpression
UQualifiedReferenceExpression
UQualifiedReferenceExpression
UQualifiedReferenceExpression
USimpleNameReferenceExpression (identifier = java)
USimpleNameReferenceExpression (identifier = lang)
USimpleNameReferenceExpression (identifier = annotation)
USimpleNameReferenceExpression (identifier = ElementType)
USimpleNameReferenceExpression (identifier = TYPE_USE)
UClass (name = Foo)
UMethod (name = foo1)
UBlockExpression
UMethod (name = foo2)
UBlockExpression
UMethod (name = foo3)
UBlockExpression

View File

@@ -0,0 +1,13 @@
package test.pkg
public abstract annotation A {
}
public class Foo {
public fun foo1() : int {
}
public fun foo2() : java.lang.String {
}
public fun foo3() : T {
}
}

View File

@@ -76,4 +76,7 @@ class SimpleJavaRenderLogTest : AbstractJavaRenderLogTest(), RenderLogTestBase {
@Test
fun testRecord() = doTest("Simple/Record.java")
@Test
fun testTypeAnnotations() = doTest("Simple/TypeAnnotations.java")
}