From 8308d4cc108f528eb39c3ac775b7bd4178f8d385 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 7 Mar 2018 18:56:52 +0300 Subject: [PATCH] [groovy] pass import via resolve state into processor --- .../lang/resolve/imports/impl/GroovyFileImportsImpl.kt | 10 +++++----- .../plugins/groovy/lang/resolve/imports/imports.kt | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/impl/GroovyFileImportsImpl.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/impl/GroovyFileImportsImpl.kt index b5548c21fce1..5d7c6ed3083d 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/impl/GroovyFileImportsImpl.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/impl/GroovyFileImportsImpl.kt @@ -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.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 } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/imports.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/imports.kt index c50c2edf9f18..da7fe947eacc 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/imports.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/imports/imports.kt @@ -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("groovy.imported.via") val importedNameKey = Key.create("groovy.imported.via.name") fun GroovyFile.getImports(): GroovyFileImports {