/*
 * Copyright 2000-2017 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.debugger.streams.psi;

import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;

/**
 * @author Vitaliy.Bibaev
 */
public class StreamApiUtil {
  private StreamApiUtil() {
  }

  public static boolean isStreamCall(@NotNull PsiMethodCallExpression expression) {
    return isIntermediateStreamCall(expression) || isProducerStreamCall(expression) || isTerminationStreamCall(expression);
  }

  public static boolean isTerminationStreamCall(@NotNull PsiMethodCallExpression expression) {
    return checkStreamCall(expression, true, false);
  }

  public static boolean isProducerStreamCall(@NotNull PsiMethodCallExpression expression) {
    return checkStreamCall(expression, false, true);
  }

  public static boolean isIntermediateStreamCall(@NotNull PsiMethodCallExpression expression) {
    return checkStreamCall(expression, true, true);
  }

  private static boolean checkStreamCall(@NotNull PsiMethodCallExpression expression,
                                         boolean mustParentBeStream,
                                         boolean mustResultBeStream) {
    final PsiMethod method = expression.resolveMethod();
    if (method != null && mustResultBeStream == isStreamType(method.getReturnType())) {
      final PsiElement methodParent = method.getParent();
      if (methodParent instanceof PsiClass) {
        return Arrays.stream(((PsiClass)methodParent).getSuperTypes()).anyMatch(x -> mustParentBeStream == isStreamType(x));
      }
    }

    return false;
  }

  private static boolean isStreamType(@Nullable PsiType type) {
    return InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_STREAM_BASE_STREAM);
  }

  @Nullable
  public static PsiType resolveReturnType(@NotNull PsiMethodCallExpression expression) {
    final PsiMethod method = expression.resolveMethod();
    return method == null ? null : method.getReturnType();
  }
}

@@ -1988,22 +1988,21 @@
 t method
-Parent
+Class
  = metho
@@ -2032,22 +2032,21 @@
  (method
-Parent
+Class
  instanc
@@ -2080,22 +2080,20 @@
 urn 
-Arrays.s
+isS
 tream
-(
+Type
 ((Ps
@@ -2109,118 +2109,215 @@
 thod
-Parent).getSuperTypes()).anyMatch(x -%3E mustParentBeStream == isStreamType(x));%0A      %7D%0A    %7D%0A%0A    return false
+Class);%0A      %7D%0A    %7D%0A%0A    return false;%0A  %7D%0A%0A  private static boolean isStreamType(@Nullable PsiType psiType) %7B%0A    return InheritanceUtil.isInheritor(psiType, CommonClassNames.JAVA_UTIL_STREAM_BASE_STREAM)
 ;%0A  
@@ -2374,17 +2374,22 @@
  Psi
-Type type
+Class psiClass
 ) %7B%0A
@@ -2431,12 +2431,16 @@
 tor(
-type
+psiClass
 , Co

Fix bug when type of the parent call wrong