mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] pass arguments into AccessorProcessor instead of types
This commit is contained in:
+1
-3
@@ -63,9 +63,7 @@ class GrRValueExpressionReference(ref: GrReferenceExpressionImpl) : GrReferenceE
|
||||
class GrLValueExpressionReference(ref: GrReferenceExpressionImpl, private val argument: Argument?) : GrReferenceExpressionReference(ref) {
|
||||
|
||||
override fun buildProcessor(name: String, place: PsiElement, kinds: Set<GroovyResolveKind>): GrResolverProcessor<*> {
|
||||
return GroovyLValueProcessor(name, place, kinds) {
|
||||
if (argument == null) null else arrayOf(argument.type)
|
||||
}
|
||||
return GroovyLValueProcessor(name, place, kinds, if (argument == null) null else listOf(argument))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAc
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.api.Argument;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.processors.AccessorProcessor;
|
||||
|
||||
import java.beans.Introspector;
|
||||
@@ -80,7 +81,7 @@ public class GroovyPropertyUtils {
|
||||
final GrExpression fromText = GroovyPsiElementFactory.getInstance(context.getProject()).createExpressionFromText("this", context);
|
||||
return findPropertySetter(fromText.getType(), propertyName, context);
|
||||
}
|
||||
final AccessorProcessor processor = new AccessorProcessor(propertyName, PropertyKind.SETTER, () -> null, context);
|
||||
final AccessorProcessor processor = new AccessorProcessor(propertyName, PropertyKind.SETTER, (List<? extends Argument>)null, context);
|
||||
ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), context);
|
||||
return PsiImplUtil.extractUniqueElement(processor.getResultsArray());
|
||||
}
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ package org.jetbrains.plugins.groovy.lang.resolve
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isApplicable
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.api.Argument
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.processors.SubstitutorComputer
|
||||
|
||||
@@ -10,7 +11,7 @@ class AccessorResolveResult(
|
||||
element: PsiMethod,
|
||||
place: PsiElement,
|
||||
state: ResolveState,
|
||||
argumentTypes: Array<PsiType?>?
|
||||
arguments: List<Argument>?
|
||||
) : BaseGroovyResolveResult<PsiMethod>(element, place, state) {
|
||||
|
||||
private val receiverType = state[ClassHint.THIS_TYPE]
|
||||
@@ -23,6 +24,7 @@ class AccessorResolveResult(
|
||||
override fun getSubstitutor(): PsiSubstitutor = fullSubstitutor
|
||||
|
||||
private val applicability by lazy {
|
||||
val argumentTypes = arguments?.map { it.type }?.toTypedArray()
|
||||
isApplicable(argumentTypes, element, substitutor, place, true)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -719,7 +719,7 @@ public class ResolveUtil {
|
||||
|
||||
//search for getters
|
||||
for (PropertyKind kind : Arrays.asList(PropertyKind.GETTER, PropertyKind.BOOLEAN_GETTER)) {
|
||||
AccessorProcessor propertyProcessor = new AccessorProcessor(methodName, kind, () -> PsiType.EMPTY_ARRAY, place);
|
||||
AccessorProcessor propertyProcessor = new AccessorProcessor(methodName, kind, Collections.emptyList(), place);
|
||||
processAllDeclarations(thisType, propertyProcessor, state, place);
|
||||
final List<GroovyResolveResult> candidates = propertyProcessor.getResults(); //can be only one candidate
|
||||
final List<GroovyResolveResult> applicable = new ArrayList<>();
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// 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.lang.resolve.api
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
|
||||
class JustTypeArgument(override val type: PsiType?) : Argument
|
||||
+12
-3
@@ -13,17 +13,26 @@ import org.jetbrains.plugins.groovy.lang.psi.util.checkKind
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.getAccessorName
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.AccessorResolveResult
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GrResolverProcessor
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.api.Argument
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.api.JustTypeArgument
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.imports.importedNameKey
|
||||
|
||||
class AccessorProcessor(
|
||||
propertyName: String,
|
||||
private val propertyKind: PropertyKind,
|
||||
argumentTypes: () -> Array<PsiType?>?,
|
||||
private val arguments: List<Argument>?,
|
||||
private val place: PsiElement
|
||||
) : ProcessorWithCommonHints(), GrResolverProcessor<GroovyResolveResult> {
|
||||
|
||||
@Deprecated("don't use this constructor")
|
||||
constructor(
|
||||
propertyName: String,
|
||||
propertyKind: PropertyKind,
|
||||
arguments: () -> Array<PsiType?>?,
|
||||
place: PsiElement
|
||||
) : this(propertyName, propertyKind, arguments()?.map { JustTypeArgument(it) }, place)
|
||||
|
||||
private val accessorName = propertyKind.getAccessorName(propertyName)
|
||||
private val argumentTypes by lazy(LazyThreadSafetyMode.NONE, argumentTypes)
|
||||
|
||||
init {
|
||||
nameHint(accessorName)
|
||||
@@ -41,7 +50,7 @@ class AccessorProcessor(
|
||||
element = element,
|
||||
place = place,
|
||||
state = state,
|
||||
argumentTypes = argumentTypes
|
||||
arguments = arguments
|
||||
)
|
||||
|
||||
return true
|
||||
|
||||
+3
-3
@@ -3,19 +3,19 @@ package org.jetbrains.plugins.groovy.lang.resolve.processors
|
||||
|
||||
import com.intellij.lang.java.beans.PropertyKind
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.isPropertyName
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GrResolverProcessor
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.api.Argument
|
||||
|
||||
class GroovyLValueProcessor(
|
||||
name: String,
|
||||
place: PsiElement,
|
||||
kinds: Set<GroovyResolveKind>,
|
||||
argumentTypes: () -> Array<PsiType?>?
|
||||
arguments: List<Argument>?
|
||||
) : AccessorAwareResolverProcessor(name, place, kinds) {
|
||||
|
||||
override val accessorProcessors: Collection<GrResolverProcessor<*>> = if (name.isPropertyName()) {
|
||||
listOf(AccessorProcessor(name, PropertyKind.SETTER, argumentTypes, place))
|
||||
listOf(AccessorProcessor(name, PropertyKind.SETTER, arguments, place))
|
||||
}
|
||||
else {
|
||||
emptyList()
|
||||
|
||||
+2
-3
@@ -3,7 +3,6 @@ package org.jetbrains.plugins.groovy.lang.resolve.processors
|
||||
|
||||
import com.intellij.lang.java.beans.PropertyKind
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.isPropertyName
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GrResolverProcessor
|
||||
|
||||
@@ -15,8 +14,8 @@ class GroovyRValueProcessor(
|
||||
|
||||
override val accessorProcessors: Collection<GrResolverProcessor<*>> = if (name.isPropertyName())
|
||||
listOf(
|
||||
AccessorProcessor(name, PropertyKind.GETTER, { PsiType.EMPTY_ARRAY }, place),
|
||||
AccessorProcessor(name, PropertyKind.BOOLEAN_GETTER, { PsiType.EMPTY_ARRAY }, place)
|
||||
AccessorProcessor(name, PropertyKind.GETTER, emptyList(), place),
|
||||
AccessorProcessor(name, PropertyKind.BOOLEAN_GETTER, emptyList(), place)
|
||||
)
|
||||
else {
|
||||
emptyList()
|
||||
|
||||
+2
-2
@@ -84,8 +84,8 @@ public abstract class GroovyResolverProcessor implements PsiScopeProcessor, Elem
|
||||
);
|
||||
}
|
||||
return ContainerUtil.newArrayList(
|
||||
new AccessorProcessor(myName, PropertyKind.GETTER, () -> PsiType.EMPTY_ARRAY, myRef),
|
||||
new AccessorProcessor(myName, PropertyKind.BOOLEAN_GETTER, () -> PsiType.EMPTY_ARRAY, myRef)
|
||||
new AccessorProcessor(myName, PropertyKind.GETTER, Collections.emptyList(), myRef),
|
||||
new AccessorProcessor(myName, PropertyKind.BOOLEAN_GETTER, Collections.emptyList(), myRef)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user