Commit 0e576f35 authored by Daniil Ovchinnikov's avatar Daniil Ovchinnikov
Browse files

[groovy] add resolve kind assertions

parent 70379901
Showing with 33 additions and 21 deletions
+33 -21
...@@ -33,6 +33,8 @@ val log: Logger = logger(::log) ...@@ -33,6 +33,8 @@ val log: Logger = logger(::log)
@JvmField @JvmField
val NON_CODE: Key<Boolean?> = Key.create("groovy.process.non.code.members") val NON_CODE: Key<Boolean?> = Key.create("groovy.process.non.code.members")
val sorryCannotKnowElementKind: Key<Boolean> = Key.create("groovy.skip.kind.check.please")
fun initialState(processNonCodeMembers: Boolean): ResolveState = ResolveState.initial().put(NON_CODE, processNonCodeMembers) fun initialState(processNonCodeMembers: Boolean): ResolveState = ResolveState.initial().put(NON_CODE, processNonCodeMembers)
fun ResolveState.processNonCodeMembers(): Boolean = get(NON_CODE).let { it == null || it } fun ResolveState.processNonCodeMembers(): Boolean = get(NON_CODE).let { it == null || it }
......
...@@ -11,6 +11,7 @@ import com.intellij.util.containers.MostlySingularMultiMap ...@@ -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.AnnotationHint
import org.jetbrains.plugins.groovy.lang.resolve.getName import org.jetbrains.plugins.groovy.lang.resolve.getName
import org.jetbrains.plugins.groovy.lang.resolve.imports.importedNameKey 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) private data class ElementWithState(val element: PsiElement, val state: ResolveState)
...@@ -46,10 +47,16 @@ class FileCacheBuilderProcessor(private val annotationResolve: Boolean) : PsiSco ...@@ -46,10 +47,16 @@ class FileCacheBuilderProcessor(private val annotationResolve: Boolean) : PsiSco
private class FileDeclarationsCache(private val declarations: MostlySingularMultiMap<String, ElementWithState>) : DeclarationHolder { private class FileDeclarationsCache(private val declarations: MostlySingularMultiMap<String, ElementWithState>) : DeclarationHolder {
override fun processDeclarations(processor: PsiScopeProcessor, state: ResolveState, place: PsiElement): Boolean { override fun processDeclarations(processor: PsiScopeProcessor, state: ResolveState, place: PsiElement): Boolean {
val newState = state.put(sorryCannotKnowElementKind, true)
val declarationProcessor = { (element, cachedState): ElementWithState -> val declarationProcessor = { (element, cachedState): ElementWithState ->
processor.execute(element, state.putAll(cachedState)) processor.execute(element, newState.putAll(cachedState))
} }
val name = processor.getName(state) 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)
}
} }
} }
...@@ -12,6 +12,7 @@ import org.jetbrains.plugins.groovy.lang.psi.util.elementInfo ...@@ -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.BaseGroovyResolveResult
import org.jetbrains.plugins.groovy.lang.resolve.getName import org.jetbrains.plugins.groovy.lang.resolve.getName
import org.jetbrains.plugins.groovy.lang.resolve.getResolveKind import org.jetbrains.plugins.groovy.lang.resolve.getResolveKind
import org.jetbrains.plugins.groovy.lang.resolve.sorryCannotKnowElementKind
open class KindsResolverProcessor( open class KindsResolverProcessor(
protected val name: String, protected val name: String,
...@@ -41,9 +42,20 @@ open class KindsResolverProcessor( ...@@ -41,9 +42,20 @@ open class KindsResolverProcessor(
val elementName = getName(state, element) val elementName = getName(state, element)
if (name != elementName) return true if (name != elementName) return true
val kind = getResolveKind(element) ?: return true val kind = requireNotNull(getResolveKind(element)) {
if (kind !in kinds) { "Unknown kind. ${elementInfo(element)}"
return true }
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) { if (kind in candidates) {
......
...@@ -21,6 +21,7 @@ import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil ...@@ -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_KEY
import org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DELEGATES_TO_STRATEGY_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.delegatesTo.getContainingCall
import org.jetbrains.plugins.groovy.lang.resolve.shouldProcessMethods
import org.jetbrains.plugins.groovy.lang.resolve.wrapClassType import org.jetbrains.plugins.groovy.lang.resolve.wrapClassType
class LogbackDelegateMemberContributor : NonCodeMembersContributor() { class LogbackDelegateMemberContributor : NonCodeMembersContributor() {
...@@ -28,6 +29,9 @@ class LogbackDelegateMemberContributor : NonCodeMembersContributor() { ...@@ -28,6 +29,9 @@ class LogbackDelegateMemberContributor : NonCodeMembersContributor() {
override fun getParentClassName(): String = componentDelegateFqn override fun getParentClassName(): String = componentDelegateFqn
override fun processDynamicElements(qualifierType: PsiType, processor: PsiScopeProcessor, place: PsiElement, state: ResolveState) { override fun processDynamicElements(qualifierType: PsiType, processor: PsiScopeProcessor, place: PsiElement, state: ResolveState) {
if (!processor.shouldProcessMethods()) {
return
}
val name = processor.getHint(NameHint.KEY)?.getName(state) val name = processor.getHint(NameHint.KEY)?.getName(state)
val componentClass = getComponentClass(place) ?: return val componentClass = getComponentClass(place) ?: return
val componentProcessor = ComponentProcessor(processor, place, name) val componentProcessor = ComponentProcessor(processor, place, name)
......
/* // 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.
* 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.
*/
package org.jetbrains.plugins.groovy.gant; package org.jetbrains.plugins.groovy.gant;
import com.intellij.psi.*; import com.intellij.psi.*;
...@@ -32,6 +18,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; ...@@ -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.psi.util.GroovyCommonClassNames;
import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor; import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor;
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtilKt;
import org.jetbrains.plugins.groovy.runner.GroovyScriptUtil; import org.jetbrains.plugins.groovy.runner.GroovyScriptUtil;
/** /**
...@@ -95,7 +82,7 @@ public class GantMemberContributor extends NonCodeMembersContributor { ...@@ -95,7 +82,7 @@ public class GantMemberContributor extends NonCodeMembersContributor {
} }
} }
if (!antTasksProcessed) { if (!antTasksProcessed && ResolveUtilKt.shouldProcessMethods(processor)) {
processAntTasks(processor, place, state); processAntTasks(processor, place, state);
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment