From 97639fb72028203db561a8071fc0f39af1d00dc6 Mon Sep 17 00:00:00 2001 From: "alexey.afanasiev" Date: Tue, 19 Jun 2018 11:30:20 +0300 Subject: [PATCH] IDEA-193165 Groovy 2.5 @NamedParam support --- .../inference/ExpressionConstraint.kt | 6 +-- .../GroovyInferenceSessionBuilder.kt | 2 +- .../GrLatestHighlightingTest.groovy | 38 +++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/ExpressionConstraint.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/ExpressionConstraint.kt index 0c6bddc77bae..0060c7945deb 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/ExpressionConstraint.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/ExpressionConstraint.kt @@ -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): 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 } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/GroovyInferenceSessionBuilder.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/GroovyInferenceSessionBuilder.kt index 08c096db725c..ae26eb73ff9f 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/GroovyInferenceSessionBuilder.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/GroovyInferenceSessionBuilder.kt @@ -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 } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy index bf764dc6a8ec..78892ec65d08 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy @@ -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 Map call(Map m) { + m + } + E bar() {null} +} + +static Map getMap() { + return new HashMap() +} + +@CompileStatic +def com() { + Map correct = new E()(getMap().withDefault({ 0 })) +} ''' } }