mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] add and use FindFirstProcessor
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.resolve.processors
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.ResolveState
|
||||
import com.intellij.psi.scope.NameHint
|
||||
import com.intellij.psi.scope.ProcessorWithHints
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GrResolverProcessor
|
||||
|
||||
abstract class FindFirstProcessor(name: String) : ProcessorWithHints(), GrResolverProcessor<GroovyResolveResult> {
|
||||
|
||||
init {
|
||||
hint(NameHint.KEY, NameHint { name })
|
||||
}
|
||||
|
||||
private var result: GroovyResolveResult? = null
|
||||
|
||||
final override val results: List<GroovyResolveResult> get() = result?.let { listOf(it) } ?: emptyList()
|
||||
|
||||
final override fun execute(element: PsiElement, state: ResolveState): Boolean {
|
||||
assert(result == null)
|
||||
result = result(element, state)
|
||||
return result == null
|
||||
}
|
||||
|
||||
abstract fun result(element: PsiElement, state: ResolveState): GroovyResolveResult?
|
||||
}
|
||||
+8
-15
@@ -1,34 +1,27 @@
|
||||
// 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-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.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.resolve.processors
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.ResolveState
|
||||
import com.intellij.psi.scope.ElementClassHint
|
||||
import com.intellij.psi.scope.NameHint
|
||||
import com.intellij.psi.scope.ProcessorWithHints
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ElementGroovyResult
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GrResolverProcessor
|
||||
|
||||
class LocalVariableProcessor(name: String) : ProcessorWithHints(), GrResolverProcessor<GroovyResolveResult> {
|
||||
class LocalVariableProcessor(name: String) : FindFirstProcessor(name) {
|
||||
|
||||
init {
|
||||
hint(NameHint.KEY, NameHint { name })
|
||||
hint(ElementClassHint.KEY, ElementClassHint { false })
|
||||
hint(GroovyResolveKind.HINT_KEY, GroovyResolveKind.Hint { it === GroovyResolveKind.VARIABLE })
|
||||
hint(GroovyResolveKind.HINT_KEY, GroovyResolveKind.Hint { it == GroovyResolveKind.VARIABLE })
|
||||
}
|
||||
|
||||
private var resolveResult: GroovyResolveResult? = null
|
||||
|
||||
override val results: List<GroovyResolveResult> get() = resolveResult?.let { listOf(it) } ?: emptyList()
|
||||
|
||||
override fun execute(element: PsiElement, state: ResolveState): Boolean {
|
||||
if (element !is GrVariable || element is GrField) return true
|
||||
override fun result(element: PsiElement, state: ResolveState): GroovyResolveResult? {
|
||||
if (element !is GrVariable || element is GrField) return null
|
||||
assert(element !is GrBindingVariable)
|
||||
resolveResult = ElementGroovyResult(element)
|
||||
return false
|
||||
return ElementGroovyResult(element)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user