// Copyright 2000-2019 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.typeEnhancers;

import com.intellij.psi.PsiArrayType;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;

import static org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isCompileStatic;

public class GrContainerConverter extends GrTypeConverter {

  @Nullable
  @Override
  public Boolean isConvertible(@NotNull PsiType lType, @NotNull PsiType rType, @NotNull GroovyPsiElement context) {
    if (isCompileStatic(context)) return null;
    if (lType instanceof PsiArrayType) {
      PsiType lComponentType = ((PsiArrayType)lType).getComponentType();
      PsiType rComponentType = ClosureParameterEnhancer.findTypeForIteration(rType, context);
      if (rComponentType != null && TypesUtil.isAssignable(lComponentType, rComponentType, context)) {
        return Boolean.TRUE;
      }
    }

    return null;
  }
}

@@ -415,16 +415,107 @@
 lement;%0A
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult;%0A
 import o
@@ -590,16 +590,16 @@
 esUtil;%0A
-
 %0Aimport 
@@ -768,23 +768,32 @@
  public 
-Boolean
+ConversionResult
  isConve
@@ -798,16 +798,18 @@
 vertible
+Ex
 (@NotNul
@@ -828,66 +828,224 @@
 ype,
- @NotNull PsiType rType, @NotNull GroovyPsiElement context
+%0A                                          @NotNull PsiType rType,%0A                                          @NotNull GroovyPsiElement context,%0A                                          @NotNull ApplicableTo position
 ) %7B%0A
@@ -1421,20 +1421,27 @@
 urn 
-Boolean.TRUE
+ConversionResult.OK
 ;%0A  

migrate last remaining GrContainerConverter