mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] fix collecting outers for anonymous classes (IDEA-190433)
This commit is contained in:
+11
-4
@@ -233,11 +233,18 @@ private fun GrCodeReferenceElement.getActualParent(): PsiElement? = containingFi
|
||||
* @see org.codehaus.groovy.control.ResolveVisitor.currentClass
|
||||
*/
|
||||
private fun PsiElement.getCurrentClass(): GrTypeDefinition? {
|
||||
var contexts = contexts().filterIsInstance<GrTypeDefinition>()
|
||||
if (context is GrAnonymousClassDefinition) {
|
||||
contexts = contexts.drop(1)
|
||||
for (context in contexts()) {
|
||||
if (context !is GrTypeDefinition) {
|
||||
continue
|
||||
}
|
||||
else if (context is GrAnonymousClassDefinition && this === context.baseClassReferenceGroovy) {
|
||||
continue
|
||||
}
|
||||
else {
|
||||
return context
|
||||
}
|
||||
}
|
||||
return contexts.firstOrNull()
|
||||
return null
|
||||
}
|
||||
|
||||
private fun PsiFile?.skipDummies(): PsiFile? {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2017 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.
|
||||
// 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.
|
||||
@file:Suppress("LoopToCallChain", "UseExpressionBody", "LiftReturnOrAssignment")
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.resolve
|
||||
@@ -9,7 +9,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.ResolveState
|
||||
import com.intellij.psi.impl.PsiFileEx
|
||||
import com.intellij.psi.scope.PsiScopeProcessor
|
||||
import com.intellij.util.SmartList
|
||||
import com.intellij.psi.util.parentsOfType
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil
|
||||
@@ -111,13 +111,7 @@ internal fun GrTypeDefinition.processInnersInOutersNoCache(processor: PsiScopePr
|
||||
}
|
||||
|
||||
private fun GrTypeDefinition.collectOuterClasses(): List<GrTypeDefinition> {
|
||||
val result = SmartList<GrTypeDefinition>()
|
||||
var current: GrTypeDefinition? = containingClass as? GrTypeDefinition
|
||||
while (current != null) {
|
||||
result += current
|
||||
current = current.containingClass as? GrTypeDefinition
|
||||
}
|
||||
return result
|
||||
return parentsOfType<GrTypeDefinition>().drop(1).toList()
|
||||
}
|
||||
|
||||
private fun useCaches(place: PsiElement): Boolean {
|
||||
|
||||
@@ -639,5 +639,20 @@ println Outer.<caret>Inner
|
||||
''', PsiClass
|
||||
}
|
||||
|
||||
void 'test resolve to inner class of outer class of anonymous class'() {
|
||||
resolveByText '''\
|
||||
class Foobar {
|
||||
private static class Quuz {}
|
||||
void foo() {
|
||||
new Runnable() {
|
||||
void run() {
|
||||
new <caret>Quuz()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
''', PsiClass
|
||||
}
|
||||
|
||||
private void doTest(String fileName = getTestName(false) + ".groovy") { resolve(fileName, PsiClass) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user