diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java index b092bf69ef40..46ab00ea2657 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java @@ -1,4 +1,6 @@ -// 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-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. + */ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path; @@ -19,6 +21,8 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpre import org.jetbrains.plugins.groovy.lang.psi.util.GroovyIndexPropertyUtil; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyLValueUtil; +import static org.jetbrains.plugins.groovy.lang.resolve.ReferencesKt.referenceArray; + /** * @author ilyas */ @@ -32,22 +36,9 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp () -> GroovyLValueUtil.isLValue(this) ? new GrIndexPropertyReference(this, false) : null ); - private final NotNullLazyValue myReferences = AtomicNotNullLazyValue.createValue(() -> { - GroovyPolyVariantReference lValueReference = getLValueReference(); - GroovyPolyVariantReference rValueReference = getRValueReference(); - if (lValueReference == null && rValueReference == null) { - return GroovyPolyVariantReference.EMPTY_ARRAY; - } - else if (lValueReference == null) { - return new GroovyPolyVariantReference[]{rValueReference}; - } - else if (rValueReference == null) { - return new GroovyPolyVariantReference[]{lValueReference}; - } - else { - return new GroovyPolyVariantReference[]{rValueReference, lValueReference}; - } - }); + private final NotNullLazyValue myReferences = AtomicNotNullLazyValue.createValue( + () -> referenceArray(getLValueReference(), getRValueReference()) + ); @Nullable @Override diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references.kt index e22aeb09d2ea..65a8653114f1 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references.kt @@ -1,9 +1,31 @@ -// 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-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. + */ package org.jetbrains.plugins.groovy.lang.resolve import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement +import org.jetbrains.plugins.groovy.lang.psi.api.GroovyPolyVariantReference + +fun referenceArray(left: GroovyPolyVariantReference?, right: GroovyPolyVariantReference?): Array { + return if (left == null) { + if (right == null) { + GroovyPolyVariantReference.EMPTY_ARRAY + } + else { + arrayOf(right) + } + } + else { + if (right == null) { + arrayOf(left) + } + else { + arrayOf(right, left) + } + } +} fun GrReferenceElement<*>.resolveClassFqn(): PsiClass? { val fqn = qualifiedReferenceName ?: return null