mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] add resolve kind assertions
This commit is contained in:
@@ -33,6 +33,8 @@ val log: Logger = logger(::log)
|
||||
@JvmField
|
||||
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 ResolveState.processNonCodeMembers(): Boolean = get(NON_CODE).let { it == null || it }
|
||||
|
||||
+9
-2
@@ -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<String, ElementWithState>) : 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-3
@@ -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) {
|
||||
|
||||
+4
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user