[groovy] pass import via resolve state into processor

This commit is contained in:
Daniil Ovchinnikov
2018-03-07 19:51:14 +03:00
parent 222cb0d70e
commit 8308d4cc10
2 changed files with 7 additions and 6 deletions
@@ -1,6 +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("UseExpressionBody")
package org.jetbrains.plugins.groovy.lang.resolve.imports.impl
@@ -13,6 +11,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatem
import org.jetbrains.plugins.groovy.lang.resolve.imports.GroovyFileImports
import org.jetbrains.plugins.groovy.lang.resolve.imports.GroovyImport
import org.jetbrains.plugins.groovy.lang.resolve.imports.defaultImports
import org.jetbrains.plugins.groovy.lang.resolve.imports.importKey
import org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint
import org.jetbrains.plugins.groovy.util.flatten
@@ -36,7 +35,8 @@ internal class GroovyFileImportsImpl(
override val allNamedImports = flatten(getImports(ImportKind.Regular), getImports(ImportKind.Static))
private val allStarImports = flatten(getImports(ImportKind.Star), getImports(ImportKind.StaticStar))
private fun addStatement(state: ResolveState, import: GroovyImport): ResolveState {
private fun ResolveState.putImport(import: GroovyImport): ResolveState {
val state = put(importKey, import)
val statement = importToStatement[import] ?: return state
return state.put(ClassHint.RESOLVE_CONTEXT, statement)
}
@@ -44,7 +44,7 @@ internal class GroovyFileImportsImpl(
@Suppress("LoopToCallChain")
private fun Collection<GroovyImport>.doProcess(processor: PsiScopeProcessor, state: ResolveState, place: PsiElement): Boolean {
for (import in this) {
if (!import.processDeclarations(processor, addStatement(state, import), place, file)) return false
if (!import.processDeclarations(processor, state.putImport(import), place, file)) return false
}
return true
}
@@ -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:JvmName("GroovyImports")
package org.jetbrains.plugins.groovy.lang.resolve.imports
@@ -21,6 +21,7 @@ internal val defaultImports = defaultStarImports + defaultRegularImports
internal val defaultRegularImportsSet = THashSet(defaultRegularImports, RegularImportHashingStrategy)
internal val defaultStarImportsSet = THashSet(defaultStarImports, StarImportHashingStrategy)
val importKey = Key.create<GroovyImport>("groovy.imported.via")
val importedNameKey = Key.create<String>("groovy.imported.via.name")
fun GroovyFile.getImports(): GroovyFileImports {