mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] cache closure/lambda type in current inference context
GitOrigin-RevId: 4f2826ac1f094d5ba74c1ed2156007b0ac21a003
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3b06964315
commit
fcb94c0f3a
+4
-1
@@ -15,6 +15,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.GrLambdaBody
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GrLambdaExpression
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList
|
||||
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterListImpl
|
||||
|
||||
@@ -46,7 +47,9 @@ class GrLambdaExpressionImpl(node: ASTNode) : GrExpressionImpl(node), GrLambdaEx
|
||||
|
||||
override fun getReturnType(): PsiType? = body?.returnType
|
||||
|
||||
override fun getType(): PsiType? = GrClosureType.create(this, true)
|
||||
override fun getType(): PsiType? = TypeInferenceHelper.getCurrentContext().getExpressionType(this) {
|
||||
GrClosureType.create(it, true)
|
||||
}
|
||||
|
||||
override fun toString(): String = "Lambda expression"
|
||||
}
|
||||
|
||||
+8
-7
@@ -20,7 +20,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
@@ -30,10 +29,10 @@ import org.jetbrains.plugins.groovy.lang.resolve.MethodTypeInferencer;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.intellij.psi.util.CachedValueProvider.Result.create;
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.impl.FunctionalExpressionsKt.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType.create;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
@@ -135,7 +134,7 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
|
||||
|
||||
@Override
|
||||
public PsiType getType() {
|
||||
return GrClosureType.create(this, true);
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, it -> create(it, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,13 +163,15 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
|
||||
return PsiImplUtil.replaceExpression(this, newExpr, removeUnnecessaryParentheses);
|
||||
}
|
||||
|
||||
private static final Function<GrClosableBlock, PsiType> ourTypesCalculator =
|
||||
block -> GroovyPsiManager.inferType(block, new MethodTypeInferencer(block));
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiType getReturnType() {
|
||||
return TypeInferenceHelper.getCurrentContext().getExpressionType(this, ourTypesCalculator);
|
||||
return TypeInferenceHelper.getCurrentContext().getCachedValue(this, this::doGetReturnType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiType doGetReturnType() {
|
||||
return GroovyPsiManager.inferType(this, new MethodTypeInferencer(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user