From 5c9b0d5489487a746c6086f1f0bcf4b12927c4bd Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 15 Jan 2020 17:54:18 +0300 Subject: [PATCH] [groovy] check if code reference immediate parent is a file in GrCodeReferenceElement#getActualParent Immediate parent is a file when the reference is created from stub, in other cases it might be a child of another tree with another context, so it's incorrect to go to the containing file skipping the tree; for example when inferring parameter types from outer calls the reference will be part of big method tree with the original method as a context. GitOrigin-RevId: 30b1cc4d25b803cfd7291d2f4019acec6c2420f6 --- .../plugins/groovy/lang/resolve/GrCodeReferenceResolver.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrCodeReferenceResolver.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrCodeReferenceResolver.kt index 50ff3f9f11be..ae76ceeca81e 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrCodeReferenceResolver.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrCodeReferenceResolver.kt @@ -231,7 +231,10 @@ private fun GrCodeReferenceElement.canResolveToInnerClassOfCurrentClass(): Boole /** * Reference element may be created from stub. In this case containing file will be dummy, and its context will be reference parent */ -private fun GrCodeReferenceElement.getActualParent(): PsiElement? = containingFile.context ?: parent +private fun GrCodeReferenceElement.getActualParent(): PsiElement? { + val parent = parent + return (parent as? PsiFile)?.context ?: parent +} /** * @see org.codehaus.groovy.control.ResolveVisitor.currentClass