Commit 2c639d02 authored by Daniil Ovchinnikov's avatar Daniil Ovchinnikov
Browse files

[groovy] delay computation of receiver type as long as possible

parent 3d5ff3e8
Branches unavailable Tags unavailable
No related merge requests found
Showing with 29 additions and 8 deletions
+29 -8
......@@ -11,6 +11,8 @@ import com.intellij.psi.scope.NameHint;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
import kotlin.Lazy;
import kotlin.LazyKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
......@@ -83,14 +85,15 @@ public abstract class GroovyResolverProcessor implements PsiScopeProcessor, Elem
if (!isPropertyResolve() || !isPropertyName(myName)) {
return Collections.emptyList();
}
final Lazy<PsiType> receiverType = LazyKt.lazy(() -> getTopLevelQualifierType());
if (myIsLValue) {
return Collections.singletonList(
new PropertyProcessor(getTopLevelQualifierType(), myName, PropertyKind.SETTER, () -> myArgumentTypes.getValue(), myRef)
new PropertyProcessor(receiverType, myName, PropertyKind.SETTER, () -> myArgumentTypes.getValue(), myRef)
);
}
return ContainerUtil.newArrayList(
new PropertyProcessor(getTopLevelQualifierType(), myName, PropertyKind.GETTER, () -> PsiType.EMPTY_ARRAY, myRef),
new PropertyProcessor(getTopLevelQualifierType(), myName, PropertyKind.BOOLEAN_GETTER, () -> PsiType.EMPTY_ARRAY, myRef)
new PropertyProcessor(receiverType, myName, PropertyKind.GETTER, () -> PsiType.EMPTY_ARRAY, myRef),
new PropertyProcessor(receiverType, myName, PropertyKind.BOOLEAN_GETTER, () -> PsiType.EMPTY_ARRAY, myRef)
);
}
......
......@@ -14,13 +14,21 @@ import org.jetbrains.plugins.groovy.lang.resolve.PropertyResolveResult
import org.jetbrains.plugins.groovy.lang.resolve.imports.importedNameKey
class PropertyProcessor(
private val receiverType: PsiType?,
private val receiverType: Lazy<PsiType?>,
propertyName: String,
private val propertyKind: PropertyKind,
argumentTypes: () -> Array<PsiType?>?,
private val place: PsiElement
) : ProcessorWithCommonHints(), GrResolverProcessor<GroovyResolveResult> {
constructor(
receiverType: PsiType?,
propertyName: String,
propertyKind: PropertyKind,
argumentTypes: () -> Array<PsiType?>?,
place: PsiElement
) : this(lazyOf(receiverType), propertyName, propertyKind, argumentTypes, place)
private val accessorName = propertyKind.getAccessorName(propertyName)
private val argumentTypes by lazy(LazyThreadSafetyMode.NONE, argumentTypes)
......
// 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.
package org.jetbrains.plugins.groovy.lang.resolve.processors;
import com.intellij.openapi.diagnostic.Logger;
......@@ -10,6 +10,8 @@ import com.intellij.psi.PsiClassType.ClassResolveResult;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiTypesUtil;
import kotlin.Lazy;
import kotlin.LazyKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils;
......@@ -51,7 +53,7 @@ public class SubstitutorComputer {
protected final PsiElement myPlace;
private final PsiType myThisType;
private final Lazy<PsiType> myThisType;
@Nullable
private final PsiType[] myArgumentTypes;
@Nullable
......@@ -60,7 +62,15 @@ public class SubstitutorComputer {
private final NotNullLazyValue<Collection<PsiElement>> myExitPoints;
private final PsiResolveHelper myHelper;
public SubstitutorComputer(PsiType thisType,
public SubstitutorComputer(@Nullable PsiType thisType,
@Nullable PsiType[] argumentTypes,
@Nullable PsiType[] typeArguments,
PsiElement place,
PsiElement placeToInferContext) {
this(LazyKt.lazyOf(thisType), argumentTypes, typeArguments, place, placeToInferContext);
}
public SubstitutorComputer(@NotNull Lazy<PsiType> thisType,
@Nullable PsiType[] argumentTypes,
@Nullable PsiType[] typeArguments,
PsiElement place,
......@@ -138,7 +148,7 @@ public class SubstitutorComputer {
newArgTypes[0] = ((GrExpression)resolveContext).getType();
}
else {
newArgTypes[0] = myThisType;
newArgTypes[0] = myThisType.getValue();
}
System.arraycopy(argTypes, 0, newArgTypes, 1, argTypes.length);
argTypes = newArgTypes;
......
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