IDEA-193165 Groovy 2.5 @NamedParam support

This commit is contained in:
alexey.afanasiev
2018-06-19 11:40:02 +03:00
parent 9e62465324
commit 97639fb720
3 changed files with 42 additions and 4 deletions
@@ -10,7 +10,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
class ExpressionConstraint(val expression: GrExpression, val leftType: PsiType) : ConstraintFormula {
class ExpressionConstraint(val expression: GrExpression, val leftType: PsiType?) : ConstraintFormula {
override fun reduce(session: InferenceSession, constraints: MutableList<ConstraintFormula>): Boolean {
when (expression) {
is GrMethodCall -> {
@@ -20,8 +20,8 @@ class ExpressionConstraint(val expression: GrExpression, val leftType: PsiType)
else -> return true
}
}
is GrClosableBlock -> constraints.add(ClosureConstraint(expression, leftType))
else -> constraints.add(TypeConstraint(leftType, expression.type, expression))
is GrClosableBlock -> if (leftType != null) constraints.add(ClosureConstraint(expression, leftType))
else -> if (leftType != null) constraints.add(TypeConstraint(leftType, expression.type, expression))
}
return true
}
@@ -75,7 +75,7 @@ class GroovyInferenceSessionBuilder(val ref: GrReferenceExpression, val candidat
} else {
val session = GroovyInferenceSession(siteTypeParams, PsiSubstitutor.EMPTY, ref, skipClosureBlock)
val methodCall = ref.parent as? GrMethodCall ?: return session
session.addConstraint(ReferenceExpressionConstraint(getMostTopLevelCall(methodCall).invokedExpression as GrReferenceExpression, left))
session.addConstraint(ExpressionConstraint(getMostTopLevelCall(methodCall), left))
return session
}
}
@@ -432,6 +432,44 @@ class Cl {
}
}
'''
}
void 'test call without reference'() {
testHighlighting '''
class E {
E call() {
null
}
E bar() {null}
}
new E().bar()()
'''
}
//TODO: IDEA-194192
void '_test call without reference with generics'() {
testHighlighting '''
import groovy.transform.CompileStatic
class E {
def <K,V> Map<K, V> call(Map<K, V> m) {
m
}
E bar() {null}
}
static <K,V> Map<K, V> getMap() {
return new HashMap<K,V>()
}
@CompileStatic
def com() {
Map<String, Integer> correct = new E()(getMap().withDefault({ 0 }))
}
'''
}
}