@Override
 public void visitListOrMap(GrListOrMap listOrMap) {
   if (listOrMap.isMap()) return;
   final TypeConstraint[] constraints = calculateTypeConstraints(listOrMap);
   List<PsiType> result = new ArrayList<PsiType>(constraints.length);
   for (TypeConstraint constraint : constraints) {
     if (constraint instanceof SubtypeConstraint) {
       final PsiType type = constraint.getType();
       final PsiType iterable =
           com.intellij.psi.util.PsiUtil.extractIterableTypeParameter(type, true);
       if (iterable != null) {
         result.add(iterable);
       }
     }
   }
   if (result.size() == 0) {
     myResult = TypeConstraint.EMPTY_ARRAY;
   } else {
     myResult = new TypeConstraint[result.size()];
     for (int i = 0; i < result.size(); i++) {
       final PsiType type = result.get(i);
       if (type != null) {
         myResult[i] = SubtypeConstraint.create(type);
       }
     }
   }
 }
Exemplo n.º 2
0
  @Nullable
  public static PsiType normalizeWildcardTypeByPosition(
      @NotNull PsiType type, @NotNull GrExpression expression) {
    GrExpression toplevel = expression;
    while (toplevel.getParent() instanceof GrIndexProperty
        && ((GrIndexProperty) toplevel.getParent()).getInvokedExpression() == toplevel) {
      toplevel = (GrExpression) toplevel.getParent();
    }

    final PsiType normalized = doNormalizeWildcardByPosition(type, expression, toplevel);
    if (normalized instanceof PsiClassType && !PsiUtil.isAccessedForWriting(toplevel)) {
      return com.intellij.psi.util.PsiUtil.captureToplevelWildcards(normalized, expression);
    }

    return normalized;
  }