mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] inference: add and use GrConstraintFormula as base class for groovy constraints
This commit is contained in:
+3
-7
@@ -2,10 +2,8 @@
|
||||
package org.jetbrains.plugins.groovy.lang.resolve.processors.inference
|
||||
|
||||
import com.intellij.psi.PsiClassType
|
||||
import com.intellij.psi.PsiSubstitutor
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil.getNonWildcardParameterization
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil.findCall
|
||||
@@ -14,10 +12,10 @@ import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames
|
||||
import org.jetbrains.plugins.groovy.lang.sam.findSingleAbstractMethod
|
||||
import org.jetbrains.plugins.groovy.lang.sam.isSamConversionAllowed
|
||||
|
||||
class ClosureConstraint(private val closure: GrClosableBlock, private val leftType: PsiType) : ConstraintFormula {
|
||||
class ClosureConstraint(private val closure: GrClosableBlock, private val leftType: PsiType) : GrConstraintFormula() {
|
||||
|
||||
override fun reduce(session: InferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
if ((session as GroovyInferenceSession).skipClosureBlock || session.closureSkipList.contains(findCall(closure))) {
|
||||
override fun reduce(session: GroovyInferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
if (session.skipClosureBlock || session.closureSkipList.contains(findCall(closure))) {
|
||||
//TODO:add explicit typed closure constraints
|
||||
}
|
||||
else {
|
||||
@@ -57,6 +55,4 @@ class ClosureConstraint(private val closure: GrClosableBlock, private val leftTy
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun apply(substitutor: PsiSubstitutor, cache: Boolean) {}
|
||||
}
|
||||
|
||||
+2
-6
@@ -1,18 +1,16 @@
|
||||
// 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.inference
|
||||
|
||||
import com.intellij.psi.PsiSubstitutor
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
|
||||
|
||||
class ExpressionConstraint(private val expression: GrExpression, private val leftType: PsiType?) : ConstraintFormula {
|
||||
class ExpressionConstraint(private val expression: GrExpression, private val leftType: PsiType?) : GrConstraintFormula() {
|
||||
|
||||
override fun reduce(session: InferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
override fun reduce(session: GroovyInferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
when (expression) {
|
||||
is GrMethodCall -> {
|
||||
val invokedExpression = expression.invokedExpression as? GrReferenceExpression ?: return true
|
||||
@@ -23,6 +21,4 @@ class ExpressionConstraint(private val expression: GrExpression, private val lef
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun apply(substitutor: PsiSubstitutor, cache: Boolean) {}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// 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.inference
|
||||
|
||||
import com.intellij.psi.PsiSubstitutor
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula
|
||||
|
||||
abstract class GrConstraintFormula : ConstraintFormula {
|
||||
|
||||
final override fun reduce(session: InferenceSession?, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
if (session !is GroovyInferenceSession) return true
|
||||
return reduce(session, constraints)
|
||||
}
|
||||
|
||||
abstract fun reduce(session: GroovyInferenceSession, constraints: MutableList<ConstraintFormula>): Boolean
|
||||
|
||||
override fun apply(substitutor: PsiSubstitutor, cache: Boolean) = Unit
|
||||
}
|
||||
+3
-7
@@ -1,14 +1,12 @@
|
||||
// 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.inference
|
||||
|
||||
import com.intellij.psi.PsiSubstitutor
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
|
||||
|
||||
class MethodCallConstraint(private val callRef: GrReferenceExpression, private val candidate: MethodCandidate) : ConstraintFormula {
|
||||
class MethodCallConstraint(private val callRef: GrReferenceExpression, private val candidate: MethodCandidate) : GrConstraintFormula() {
|
||||
|
||||
override fun reduce(session: InferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
override fun reduce(session: GroovyInferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
processArguments(constraints)
|
||||
return true
|
||||
}
|
||||
@@ -27,6 +25,4 @@ class MethodCallConstraint(private val callRef: GrReferenceExpression, private v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun apply(substitutor: PsiSubstitutor, cache: Boolean) {}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-7
@@ -1,19 +1,16 @@
|
||||
// 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.inference
|
||||
|
||||
import com.intellij.psi.PsiSubstitutor
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeCompatibilityConstraint
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyMethodResult
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil
|
||||
|
||||
class ReferenceExpressionConstraint(private val callRef: GrReferenceExpression, private val leftType: PsiType?) : ConstraintFormula {
|
||||
class ReferenceExpressionConstraint(private val callRef: GrReferenceExpression, private val leftType: PsiType?) : GrConstraintFormula() {
|
||||
|
||||
override fun reduce(session: InferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
if (session !is GroovyInferenceSession) return true
|
||||
override fun reduce(session: GroovyInferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
val resolved = callRef.advancedResolve()
|
||||
if (resolved !is GroovyMethodResult) return true
|
||||
resolved.candidate?.let {
|
||||
@@ -44,6 +41,4 @@ class ReferenceExpressionConstraint(private val callRef: GrReferenceExpression,
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun apply(substitutor: PsiSubstitutor, cache: Boolean) {}
|
||||
}
|
||||
|
||||
+2
-7
@@ -3,9 +3,7 @@ package org.jetbrains.plugins.groovy.lang.resolve.processors.inference
|
||||
|
||||
import com.intellij.psi.CommonClassNames
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiSubstitutor
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeCompatibilityConstraint
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrLiteralClassType
|
||||
@@ -13,10 +11,9 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil
|
||||
|
||||
class TypeConstraint(private val leftType: PsiType, private val rightType: PsiType?, private val context: PsiElement) : ConstraintFormula {
|
||||
class TypeConstraint(private val leftType: PsiType, private val rightType: PsiType?, private val context: PsiElement) : GrConstraintFormula() {
|
||||
|
||||
override fun reduce(session: InferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
if (session !is GroovyInferenceSession) return true
|
||||
override fun reduce(session: GroovyInferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
|
||||
var argType = rightType ?: PsiType.NULL
|
||||
if (argType is GrTupleType) {
|
||||
val rawWildcardType = TypesUtil.rawWildcard(argType, context)
|
||||
@@ -34,6 +31,4 @@ class TypeConstraint(private val leftType: PsiType, private val rightType: PsiTy
|
||||
constraints.add(TypeCompatibilityConstraint(t, s))
|
||||
return true
|
||||
}
|
||||
|
||||
override fun apply(substitutor: PsiSubstitutor, cache: Boolean) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user