IDEA-CR-56660 UAST: JavaConstructorUCallExpression multiResolve() for constructor methods

GitOrigin-RevId: 71f22e1151f9ad89e3e26c5845bfbf481744368d
This commit is contained in:
Yuriy Artamonov
2019-12-18 16:03:07 +00:00
committed by intellij-monorepo-bot
parent cc965dbcba
commit 6a01cb2d5e
4 changed files with 32 additions and 23 deletions
@@ -184,7 +184,7 @@ class JavaConstructorUCallExpression(
val methodResolve = sourcePsi.resolveMethodGenerics()
if (methodResolve != JavaResolveResult.EMPTY) {
// if there is a non-default constructor
return arrayOf<ResolveResult>(methodResolve).asIterable()
return listOf<ResolveResult>(methodResolve)
}
// unable to resolve constructor method - resolve to class
val classResolve = sourcePsi.classReference?.multiResolve(false) ?: emptyArray()
@@ -1,14 +1,14 @@
UField (name = number) -> UTypeReferenceExpression (name = int) -> null
UParameter (name = number) -> UTypeReferenceExpression (name = int) -> null
UMethod (name = Foo) -> UBlockExpression -> null
UBlockExpression -> UBinaryExpression (operator = =) -> null
UBlockExpression -> UBinaryExpression (operator = =) -> null
UBinaryExpression (operator = =) -> UQualifiedReferenceExpression -> [M] PsiFieldImpl
UQualifiedReferenceExpression -> UThisExpression (label = null) -> [M]
UBinaryExpression (operator = =) -> USimpleNameReferenceExpression (identifier = number) -> [M] PsiParameterImpl
UMethod (name = test) -> UTypeReferenceExpression (name = void) -> null
UMethod (name = test) -> UBlockExpression -> null
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> [M] PsiMethodImpl
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> [M] PsiMethodImpl
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> USimpleNameReferenceExpression (identifier = Foo) -> [M] PsiClassImpl
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> ULiteralExpression (value = 10) -> null
UField (name = number) -> UTypeReferenceExpression (name = int) -> [] ~= []
UParameter (name = number) -> UTypeReferenceExpression (name = int) -> [] ~= []
UMethod (name = Foo) -> UBlockExpression -> [] ~= []
UBlockExpression -> UBinaryExpression (operator = =) -> [] ~= []
UBlockExpression -> UBinaryExpression (operator = =) -> [] ~= []
UBinaryExpression (operator = =) -> UQualifiedReferenceExpression -> [M] PsiFieldImpl ~= PsiField:number
UQualifiedReferenceExpression -> UThisExpression (label = null) -> [M] ~= []
UBinaryExpression (operator = =) -> USimpleNameReferenceExpression (identifier = number) -> [M] PsiParameterImpl ~= PsiParameter:number
UMethod (name = test) -> UTypeReferenceExpression (name = void) -> [] ~= []
UMethod (name = test) -> UBlockExpression -> [] ~= []
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> [M] PsiMethodImpl ~= PsiMethod:Foo
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> [M] PsiMethodImpl ~= PsiMethod:Foo
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> USimpleNameReferenceExpression (identifier = Foo) -> [M] PsiClassImpl ~= PsiClass:Foo
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1)) -> ULiteralExpression (value = 10) -> [] ~= []
@@ -1,5 +1,5 @@
UMethod (name = test) -> UTypeReferenceExpression (name = void) -> null
UMethod (name = test) -> UBlockExpression -> null
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> [M] PsiClassImpl
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> [M] PsiClassImpl
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = Foo) -> [M] PsiClassImpl
UMethod (name = test) -> UTypeReferenceExpression (name = void) -> [] ~= []
UMethod (name = test) -> UBlockExpression -> [] ~= []
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> [M] PsiClassImpl ~= []
UBlockExpression -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> [M] PsiClassImpl ~= []
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) -> USimpleNameReferenceExpression (identifier = Foo) -> [M] PsiClassImpl ~= PsiClass:Foo
@@ -24,18 +24,27 @@ abstract class AbstractJavaExpressionMultiResolveTest : AbstractJavaUastTest() {
append(ref.asLogString())
append(" -> ")
append(multiResolve(ref))
append(" ~= ")
append(resolve(ref))
}
}
}.visitUFileAndGetResult(this)
private fun multiResolve(ref: UExpression): String {
if (ref is UMultiResolvable) {
return "[M] " + ref.multiResolve().joinToString(",") { it.element?.javaClass?.simpleName ?: "null" }
return "[M] " + ref.multiResolve().joinToString(",") { it.element?.javaClass?.simpleName ?: "[]" }
}
if (ref is UResolvable) {
return "[S] " + (ref.resolve()?.toString() ?: "null")
return "[S] " + (ref.resolve()?.toString() ?: "[]")
}
return "null"
return "[]"
}
private fun resolve(ref: UExpression): String {
if (ref is UResolvable) {
return (ref.resolve()?.toString() ?: "[]")
}
return "[]"
}
override fun check(testName: String, file: UFile) {