[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
This commit is contained in:
Daniil Ovchinnikov
2020-01-16 08:11:51 +00:00
committed by intellij-monorepo-bot
parent 8aae2a397e
commit 5c9b0d5489
@@ -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