diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.kt index 8a029993bbc5..147c9e9af0aa 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.kt @@ -33,6 +33,8 @@ val log: Logger = logger(::log) @JvmField val NON_CODE: Key = Key.create("groovy.process.non.code.members") +val sorryCannotKnowElementKind: Key = Key.create("groovy.skip.kind.check.please") + fun initialState(processNonCodeMembers: Boolean): ResolveState = ResolveState.initial().put(NON_CODE, processNonCodeMembers) fun ResolveState.processNonCodeMembers(): Boolean = get(NON_CODE).let { it == null || it } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/caches/fileCache.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/caches/fileCache.kt index c30fe2e7dfb5..861f2e8cd0fa 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/caches/fileCache.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/caches/fileCache.kt @@ -11,6 +11,7 @@ import com.intellij.util.containers.MostlySingularMultiMap import org.jetbrains.plugins.groovy.lang.resolve.AnnotationHint import org.jetbrains.plugins.groovy.lang.resolve.getName import org.jetbrains.plugins.groovy.lang.resolve.imports.importedNameKey +import org.jetbrains.plugins.groovy.lang.resolve.sorryCannotKnowElementKind private data class ElementWithState(val element: PsiElement, val state: ResolveState) @@ -46,10 +47,16 @@ class FileCacheBuilderProcessor(private val annotationResolve: Boolean) : PsiSco private class FileDeclarationsCache(private val declarations: MostlySingularMultiMap) : DeclarationHolder { override fun processDeclarations(processor: PsiScopeProcessor, state: ResolveState, place: PsiElement): Boolean { + val newState = state.put(sorryCannotKnowElementKind, true) val declarationProcessor = { (element, cachedState): ElementWithState -> - processor.execute(element, state.putAll(cachedState)) + processor.execute(element, newState.putAll(cachedState)) } val name = processor.getName(state) - return if (name == null) declarations.processAllValues(declarationProcessor) else declarations.processForKey(name, declarationProcessor) + return if (name == null) { + declarations.processAllValues(declarationProcessor) + } + else { + declarations.processForKey(name, declarationProcessor) + } } } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/KindsResolverProcessor.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/KindsResolverProcessor.kt index f1032f21c38c..09422dbfca9d 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/KindsResolverProcessor.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/KindsResolverProcessor.kt @@ -12,6 +12,7 @@ import org.jetbrains.plugins.groovy.lang.psi.util.elementInfo import org.jetbrains.plugins.groovy.lang.resolve.BaseGroovyResolveResult import org.jetbrains.plugins.groovy.lang.resolve.getName import org.jetbrains.plugins.groovy.lang.resolve.getResolveKind +import org.jetbrains.plugins.groovy.lang.resolve.sorryCannotKnowElementKind open class KindsResolverProcessor( protected val name: String, @@ -41,9 +42,20 @@ open class KindsResolverProcessor( val elementName = getName(state, element) if (name != elementName) return true - val kind = getResolveKind(element) ?: return true - if (kind !in kinds) { - return true + val kind = requireNotNull(getResolveKind(element)) { + "Unknown kind. ${elementInfo(element)}" + } + + if (state[sorryCannotKnowElementKind] == true) { + if (kind !in kinds) { + // return without exception + return true + } + } + else { + require(kind in kinds) { + "Unneeded kind. ${elementInfo(element)}" + } } if (kind in candidates) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackDelegateMemberContributor.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackDelegateMemberContributor.kt index 62ab715edf1a..58988ebbf12e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackDelegateMemberContributor.kt +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackDelegateMemberContributor.kt @@ -21,6 +21,7 @@ import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil import org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DELEGATES_TO_KEY import org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DELEGATES_TO_STRATEGY_KEY import org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.getContainingCall +import org.jetbrains.plugins.groovy.lang.resolve.shouldProcessMethods import org.jetbrains.plugins.groovy.lang.resolve.wrapClassType class LogbackDelegateMemberContributor : NonCodeMembersContributor() { @@ -28,6 +29,9 @@ class LogbackDelegateMemberContributor : NonCodeMembersContributor() { override fun getParentClassName(): String = componentDelegateFqn override fun processDynamicElements(qualifierType: PsiType, processor: PsiScopeProcessor, place: PsiElement, state: ResolveState) { + if (!processor.shouldProcessMethods()) { + return + } val name = processor.getHint(NameHint.KEY)?.getName(state) val componentClass = getComponentClass(place) ?: return val componentProcessor = ComponentProcessor(processor, place, name) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantMemberContributor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantMemberContributor.java index 4016deda1811..dce1e8be54f3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantMemberContributor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantMemberContributor.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// 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. package org.jetbrains.plugins.groovy.gant; import com.intellij.psi.*; @@ -32,6 +18,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames; import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor; import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; +import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtilKt; import org.jetbrains.plugins.groovy.runner.GroovyScriptUtil; /** @@ -95,7 +82,7 @@ public class GantMemberContributor extends NonCodeMembersContributor { } } - if (!antTasksProcessed) { + if (!antTasksProcessed && ResolveUtilKt.shouldProcessMethods(processor)) { processAntTasks(processor, place, state); } }