Uast-Groovy: better uastAnchor-s (IDEA-CR-28371)

This commit is contained in:
Nicolay Mitropolsky
2018-01-12 21:47:58 +03:00
parent 62b229c701
commit 4c03a64d86
5 changed files with 33 additions and 6 deletions
@@ -32,7 +32,7 @@ class GrUClass(val grElement: GrTypeDefinition, parentProvider: () -> UElement?)
}
override val uastAnchor: UElement?
get() = UIdentifier(psi.nameIdentifier, this)
get() = UIdentifier(grElement.nameIdentifierGroovy, this)
override val uastParent by lazy(parentProvider)
@@ -67,7 +67,7 @@ class GrUMethod(val grElement: GrMethod, parentProvider: () -> UElement?) : UMet
override val isOverride: Boolean by lazy { psi.modifierList.findAnnotation("java.lang.Override") != null }
override val uastAnchor: UElement?
get() = UIdentifier((psi.originalElement as? PsiNameIdentifierOwner)?.nameIdentifier ?: psi.nameIdentifier, this)
get() = UIdentifier(grElement.nameIdentifierGroovy, this)
override val annotations: List<UAnnotation> by lazy { grAnnotations(grElement.modifierList, this) }
@@ -87,14 +87,14 @@ class GrUParameter(val grElement: GrParameter,
override val psi = javaPsi
override val uastInitializer by lazy {
val initializer = psi.initializer ?: return@lazy null
val initializer = grElement.initializerGroovy ?: return@lazy null
getLanguagePlugin().convertElement(initializer, this) as? UExpression
}
override val typeReference: UTypeReferenceExpression? = null //not implemented
override val uastAnchor: UElement
get() = UIdentifier(psi.nameIdentifier, this)
get() = UIdentifier(grElement.nameIdentifierGroovy, this)
override val annotations: List<UAnnotation> by lazy { grAnnotations(grElement.modifierList, this) }
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package org.jetbrains.plugins.groovy.uast
import junit.framework.TestCase
import org.jetbrains.uast.UFile
import org.junit.Test
class GroovyUastApiTest : AbstractGroovyUastTest() {
override fun check(testName: String, file: UFile) {
}
@Test
fun testUastAnchors() {
doTest("SimpleClass.groovy") { name, file ->
val uClass = file.classes.single { it.qualifiedName == "SimpleClass" }
TestCase.assertEquals("SimpleClass", uClass.uastAnchor?.psi?.text)
val uMethod = uClass.methods.single { it.name == "bar" }
TestCase.assertEquals("bar", uMethod.uastAnchor?.psi?.text)
val uParameter = uMethod.uastParameters.single()
TestCase.assertEquals("param", uParameter.uastAnchor?.psi?.text)
}
}
}
+1 -1
View File
@@ -8,5 +8,5 @@ class SimpleClass {
@java.lang.Deprecated
def foo() { return field }
String bar() { return "abc$field" }
String bar(int param) { return "abc$field$param" }
}
+1
View File
@@ -5,3 +5,4 @@ UFile (package = )
UMethod (name = foo)
UAnnotation (fqName = java.lang.Deprecated)
UMethod (name = bar)
UParameter (name = param)
+1 -1
View File
@@ -4,5 +4,5 @@ public abstract annotation SimpleAnnotation {
public class SimpleClass {
@java.lang.Deprecated
public fun foo() : java.lang.Object = UastEmptyExpression
public fun bar() : java.lang.String = UastEmptyExpression
public fun bar(param: int) : java.lang.String = UastEmptyExpression
}