old guava inspection removed
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 28 Oct 2015 17:00:33 +0000 (20:00 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 28 Oct 2015 17:00:33 +0000 (20:00 +0300)
23 files changed:
java/java-impl/src/com/intellij/codeInspection/java18StreamApi/FluentIterableMethodTransformer.java [deleted file]
java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFluentIterableInspection.java [deleted file]
java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFluentIterableMethodConverters.java [deleted file]
java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFunctionAndPredicateConverter.java [deleted file]
java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaOptionalConverter.java [deleted file]
java/java-tests/testData/inspection/guava/base.java [deleted file]
java/java-tests/testData/inspection/guava/base_after.java [deleted file]
java/java-tests/testData/inspection/guava/insideLambda.java [deleted file]
java/java-tests/testData/inspection/guava/insideLambda_after.java [deleted file]
java/java-tests/testData/inspection/guava/localVariable.java [deleted file]
java/java-tests/testData/inspection/guava/localVariable_after.java [deleted file]
java/java-tests/testData/inspection/guava/nonSuitableMethodParameterType.java [deleted file]
java/java-tests/testData/inspection/guava/nonSuitableReturnType.java [deleted file]
java/java-tests/testData/inspection/guava/nonSuitableReturnType2.java [deleted file]
java/java-tests/testData/inspection/guava/stopMethods.java [deleted file]
java/java-tests/testData/inspection/guava/suitableReturnType1.java [deleted file]
java/java-tests/testData/inspection/guava/suitableReturnType1_after.java [deleted file]
java/java-tests/testData/inspection/guava/suitableReturnType2.java [deleted file]
java/java-tests/testData/inspection/guava/suitableReturnType2_after.java [deleted file]
java/java-tests/testData/inspection/guava/suitableReturnType3.java [deleted file]
java/java-tests/testData/inspection/guava/suitableReturnType3_after.java [deleted file]
java/java-tests/testSrc/com/intellij/codeInspection/GuavaFluentIterableTest.java [deleted file]
resources/src/META-INF/IdeaPlugin.xml

diff --git a/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/FluentIterableMethodTransformer.java b/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/FluentIterableMethodTransformer.java
deleted file mode 100644 (file)
index 165814b..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2000-2015 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.codeInspection.java18StreamApi;
-
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.psi.*;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * @author Dmitry Batkovich
- */
-abstract class FluentIterableMethodTransformer {
-  private final static Logger LOG = Logger.getInstance(FluentIterableMethodTransformer.class);
-
-  protected abstract String formatMethod(PsiExpression[] initialMethodParameters);
-
-  protected boolean negate() {
-    return false;
-  }
-
-  @Nullable
-  public final PsiMethodCallExpression transform(PsiMethodCallExpression expression, PsiElementFactory elementFactory) {
-    final String formatted = formatMethod(expression.getArgumentList().getExpressions());
-    final String negation = negate() ? "!" : "";
-    final PsiExpression qualifierExpression = expression.getMethodExpression().getQualifierExpression();
-    LOG.assertTrue(qualifierExpression != null);
-    final String oldQualifierText = qualifierExpression.getText();
-    final String expressionText = negation + oldQualifierText + "." + formatted;
-    final PsiElement replaced = expression.replace(elementFactory.createExpressionFromText(expressionText, null));
-    if (replaced instanceof PsiMethodCallExpression) {
-      PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)replaced;
-      while (true) {
-        final PsiExpression qualifier = methodCallExpression.getMethodExpression().getQualifierExpression();
-        LOG.assertTrue(qualifier != null);
-        if (oldQualifierText.equals(qualifier.getText())) {
-          return methodCallExpression;
-        }
-        methodCallExpression = (PsiMethodCallExpression)qualifier;
-      }
-    }
-    else {
-      return null;
-    }
-  }
-
-  static class OneParameterMethodTransformer extends FluentIterableMethodTransformer {
-    private final String myTemplate;
-    private final boolean myParameterIsFunctionOrPredicate;
-
-    OneParameterMethodTransformer(String template, boolean parameterIsFunctionOrPredicate) {
-      myTemplate = template;
-      myParameterIsFunctionOrPredicate = parameterIsFunctionOrPredicate;
-    }
-
-    OneParameterMethodTransformer(String parameterIsFunctionOrPredicate) {
-      this(parameterIsFunctionOrPredicate, false);
-    }
-
-    protected String formatMethod(PsiExpression[] initialMethodParameters) {
-      final String matchedElementText;
-      if (myParameterIsFunctionOrPredicate) {
-        if (initialMethodParameters.length == 1) {
-          PsiExpression parameter = initialMethodParameters[0];
-          final PsiType type = parameter.getType();
-          Boolean role;
-          if (!(type instanceof PsiMethodReferenceType) && !(type instanceof PsiLambdaExpressionType)
-              && (role = GuavaFunctionAndPredicateConverter.isClassConditionPredicate(parameter)) != null) {
-            matchedElementText = GuavaFunctionAndPredicateConverter.convertFunctionOrPredicateParameter(parameter, role);
-          } else {
-            matchedElementText = parameter.getText();
-          }
-        } else {
-          matchedElementText = "";
-        }
-      } else {
-        matchedElementText = initialMethodParameters.length > 0 ? initialMethodParameters[0].getText() : "";
-      }
-      return String.format(myTemplate, matchedElementText);
-    }
-  }
-
-  static class ToArrayMethodTransformer extends FluentIterableMethodTransformer {
-    @Override
-    protected String formatMethod(PsiExpression[] initialMethodParameters) {
-      final PsiExpression parameter = initialMethodParameters[0];
-      if (parameter instanceof PsiClassObjectAccessExpression) {
-        final PsiType type = ((PsiClassObjectAccessExpression)parameter).getOperand().getType();
-        if (type instanceof PsiClassType) {
-          final PsiClass resolvedClass = ((PsiClassType)type).resolve();
-          if (resolvedClass != null) {
-            final String qName = resolvedClass.getQualifiedName();
-            if (qName != null) {
-              return String.format("toArray(%s[]::new)", qName);
-            }
-          }
-        }
-      }
-      return "toArray()";
-    }
-  }
-
-  static class ParameterlessMethodTransformer extends FluentIterableMethodTransformer {
-    private final String myTemplate;
-    private final boolean myNegation;
-
-    ParameterlessMethodTransformer(String template) {
-      this(template.endsWith(")") ? template : (template + "()"), false);
-    }
-
-    ParameterlessMethodTransformer(String template, boolean negation) {
-      myTemplate = template;
-      myNegation = negation;
-    }
-
-    @Override
-    protected boolean negate() {
-      return myNegation;
-    }
-
-    @Override
-    protected String formatMethod(PsiExpression[] initialMethodParameters) {
-      return myTemplate;
-    }
-  }
-}
diff --git a/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFluentIterableInspection.java b/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFluentIterableInspection.java
deleted file mode 100644 (file)
index 1b13376..0000000
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * Copyright 2000-2015 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.codeInspection.java18StreamApi;
-
-import com.intellij.codeInspection.*;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.module.impl.scopes.JdkScope;
-import com.intellij.openapi.project.Project;
-import com.intellij.psi.*;
-import com.intellij.psi.codeStyle.JavaCodeStyleManager;
-import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.util.InheritanceUtil;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.psi.util.PsiTypesUtil;
-import com.intellij.psi.util.PsiUtil;
-import com.intellij.util.Function;
-import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.MultiMap;
-import gnu.trove.THashSet;
-import gnu.trove.TObjectIdentityHashingStrategy;
-import org.jetbrains.annotations.Nls;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.*;
-
-/**
- * @author Dmitry Batkovich
- */
-@SuppressWarnings("DialogTitleCapitalization")
-public class GuavaFluentIterableInspection extends BaseJavaBatchLocalInspectionTool {
-  private final static Logger LOG = Logger.getInstance(GuavaFluentIterableInspection.class);
-  private final static String PROBLEM_DESCRIPTION = "FluentIterable is used while Stream API is accessible";
-  public final static String GUAVA_FLUENT_ITERABLE = "com.google.common.collect.FluentIterable";
-  public final static String GUAVA_OPTIONAL = "com.google.common.base.Optional";
-  public final static String GUAVA_IMMUTABLE_MAP = "com.google.common.collect.ImmutableMap";
-  public final static String FLUENT_ITERABLE_FROM = "from";
-
-  @Nullable
-  @Override
-  public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
-    if (!PsiUtil.isLanguageLevel8OrHigher(file)) {
-      return null;
-    }
-    final Project project = manager.getProject();
-    final PsiClass fluentIterable = JavaPsiFacade.getInstance(project).findClass(GUAVA_FLUENT_ITERABLE, file.getResolveScope());
-    if (fluentIterable == null) {
-      return null;
-    }
-    final SmartPointerManager mySmartPointerManager = SmartPointerManager.getInstance(project);
-    final Set<PsiMethodCallExpression> myMethodCallsToIgnore =
-      new THashSet<PsiMethodCallExpression>(new TObjectIdentityHashingStrategy<PsiMethodCallExpression>());
-    final MultiMap<PsiLocalVariable, PsiExpression> localVariablesUsages =
-      new MultiMap<PsiLocalVariable, PsiExpression>();
-    final Set<PsiLocalVariable> unconvertibleVariables =
-      new THashSet<PsiLocalVariable>(new TObjectIdentityHashingStrategy<PsiLocalVariable>());
-
-    final List<ProblemDescriptor> descriptors = new ArrayList<ProblemDescriptor>();
-    final JavaRecursiveElementVisitor visitor = new JavaRecursiveElementVisitor() {
-
-      @Override
-      public void visitLocalVariable(final PsiLocalVariable localVariable) {
-        super.visitLocalVariable(localVariable);
-        final PsiType type = localVariable.getType();
-        if (!(type instanceof PsiClassType) || unconvertibleVariables.contains(localVariable)) {
-          return;
-        }
-        final PsiClass variableClass = ((PsiClassType)type).resolve();
-        if (variableClass == null) {
-          return;
-        }
-        final String qualifiedName = variableClass.getQualifiedName();
-        if (!GUAVA_FLUENT_ITERABLE.equals(qualifiedName)) {
-          return;
-        }
-        final PsiCodeBlock context = PsiTreeUtil.getParentOfType(localVariable, PsiCodeBlock.class);
-        if (context == null || !checkDeclaration(localVariable.getInitializer())) {
-          unconvertibleVariables.add(localVariable);
-        }
-      }
-
-      private boolean checkDeclaration(PsiExpression declaration) {
-        if (declaration == null) {
-          return true;
-        }
-        if (!(declaration instanceof PsiMethodCallExpression)) {
-          return false;
-        }
-
-        PsiMethodCallExpression currentCallExpression = (PsiMethodCallExpression)declaration;
-        while (true) {
-          final PsiExpression qualifier = currentCallExpression.getMethodExpression().getQualifierExpression();
-          if (qualifier instanceof PsiMethodCallExpression) {
-            final PsiMethod method = currentCallExpression.resolveMethod();
-            if (method == null || GuavaFluentIterableMethodConverters.isStopMethod(method.getName())) {
-              return false;
-            }
-            final PsiClass aClass = method.getContainingClass();
-            if (aClass == null || !aClass.isEquivalentTo(fluentIterable)) {
-              return false;
-            }
-            currentCallExpression = (PsiMethodCallExpression)qualifier;
-          }
-          else {
-            if (qualifier instanceof PsiReferenceExpression) {
-              final PsiMethod method = currentCallExpression.resolveMethod();
-              if (method == null || !FLUENT_ITERABLE_FROM.equals(method.getName())) {
-                return false;
-              }
-              final PsiClass aClass = method.getContainingClass();
-              if (aClass == null || !GUAVA_FLUENT_ITERABLE.equals(aClass.getQualifiedName())) {
-                return false;
-              }
-              break;
-            }
-            else {
-              return false;
-            }
-          }
-        }
-        return true;
-      }
-
-      @Override
-      public void visitReferenceExpression(PsiReferenceExpression expression) {
-        super.visitReferenceExpression(expression);
-        final PsiElement resolvedElement = expression.resolve();
-        if (resolvedElement instanceof PsiLocalVariable) {
-          PsiLocalVariable fluentIterableVariable = (PsiLocalVariable)resolvedElement;
-          if (!fluentIterable.isEquivalentTo(PsiTypesUtil.getPsiClass(fluentIterableVariable.getType())) ||
-              unconvertibleVariables.contains(fluentIterableVariable)) {
-            return;
-          }
-          analyzeExpression(expression, fluentIterableVariable);
-        }
-      }
-
-      private void addToUnconvertible(PsiLocalVariable variable) {
-        unconvertibleVariables.add(variable);
-        localVariablesUsages.remove(variable);
-      }
-
-      @Override
-      public void visitMethodCallExpression(PsiMethodCallExpression expression) {
-        super.visitMethodCallExpression(expression);
-        if (!myMethodCallsToIgnore.add(expression)) {
-          return;
-        }
-        final PsiReferenceExpression methodExpression = expression.getMethodExpression();
-        final String methodName = methodExpression.getReferenceName();
-        if (FLUENT_ITERABLE_FROM.equals(methodName)) {
-          final PsiMethod method = expression.resolveMethod();
-          if (method == null ||
-              !method.hasModifierProperty(PsiModifier.STATIC) ||
-              !fluentIterable.isEquivalentTo(method.getContainingClass())) {
-            return;
-          }
-          PsiMethodCallExpression currentExpression = expression;
-          while (true) {
-            myMethodCallsToIgnore.add(currentExpression);
-            PsiMethodCallExpression parentMethodCall = PsiTreeUtil.getParentOfType(currentExpression, PsiMethodCallExpression.class);
-            if (parentMethodCall != null) {
-              if (parentMethodCall.getMethodExpression().getQualifierExpression() == currentExpression) {
-                final PsiMethod parentCallMethod = parentMethodCall.resolveMethod();
-                if (parentCallMethod != null && fluentIterable.isEquivalentTo(parentCallMethod.getContainingClass())) {
-                  if (GuavaFluentIterableMethodConverters.isStopMethod(parentCallMethod.getName())) {
-                    return;
-                  }
-                  currentExpression = parentMethodCall;
-                  continue;
-                }
-              }
-            }
-            final PsiElement expressionParent = currentExpression.getParent();
-            if (expressionParent instanceof PsiReturnStatement) {
-              final PsiType containingMethodReturnType = findContainingMethodReturnType((PsiReturnStatement) expressionParent);
-              if (containingMethodReturnType instanceof PsiClassType) {
-                final PsiClass resolvedClass = ((PsiClassType)containingMethodReturnType).resolve();
-                if (resolvedClass == null || !(resolvedClass.getResolveScope() instanceof JdkScope)) {
-                  return;
-                }
-              }
-            }
-            else if (expressionParent instanceof PsiLocalVariable) {
-              final PsiType type = ((PsiLocalVariable)expressionParent).getType();
-              if (type instanceof PsiClassType) {
-                final PsiClass resolvedClass = ((PsiClassType)type).resolve();
-                if (resolvedClass == null || !(resolvedClass.getResolveScope() instanceof JdkScope)) {
-                  return;
-                }
-              }
-            }
-            else if (expressionParent instanceof PsiExpressionList) {
-              if (expressionParent.getParent() instanceof PsiMethodCallExpression
-                  && !isMethodWithParamAcceptsConversion((PsiMethodCallExpression)expressionParent.getParent(),
-                                                         currentExpression,
-                                                         fluentIterable)) {
-                return;
-              }
-            }
-
-            final List<SmartPsiElementPointer<PsiExpression>> exprAsList =
-              ContainerUtil.list(mySmartPointerManager.createSmartPsiElementPointer((PsiExpression)currentExpression));
-            descriptors.add(manager.createProblemDescriptor(currentExpression,
-                                                            PROBLEM_DESCRIPTION,
-                                                            new ConvertGuavaFluentIterableQuickFix(null, exprAsList),
-                                                            ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
-                                                            isOnTheFly));
-            return;
-          }
-        }
-        else {
-          final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
-          if (GuavaFluentIterableMethodConverters.isFluentIterableMethod(methodName) &&
-              qualifierExpression instanceof PsiReferenceExpression) {
-            final PsiElement resolvedElement = ((PsiReferenceExpression)qualifierExpression).resolve();
-            if (resolvedElement instanceof PsiLocalVariable) {
-              PsiLocalVariable fluentIterableLocalVariable = (PsiLocalVariable)resolvedElement;
-              if (!fluentIterable.isEquivalentTo(PsiTypesUtil.getPsiClass(fluentIterableLocalVariable.getType())) ||
-                  unconvertibleVariables.contains(fluentIterableLocalVariable)) {
-                return;
-              }
-              analyzeExpression(expression, fluentIterableLocalVariable);
-            }
-          }
-        }
-      }
-
-      private void analyzeExpression(PsiExpression expression, PsiLocalVariable fluentIterableLocalVariable) {
-        PsiExpression baseExpression = expression;
-        while (true) {
-          final PsiMethodCallExpression
-            methodCallExpression = PsiTreeUtil.getParentOfType(baseExpression, PsiMethodCallExpression.class);
-          if (methodCallExpression != null && methodCallExpression.getMethodExpression().getQualifierExpression() == baseExpression) {
-            final String currentMethodName = methodCallExpression.getMethodExpression().getReferenceName();
-            if (GuavaFluentIterableMethodConverters.isFluentIterableMethod(currentMethodName)) {
-              if (GuavaFluentIterableMethodConverters.isStopMethod((currentMethodName))) {
-                addToUnconvertible(fluentIterableLocalVariable);
-                return;
-              }
-              else {
-                final PsiMethod method = methodCallExpression.resolveMethod();
-                if (method != null && method.getContainingClass() != null && method.getContainingClass().isEquivalentTo(fluentIterable)) {
-                  baseExpression = methodCallExpression;
-                  myMethodCallsToIgnore.add(methodCallExpression);
-                  continue;
-                }
-              }
-            }
-          }
-          break;
-        }
-        final PsiElement parent = baseExpression.getParent();
-        if (parent instanceof PsiExpressionList) {
-          localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-          final boolean suitable = parent.getParent() instanceof PsiMethodCallExpression &&
-                                   isMethodWithParamAcceptsConversion((PsiMethodCallExpression)parent.getParent(), baseExpression,
-                                                                      fluentIterable);
-          if (!suitable) {
-            addToUnconvertible(fluentIterableLocalVariable);
-          }
-        }
-        else if (parent instanceof PsiReferenceExpression) {
-          final PsiMethodCallExpression parentMethodCall = PsiTreeUtil.getParentOfType(baseExpression, PsiMethodCallExpression.class);
-          if (parentMethodCall != null && parentMethodCall.getMethodExpression().getQualifier() == baseExpression) {
-            if (GuavaOptionalConverter.isConvertibleIfOption(parentMethodCall)) {
-              localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-            }
-            else {
-              addToUnconvertible(fluentIterableLocalVariable);
-            }
-          }
-        }
-        else if (parent instanceof PsiLocalVariable) {
-          localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-        }
-        else if (parent instanceof PsiAssignmentExpression) {
-          final PsiAssignmentExpression assignment = (PsiAssignmentExpression)parent;
-          final PsiExpression lExpression = assignment.getLExpression();
-          if (lExpression instanceof PsiReferenceExpression) {
-            if (((PsiReferenceExpression)lExpression).isReferenceTo(fluentIterableLocalVariable)) {
-              if (isSelfAssignment(assignment, fluentIterableLocalVariable)) {
-                localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-                return;
-              }
-              if (checkDeclaration(assignment.getRExpression())) {
-                localVariablesUsages.putValue(fluentIterableLocalVariable, assignment.getRExpression());
-                return;
-              }
-              addToUnconvertible(fluentIterableLocalVariable);
-            }
-            else {
-              localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-            }
-          }
-          else {
-            localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-          }
-        }
-        else if (parent instanceof PsiReturnStatement) {
-          final PsiType containingMethodReturnType = findContainingMethodReturnType((PsiReturnStatement) parent);
-          if (!(containingMethodReturnType instanceof PsiClassType)) {
-            addToUnconvertible(fluentIterableLocalVariable);
-            return;
-          }
-          final PsiClass resolvedClass = ((PsiClassType)containingMethodReturnType).resolve();
-          if (resolvedClass == null || (!CommonClassNames.JAVA_LANG_ITERABLE.equals(resolvedClass.getQualifiedName()) &&
-                                        !CommonClassNames.JAVA_LANG_OBJECT.equals(resolvedClass.getQualifiedName()))) {
-            addToUnconvertible(fluentIterableLocalVariable);
-          }
-          else {
-            localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-          }
-        }
-        else if (parent instanceof PsiExpressionStatement) {
-          localVariablesUsages.putValue(fluentIterableLocalVariable, baseExpression);
-        }
-      }
-    };
-    file.accept(visitor);
-    for (Map.Entry<PsiLocalVariable, Collection<PsiExpression>> e : localVariablesUsages.entrySet()) {
-      final PsiLocalVariable localVariable = e.getKey();
-      final Collection<PsiExpression> foundUsages = e.getValue();
-      final SmartPsiElementPointer<PsiLocalVariable> variablePointer =
-        mySmartPointerManager.createSmartPsiElementPointer(localVariable);
-      final ConvertGuavaFluentIterableQuickFix quickFix = new ConvertGuavaFluentIterableQuickFix(variablePointer, ContainerUtil.map(
-        new THashSet<PsiExpression>(foundUsages), new Function<PsiExpression, SmartPsiElementPointer<PsiExpression>>() {
-          @Override
-          public SmartPsiElementPointer<PsiExpression> fun(PsiExpression expression) {
-            return mySmartPointerManager.createSmartPsiElementPointer(expression);
-          }
-        }));
-      descriptors.add(manager.createProblemDescriptor(localVariable,
-                                                      PROBLEM_DESCRIPTION,
-                                                      quickFix,
-                                                      ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
-                                                      isOnTheFly));
-      for (PsiExpression usage : foundUsages) {
-        descriptors.add(manager.createProblemDescriptor(usage,
-                                                        PROBLEM_DESCRIPTION,
-                                                        quickFix,
-                                                        ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
-                                                        isOnTheFly));
-      }
-    }
-    return descriptors.isEmpty() ? null : descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
-  }
-
-  public static boolean isMethodWithParamAcceptsConversion(PsiMethodCallExpression methodCallExpression,
-                                                     PsiExpression baseExpression,
-                                                     PsiClass fluentIterable) {
-    final PsiExpressionList argList = methodCallExpression.getArgumentList();
-    final PsiMethod method = methodCallExpression.resolveMethod();
-    if (method == null) {
-      return true;
-    }
-    final PsiParameterList paramList = method.getParameterList();
-    if (paramList.getParametersCount() != argList.getExpressions().length &&
-        !(paramList.getParameters()[paramList.getParametersCount() - 1].getType() instanceof PsiEllipsisType)) {
-      return false;
-    }
-    int index = -1;
-    PsiExpression[] expressions = argList.getExpressions();
-    for (int i = 0, length = expressions.length; i < length; i++) {
-      if (expressions[i] == baseExpression) {
-        index = i;
-        break;
-      }
-    }
-    LOG.assertTrue(index >= 0);
-    PsiType parameterType;
-    if (index > paramList.getParametersCount() - 1) {
-      parameterType = paramList.getParameters()[paramList.getParametersCount() - 1].getType();
-    } else {
-      parameterType = paramList.getParameters()[index].getType();
-    }
-    if (parameterType instanceof PsiEllipsisType) {
-      parameterType = ((PsiEllipsisType)parameterType).getComponentType();
-    }
-    if (parameterType instanceof PsiClassType) {
-      final PsiClass resolvedParameterClass = ((PsiClassType)parameterType).resolve();
-      final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(methodCallExpression.getProject());
-      final GlobalSearchScope scope = methodCallExpression.getResolveScope();
-      final PsiClass optional = javaPsiFacade.findClass(GUAVA_OPTIONAL, scope);
-      final PsiClass immutableMap = javaPsiFacade.findClass(GUAVA_IMMUTABLE_MAP, scope);
-      if (resolvedParameterClass != null &&
-          (InheritanceUtil.isInheritorOrSelf(resolvedParameterClass, fluentIterable, true) ||
-           InheritanceUtil.isInheritorOrSelf(resolvedParameterClass, optional, true) ||
-           InheritanceUtil.isInheritorOrSelf(resolvedParameterClass, immutableMap, true))){
-        return false;
-      }
-    }
-    return true;
-  }
-
-  @Nullable
-  private static PsiType findContainingMethodReturnType(PsiReturnStatement returnStatement) {
-    final NavigatablePsiElement contextElement = PsiTreeUtil.getParentOfType(returnStatement, PsiMethod.class, PsiLambdaExpression.class);
-    if (contextElement == null) {
-      return null;
-    }
-    final PsiType containingMethodReturnType = contextElement instanceof PsiMethod ?
-                                               ((PsiMethod) contextElement).getReturnType() :
-                                               LambdaUtil.getFunctionalInterfaceReturnType((PsiLambdaExpression) contextElement);
-    if (containingMethodReturnType == null) {
-      return null;
-    }
-    return containingMethodReturnType;
-  }
-
-  private static boolean isSelfAssignment(PsiAssignmentExpression expression, PsiLocalVariable localVariable) {
-    final PsiExpression rExpression = expression.getRExpression();
-    if (!(rExpression instanceof PsiMethodCallExpression)) {
-      return false;
-    }
-
-    PsiMethodCallExpression methodCall = (PsiMethodCallExpression)rExpression;
-    while (true) {
-      final PsiExpression qualifier = methodCall.getMethodExpression().getQualifierExpression();
-      if (qualifier instanceof PsiMethodCallExpression) {
-        methodCall = (PsiMethodCallExpression)qualifier;
-      } else {
-        break;
-      }
-    }
-
-    final PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression();
-    if (qualifierExpression instanceof PsiReferenceExpression &&
-        !((PsiReferenceExpression)qualifierExpression).isReferenceTo(localVariable)) {
-      return false;
-    }
-    return true;
-  }
-
-  public static class ConvertGuavaFluentIterableQuickFix implements LocalQuickFix {
-    @Nullable private final SmartPsiElementPointer<PsiLocalVariable> myVariable;
-    @NotNull private final List<SmartPsiElementPointer<PsiExpression>> myFoundUsages;
-
-    protected ConvertGuavaFluentIterableQuickFix(@Nullable SmartPsiElementPointer<PsiLocalVariable> variable,
-                                                 @NotNull List<SmartPsiElementPointer<PsiExpression>> foundUsages) {
-      myVariable = variable;
-      myFoundUsages = foundUsages;
-    }
-
-    @Nls
-    @NotNull
-    @Override
-    public String getName() {
-      return getFamilyName();
-    }
-
-    @NotNull
-    @Override
-    public String getFamilyName() {
-      return "Convert Guava's FluentIterable to java.util.stream.Stream";
-    }
-
-    @Override
-    public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
-      final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
-      final PsiElementFactory elementFactory = javaPsiFacade.getElementFactory();
-      final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
-      final GuavaFluentIterableMethodConverters converters = new GuavaFluentIterableMethodConverters(elementFactory);
-      for (SmartPsiElementPointer<PsiExpression> usage : myFoundUsages) {
-        final PsiExpression element = usage.getElement();
-        if (element != null) {
-          PsiElement converted = converters.convert(element);
-          if (converted != null) {
-            codeStyleManager.shortenClassReferences(converted);
-          }
-        }
-      }
-      if (myVariable != null) {
-        final PsiLocalVariable element = myVariable.getElement();
-        if (element != null) {
-          codeStyleManager.shortenClassReferences(converters.convert(element));
-        }
-      }
-    }
-  }
-}
diff --git a/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFluentIterableMethodConverters.java b/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFluentIterableMethodConverters.java
deleted file mode 100644 (file)
index ade6ce3..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright 2000-2015 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.codeInspection.java18StreamApi;
-
-
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import com.intellij.psi.*;
-import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.util.InheritanceUtil;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.util.ArrayUtil;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Dmitry Batkovich
- */
-public class GuavaFluentIterableMethodConverters {
-  private static final Logger LOG = Logger.getInstance(GuavaFluentIterableMethodConverters.class);
-
-  private static final Map<String, FluentIterableMethodTransformer> METHOD_INDEX = new HashMap<String, FluentIterableMethodTransformer>();
-  private static final Map<String, String> TO_OTHER_COLLECTION_METHODS = new HashMap<String, String>();
-  private static final Set<String> STOP_METHODS = new HashSet<String>();
-  private final PsiElementFactory myElementFactory;
-
-  public GuavaFluentIterableMethodConverters(PsiElementFactory elementFactory) {
-    myElementFactory = elementFactory;
-  }
-
-  static {
-    METHOD_INDEX.put("allMatch", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.ALL_MATCH + "(%s)", true));
-    METHOD_INDEX.put("anyMatch", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.ANY_MATCH + "(%s)", true));
-
-    METHOD_INDEX.put("contains", new FluentIterableMethodTransformer.OneParameterMethodTransformer("anyMatch(e -> e != null && e.equals(%s))"));
-    METHOD_INDEX.put("copyInto", new FluentIterableMethodTransformer.OneParameterMethodTransformer("forEach(%s::add)"));
-    METHOD_INDEX.put("filter", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.FILTER + "(%s)", true));
-    METHOD_INDEX.put("first", new FluentIterableMethodTransformer.ParameterlessMethodTransformer(StreamApiConstants.FIND_FIRST));
-    METHOD_INDEX.put("firstMatch", new FluentIterableMethodTransformer.OneParameterMethodTransformer("filter(%s).findFirst()", true));
-    METHOD_INDEX.put("get", new FluentIterableMethodTransformer.OneParameterMethodTransformer("collect(java.util.stream.Collectors.toList()).get(%s)"));
-    METHOD_INDEX
-      .put("index", new FluentIterableMethodTransformer.OneParameterMethodTransformer("collect(java.util.stream.Collectors.toList()).indexOf(%s)"));
-    METHOD_INDEX.put("isEmpty", new FluentIterableMethodTransformer.ParameterlessMethodTransformer("findAny().isPresent()", true));
-    METHOD_INDEX.put("last", new FluentIterableMethodTransformer.ParameterlessMethodTransformer("reduce((previous, current) -> current)"));
-    METHOD_INDEX.put("limit", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.LIMIT + "(%s)"));
-    METHOD_INDEX.put("size", new FluentIterableMethodTransformer.ParameterlessMethodTransformer("collect(java.util.stream.Collectors.toList()).size()"));
-    METHOD_INDEX.put("skip", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.SKIP + "(%s)"));
-    METHOD_INDEX.put("toArray", new FluentIterableMethodTransformer.ToArrayMethodTransformer());
-    METHOD_INDEX.put("transform", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.MAP + "(%s)", true));
-    METHOD_INDEX.put("transformAndConcat", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.FLAT_MAP + "(%s)", true));
-    METHOD_INDEX.put("uniqueIndex", new FluentIterableMethodTransformer.OneParameterMethodTransformer(
-      "collect(java.util.stream.Collectors.toMap(%s, java.util.function.Function.identity()))"));
-
-    TO_OTHER_COLLECTION_METHODS.put("toMap", "collect(java.util.stream.Collectors.toMap(java.util.function.Function.identity(), %s))");
-    TO_OTHER_COLLECTION_METHODS.put("toList", "collect(java.util.stream.Collectors.toList())");
-    TO_OTHER_COLLECTION_METHODS.put("toSet", "collect(java.util.stream.Collectors.toSet())");
-    TO_OTHER_COLLECTION_METHODS.put("toSortedList", "sorted(%s).collect(java.util.stream.Collectors.toList())");
-    TO_OTHER_COLLECTION_METHODS.put("toSortedSet", "sorted(%s).collect(java.util.stream.Collectors.toSet())");
-
-    STOP_METHODS.add("append");
-    STOP_METHODS.add("cycle");
-  }
-
-  public static boolean isFluentIterableMethod(final String methodName) {
-    return STOP_METHODS.contains(methodName) ||
-           TO_OTHER_COLLECTION_METHODS.containsKey(methodName) ||
-           METHOD_INDEX.containsKey(methodName);
-  }
-
-  public static boolean isStopMethod(final String methodName) {
-    return STOP_METHODS.contains(methodName);
-  }
-
-  public PsiLocalVariable convert(final PsiLocalVariable localVariable) {
-    final PsiTypeElement typeElement = localVariable.getTypeElement();
-    final PsiReferenceParameterList generics = PsiTreeUtil.findChildOfType(typeElement, PsiReferenceParameterList.class);
-    typeElement.replace(myElementFactory.createTypeElementFromText(
-      StreamApiConstants.JAVA_UTIL_STREAM_STREAM + (generics == null ? "" : generics.getText()), null));
-
-    final PsiExpression initializer = localVariable.getInitializer();
-    if (initializer != null) {
-      convertMethodCallDeep((PsiMethodCallExpression)initializer);
-    }
-    return localVariable;
-  }
-
-  public PsiElement convert(PsiExpression expression) {
-    if (expression instanceof PsiReferenceExpression) {
-      final PsiElement expressionParent = expression.getParent();
-      if (expressionParent instanceof PsiReturnStatement || isIterableMethodParameter(expressionParent, expression)) {
-        return addCollectionToList(expression);
-      }
-      return null;
-    }
-    final PsiMethodCallExpression parentMethodCall = PsiTreeUtil.getParentOfType(expression, PsiMethodCallExpression.class);
-    if (parentMethodCall != null && parentMethodCall.getMethodExpression().getQualifierExpression() == expression) {
-      final PsiMethod seqTailMethod = parentMethodCall.resolveMethod();
-      if (seqTailMethod == null) {
-        return null;
-      }
-      final PsiClass seqTailMethodClass = seqTailMethod.getContainingClass();
-      if (seqTailMethodClass != null && GuavaFluentIterableInspection.GUAVA_OPTIONAL.equals(seqTailMethodClass.getQualifiedName())) {
-        final PsiMethodCallExpression newParentMethodCall = GuavaOptionalConverter.convertGuavaOptionalToJava(parentMethodCall, myElementFactory);
-        expression = newParentMethodCall.getMethodExpression().getQualifierExpression();
-      }
-    }
-    if (expression instanceof PsiMethodCallExpression) {
-      expression = convertMethodCallDeep((PsiMethodCallExpression)expression);
-    }
-    if (expression == null) {
-      return null;
-    }
-    final PsiElement parent = expression.getParent();
-    if (parent instanceof PsiExpressionList) {
-      final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)parent.getParent();
-      PsiExpression[] expressions = methodCall.getArgumentList().getExpressions();
-      int index = ArrayUtil.indexOf(expressions, expression);
-      LOG.assertTrue(index >= 0);
-      final PsiMethod method = methodCall.resolveMethod();
-      LOG.assertTrue(method != null);
-      final PsiType parameterType = method.getParameterList().getParameters()[index].getType();
-      return addCollectToListIfNeed(expression, parameterType);
-    }
-    else if (parent instanceof PsiReturnStatement) {
-      final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(parent, PsiMethod.class);
-      LOG.assertTrue(containingMethod != null);
-      final PsiType returnType = containingMethod.getReturnType();
-      return addCollectToListIfNeed(expression, returnType);
-    }
-    return expression;
-  }
-
-  private PsiExpression addCollectToListIfNeed(PsiExpression expression, PsiType type) {
-    if (type instanceof PsiClassType && ((PsiClassType)type).rawType().equalsToText(CommonClassNames.JAVA_LANG_ITERABLE)) {
-      return (PsiExpression)addCollectionToList(expression);
-    }
-    return expression;
-  }
-
-  private PsiElement addCollectionToList(PsiElement expression) {
-    return expression.replace(myElementFactory.createExpressionFromText(expression.getText() + ".collect(java.util.stream.Collectors.toList())", null));
-  }
-
-  private static boolean isIterableMethodParameter(PsiElement listExpression, PsiExpression parameterExpression) {
-    if (!(listExpression instanceof PsiExpressionList)) {
-      return false;
-    }
-    if (!(listExpression.getParent() instanceof PsiMethodCallExpression)) {
-      return false;
-    }
-    final Project project = parameterExpression.getProject();
-    final PsiClass fluentIterable = JavaPsiFacade.getInstance(project).findClass(GuavaFluentIterableInspection.GUAVA_FLUENT_ITERABLE, 
-                                                                                 listExpression.getResolveScope());
-    return GuavaFluentIterableInspection.isMethodWithParamAcceptsConversion((PsiMethodCallExpression)listExpression.getParent(), parameterExpression, fluentIterable);
-  }
-
-  @Nullable
-  private PsiMethodCallExpression convertMethodCallDeep(@NotNull PsiMethodCallExpression methodCall) {
-    PsiMethodCallExpression newMethodCall = methodCall;
-    PsiMethodCallExpression returnCall = null;
-    while (true) {
-      final PsiReferenceExpression methodExpression = newMethodCall.getMethodExpression();
-      final String name = methodExpression.getReferenceName();
-      PsiMethodCallExpression converted = convertFromMethodCall(newMethodCall);
-      if (converted != null) {
-        return returnCall;
-      }
-      if (TO_OTHER_COLLECTION_METHODS.containsKey(name)) {
-        converted = convertToCollection(newMethodCall, name);
-      }
-      else {
-        final FluentIterableMethodTransformer transformer = METHOD_INDEX.get(name);
-        LOG.assertTrue(transformer != null, name);
-        converted = transformer.transform(newMethodCall, myElementFactory);
-      }
-      if (converted == null) {
-        return returnCall;
-      }
-
-      if (returnCall == null) {
-        returnCall = converted;
-      }
-      newMethodCall = converted;
-      final PsiExpression expression = newMethodCall.getMethodExpression().getQualifierExpression();
-      if (expression instanceof PsiMethodCallExpression) {
-        newMethodCall = (PsiMethodCallExpression)expression;
-      }
-      else {
-        return returnCall;
-      }
-    }
-  }
-  
-  private PsiMethodCallExpression convertFromMethodCall(PsiMethodCallExpression methodCall) {
-    if (GuavaFluentIterableInspection.FLUENT_ITERABLE_FROM.equals(methodCall.getMethodExpression().getReferenceName())) {
-      final PsiExpression[] argumentList = methodCall.getArgumentList().getExpressions();
-      LOG.assertTrue(argumentList.length == 1);
-      final PsiExpression expression = argumentList[0];
-
-      final PsiType type = expression.getType();
-      LOG.assertTrue(type instanceof PsiClassType);
-      final String newExpressionText;
-      if (InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_COLLECTION)) {
-        newExpressionText = expression.getText() + ".stream()";
-      } else {
-        newExpressionText = "java.util.stream.StreamSupport.stream(" + expression.getText() + ".spliterator(), false)";
-      }
-      return (PsiMethodCallExpression)methodCall.replace(myElementFactory.createExpressionFromText(newExpressionText, null));
-    }
-    return null;
-  }
-
-  private PsiMethodCallExpression convertToCollection(final PsiMethodCallExpression methodCall,
-                                                      final String methodName) {
-    final PsiExpression[] expressions = methodCall.getArgumentList().getExpressions();
-    LOG.assertTrue(expressions.length < 2);
-    String template = TO_OTHER_COLLECTION_METHODS.get(methodName);
-    if (expressions.length == 1) {
-      template = String.format(template, expressions[0].getText());
-    }
-    final PsiExpression qualifier = methodCall.getMethodExpression().getQualifierExpression();
-    if (qualifier == null) {
-      return null;
-    }
-    final PsiExpression expression = myElementFactory.createExpressionFromText(qualifier.getText() + "." + template, null);
-    return (PsiMethodCallExpression)methodCall.replace(expression);
-  }
-}
diff --git a/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFunctionAndPredicateConverter.java b/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaFunctionAndPredicateConverter.java
deleted file mode 100644 (file)
index f6b14a0..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2000-2015 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.codeInspection.java18StreamApi;
-
-import com.intellij.codeInspection.AnonymousCanBeLambdaInspection;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.psi.*;
-import com.intellij.psi.util.InheritanceUtil;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * @author Dmitry Batkovich
- */
-public class GuavaFunctionAndPredicateConverter {
-  private final static Logger LOG = Logger.getInstance(GuavaFunctionAndPredicateConverter.class);
-
-  @Nullable
-  public static Boolean isClassConditionPredicate(final PsiExpression expression) {
-    final PsiType type = expression.getType();
-    if (type instanceof PsiClassType) {
-      final PsiClass resolvedClass = ((PsiClassType)type).resolve();
-      if (InheritanceUtil.isInheritor(resolvedClass, "com.google.common.base.Function") ||
-          InheritanceUtil.isInheritor(resolvedClass, "com.google.common.base.Predicate")) {
-        return Boolean.FALSE;
-      }
-      else if (InheritanceUtil.isInheritor(resolvedClass, CommonClassNames.JAVA_LANG_CLASS)) {
-        return Boolean.TRUE;
-      }
-    }
-    return null;
-  }
-
-  @NotNull
-  public static String convertFunctionOrPredicateParameter(final @NotNull PsiExpression expression,
-                                                           final boolean role) {
-    if (role) {
-      final String pattern = expression instanceof PsiMethodCallExpression || expression instanceof PsiReferenceExpression
-                             ? "%s::isInstance"
-                             : "(%s)::isInstance";
-      return String.format(pattern, expression.getText());
-    }
-    if (expression instanceof PsiNewExpression) {
-      final PsiAnonymousClass anonymousClass = ((PsiNewExpression)expression).getAnonymousClass();
-      if (anonymousClass != null && AnonymousCanBeLambdaInspection.canBeConvertedToLambda(anonymousClass, true)) {
-        final PsiExpression lambdaExpression = AnonymousCanBeLambdaInspection.replacePsiElementWithLambda(expression, true, false);
-        LOG.assertTrue(lambdaExpression != null);
-        return lambdaExpression.getText();
-      }
-    }
-    String qualifierText = expression.getText();
-    if (!(expression instanceof PsiMethodCallExpression) && !(expression instanceof PsiReferenceExpression)) {
-      qualifierText = "(" + qualifierText + ")";
-    }
-    return qualifierText + "::apply";
-  }
-}
diff --git a/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaOptionalConverter.java b/java/java-impl/src/com/intellij/codeInspection/java18StreamApi/GuavaOptionalConverter.java
deleted file mode 100644 (file)
index 673f25d..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2000-2015 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.codeInspection.java18StreamApi;
-
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.psi.*;
-import com.intellij.util.containers.hash.HashMap;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Map;
-
-/**
- * @author Dmitry Batkovich
- */
-public class GuavaOptionalConverter {
-  private static final Logger LOG = Logger.getInstance(GuavaOptionalConverter.class);
-  private static final Map<String, FluentIterableMethodTransformer> METHODS_CONVERSION = new HashMap<String, FluentIterableMethodTransformer>();
-  private static final String OR_METHOD = "or";
-
-  static {
-    METHODS_CONVERSION.put("isPresent", new FluentIterableMethodTransformer.ParameterlessMethodTransformer("isPresent"));
-    METHODS_CONVERSION.put("get", new FluentIterableMethodTransformer.ParameterlessMethodTransformer("get"));
-    METHODS_CONVERSION.put(OR_METHOD, new FluentIterableMethodTransformer.OneParameterMethodTransformer("orElse(%s)"));
-    METHODS_CONVERSION.put("orNull", new FluentIterableMethodTransformer.ParameterlessMethodTransformer("orElse(null)"));
-  }
-
-  public static boolean isConvertibleIfOption(PsiMethodCallExpression methodCallExpression) {
-    final PsiMethod method = methodCallExpression.resolveMethod();
-    if (method == null) {
-      return false;
-    }
-    final PsiClass aClass = method.getContainingClass();
-    if (aClass == null) {
-      return false;
-    }
-    if (!GuavaFluentIterableInspection.GUAVA_OPTIONAL.equals(aClass.getQualifiedName())) {
-      return true;
-    }
-    return METHODS_CONVERSION.containsKey(method.getName());
-  }
-
-  @NotNull
-  public static PsiMethodCallExpression convertGuavaOptionalToJava(final PsiMethodCallExpression methodCall,
-                                                                   final PsiElementFactory elementFactory) {
-    final String methodName = methodCall.getMethodExpression().getReferenceName();
-    if (methodName == OR_METHOD) {
-      final PsiExpression[] arguments = methodCall.getArgumentList().getExpressions();
-      if (arguments.length != 1) {
-        return methodCall;
-      }
-      final PsiExpression argument = arguments[0];
-      final PsiType type = argument.getType();
-      if (type instanceof PsiClassType) {
-        final PsiClass resolvedClass = ((PsiClassType)type).resolve();
-        if (resolvedClass != null) {
-          final String qName = resolvedClass.getQualifiedName();
-          if (GuavaFluentIterableInspection.GUAVA_OPTIONAL.equals(qName) || "com.google.common.base.Supplier".equals(qName)) {
-            return methodCall;
-          }
-        }
-      }
-    }
-    final FluentIterableMethodTransformer conversion = METHODS_CONVERSION.get(methodName);
-    if (conversion == null) {
-      return methodCall;
-    }
-    final PsiMethodCallExpression transformed = conversion.transform(methodCall, elementFactory);
-    LOG.assertTrue(transformed != null);
-    return transformed;
-  }
-}
diff --git a/java/java-tests/testData/inspection/guava/base.java b/java/java-tests/testData/inspection/guava/base.java
deleted file mode 100644 (file)
index b8af36b..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-import com.google.common.collect.FluentIterable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class FluentIterableMain {
-
-  Function<String, String> getFunction(int parameter) {
-    return new Function<String, String>() {
-      @Override
-      public String apply(String input) {
-        return null;
-      }
-    };
-  }
-
-  Iterable<String> m2() {
-    FluentIte<caret>rable<String> i;
-    i = FluentIterable.from(new ArrayList<String>()).transform(String::trim);
-
-    i.transform(null);
-
-    String s = i.firstMatch(null).orNull();
-
-    i = i.transform(getFunction(10));
-
-    i = i.transform(new Function<String, String>() {
-      @Override
-      public String apply(String input) {
-        return null;
-      }
-    });
-
-    i.filter(Object.class);
-
-    i = i.transform(s11 -> s11.intern());
-    i = i.transform(String::intern);
-
-    i = i.transform(s11 -> {
-      return s11.intern();
-    });
-
-    i.firstMatch((String ssss) -> {
-      System.out.println(ssss);
-      return ssss.contains("asfdsf");
-    }).or("");
-
-    m3(i);
-    m4(i.transform(String::trim).transform(String::isEmpty));
-
-    i.toList().get(10);
-
-    boolean empty = i.isEmpty();
-    String last = i.last().get();
-
-    i.first();
-    i.forEach(s1 -> {
-
-      System.out.println(s1);
-
-    });
-
-    i.skip(10);
-
-    ArrayList<String> l = new ArrayList<>();
-    i.forEach(l::add);
-    System.out.println();
-    System.out.println();
-    i.anyMatch(e -> e != null && e.equals(123));
-    i.forEach(System.out::println);
-    System.out.println(i.allMatch(a -> a.isEmpty()));
-    System.out.println(i.anyMatch(a -> a.isEmpty()));
-    i.transform(a -> a);
-    i.transform(a -> a);
-
-    i = i.skip(10);
-
-    i = i.filter(s10 -> s10.isEmpty());
-    i = i.transform(s11 -> s11.intern()).transform(s12 -> String.valueOf(s12));
-
-    System.out.println();
-
-    i = i.transform(String::trim);
-
-    List<String> list = i.toList();
-    String[] arr = i.toArray(String.class);
-
-    String stringOptional = i.filter(String::isEmpty).first().get();
-
-    return i;
-  }
-
-  void m3(Iterable i) {
-
-  }
-
-  void m4(Iterable i) {
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/base_after.java b/java/java-tests/testData/inspection/guava/base_after.java
deleted file mode 100644 (file)
index 5c5d74a..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-import com.google.common.collect.FluentIterable;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public class FluentIterableMain {
-
-  Function<String, String> getFunction(int parameter) {
-    return new Function<String, String>() {
-      @Override
-      public String apply(String input) {
-        return null;
-      }
-    };
-  }
-
-  Iterable<String> m2() {
-    Stream<String> i;
-    i = new ArrayList<String>().stream().map(String::trim);
-
-    i.map(null);
-
-    String s = i.filter(null).findFirst().orElse(null);
-
-    i = i.map(getFunction(10));
-
-    i = i.map(new Function<String, String>() {
-        @Override
-        public String apply(String input) {
-            return null;
-        }
-    });
-
-    i.filter((Object.class)::isInstance);
-
-    i = i.map(s11 -> s11.intern());
-    i = i.map(String::intern);
-
-    i = i.map(s11 -> {
-        return s11.intern();
-    });
-
-    i.filter((String ssss) -> {
-        System.out.println(ssss);
-        return ssss.contains("asfdsf");
-    }).findFirst().orElse("");
-
-    m3(i.collect(Collectors.toList()));
-    m4(i.map(String::trim).map(String::isEmpty).collect(Collectors.toList()));
-
-    i.collect(Collectors.toList()).get(10);
-
-    boolean empty = !i.findAny().isPresent();
-    String last = i.reduce((previous, current) -> current).get();
-
-    i.findFirst();
-    i.forEach(s1 -> {
-
-      System.out.println(s1);
-
-    });
-
-    i.skip(10);
-
-    ArrayList<String> l = new ArrayList<>();
-    i.forEach(l::add);
-    System.out.println();
-    System.out.println();
-    i.anyMatch(e -> e != null && e.equals(123));
-    i.forEach(System.out::println);
-    System.out.println(i.allMatch(a -> a.isEmpty()));
-    System.out.println(i.anyMatch(a -> a.isEmpty()));
-    i.map(a -> a);
-    i.map(a -> a);
-
-    i = i.skip(10);
-
-    i = i.filter(s10 -> s10.isEmpty());
-    i = i.map(s11 -> s11.intern()).map(s12 -> String.valueOf(s12));
-
-    System.out.println();
-
-    i = i.map(String::trim);
-
-    List<String> list = i.collect(Collectors.toList());
-    String[] arr = i.toArray(String[]::new);
-
-    String stringOptional = i.filter(String::isEmpty).findFirst().get();
-
-    return i.collect(Collectors.toList());
-  }
-
-  void m3(Iterable i) {
-
-  }
-
-  void m4(Iterable i) {
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/insideLambda.java b/java/java-tests/testData/inspection/guava/insideLambda.java
deleted file mode 100644 (file)
index baf7712..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-import com.google.common.base.*;
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-import java.util.ArrayList;
-
-public class Main20 {
-  void m() {
-    Supplier<Object> doubleSupplier = () -> {
-      FluentIterable<String> fi = FluentIterable.from(new ArrayList<String>());
-      return fi.transf<caret>orm(new Function<String, Integer>() {
-        @Override
-        public Integer apply(String input) {
-          return input.length();
-        }
-      });
-    };
-
-  }
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/insideLambda_after.java b/java/java-tests/testData/inspection/guava/insideLambda_after.java
deleted file mode 100644 (file)
index b4c4145..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-import com.google.common.base.*;
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-import java.util.ArrayList;
-import java.util.stream.Stream;
-
-public class Main20 {
-  void m() {
-    Supplier<Object> doubleSupplier = () -> {
-      Stream<String> fi = new ArrayList<String>().stream();
-      return fi.map(input -> input.length());
-    };
-
-  }
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/localVariable.java b/java/java-tests/testData/inspection/guava/localVariable.java
deleted file mode 100644 (file)
index 0894895..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-import com.google.common.collect.FluentIterable;
-import java.util.ArrayList;
-
-public class Main20 {
-  void get() {
-    FluentIterable<String> i = FluentIterable.from(new ArrayList<String>());
-    if (i.tran<caret>sform(String::isEmpty).first().orNull()) {
-      System.out.println(String.format("asd %s zxc", i));
-    }
-  }
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/localVariable_after.java b/java/java-tests/testData/inspection/guava/localVariable_after.java
deleted file mode 100644 (file)
index 89b93e4..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-import com.google.common.collect.FluentIterable;
-import java.util.ArrayList;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public class Main20 {
-  void get() {
-    Stream<String> i = new ArrayList<String>().stream();
-    if (i.map(String::isEmpty).findFirst().orElse(null)) {
-      System.out.println(String.format("asd %s zxc", i.collect(Collectors.toList())));
-    }
-  }
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/nonSuitableMethodParameterType.java b/java/java-tests/testData/inspection/guava/nonSuitableMethodParameterType.java
deleted file mode 100644 (file)
index 7d5ad5f..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-import com.google.common.collect.FluentIterable;
-
-import java.util.ArrayList;
-
-public class Main20 {
-
-  void get() {
-    FluentIterable<String> i = FluentIterable.fr<caret>om(new ArrayList<String>());
-    m(i);
-  }
-
-  void m(FluentIterable abc) {
-
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/nonSuitableReturnType.java b/java/java-tests/testData/inspection/guava/nonSuitableReturnType.java
deleted file mode 100644 (file)
index 6c2c0c9..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class Main20 {
-
-  Optional<String> get() {
-    return FluentIterable.fr<caret>om(new ArrayList<String>()).transform(String::trim).first();
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/nonSuitableReturnType2.java b/java/java-tests/testData/inspection/guava/nonSuitableReturnType2.java
deleted file mode 100644 (file)
index fc6e848..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class Main20 {
-
-  FluentIterable<String> get() {
-    return FluentIterable.fro<caret>m(new ArrayList<String>()).transform(String::trim);
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/stopMethods.java b/java/java-tests/testData/inspection/guava/stopMethods.java
deleted file mode 100644 (file)
index 6c5d6a5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-import com.google.common.collect.FluentIterable;
-
-import java.util.ArrayList;
-
-public class Main20 {
-
-  void get() {
-    FluentIterable<String> i = FluentIterable.f<caret>rom(new ArrayList<String>()).cycle();
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/suitableReturnType1.java b/java/java-tests/testData/inspection/guava/suitableReturnType1.java
deleted file mode 100644 (file)
index a932350..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class Main20 {
-
-  Iterable<String> get() {
-    return FluentIterable.f<caret>rom(new ArrayList<String>()).transform(String::trim);
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/suitableReturnType1_after.java b/java/java-tests/testData/inspection/guava/suitableReturnType1_after.java
deleted file mode 100644 (file)
index d130e8e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-public class Main20 {
-
-  Iterable<String> get() {
-    return new ArrayList<String>().stream().map(String::trim).collect(Collectors.toList());
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/suitableReturnType2.java b/java/java-tests/testData/inspection/guava/suitableReturnType2.java
deleted file mode 100644 (file)
index bb4fb5e..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class Main20 {
-
-  String get() {
-    return FluentIterable.f<caret>rom(new ArrayList<String>()).transform(String::trim).get(10);
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/suitableReturnType2_after.java b/java/java-tests/testData/inspection/guava/suitableReturnType2_after.java
deleted file mode 100644 (file)
index c71d0d1..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-public class Main20 {
-
-  String get() {
-    return new ArrayList<String>().stream().map(String::trim).collect(Collectors.toList()).get(10);
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/suitableReturnType3.java b/java/java-tests/testData/inspection/guava/suitableReturnType3.java
deleted file mode 100644 (file)
index 9cfc8d2..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class Main20 {
-
-  boolean get() {
-    return FluentIterable.f<caret>rom(new ArrayList<String>()).transform(String::trim).first().isPresent();
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/guava/suitableReturnType3_after.java b/java/java-tests/testData/inspection/guava/suitableReturnType3_after.java
deleted file mode 100644 (file)
index 866571c..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class Main20 {
-
-  boolean get() {
-    return new ArrayList<String>().stream().map(String::trim).findFirst().isPresent();
-  }
-
-}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/GuavaFluentIterableTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/GuavaFluentIterableTest.java
deleted file mode 100644 (file)
index dd9ab0a..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2000-2015 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.codeInspection;
-
-import com.intellij.JavaTestUtil;
-import com.intellij.codeInsight.intention.IntentionAction;
-import com.intellij.codeInspection.ex.QuickFixWrapper;
-import com.intellij.codeInspection.java18StreamApi.GuavaFluentIterableInspection;
-import com.intellij.codeInspection.java18StreamApi.StaticPseudoFunctionalStyleMethodInspection;
-import com.intellij.openapi.application.PathManager;
-import com.intellij.pom.java.LanguageLevel;
-import com.intellij.testFramework.IdeaTestUtil;
-import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
-import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
-
-import java.io.File;
-import java.util.ArrayList;
-
-/**
- * @author Dmitry Batkovich
- */
-public class GuavaFluentIterableTest extends JavaCodeInsightFixtureTestCase {
-  @Override
-  protected String getTestDataPath()  {
-    return JavaTestUtil.getJavaTestDataPath() + "/inspection/guava";
-  }
-
-  @Override
-  protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception {
-    moduleBuilder.setLanguageLevel(LanguageLevel.JDK_1_8);
-    moduleBuilder.addLibraryJars("guava-17.0.jar", PathManager.getHomePath().replace(File.separatorChar, '/') + "/community/lib/",
-                                 "guava-17.0.jar");
-    moduleBuilder.addLibraryJars("guava-17.0.jar-2", PathManager.getHomePath().replace(File.separatorChar, '/') + "/lib/",
-                                 "guava-17.0.jar");
-    moduleBuilder.addJdk(IdeaTestUtil.getMockJdk18Path().getPath());
-  }
-
-  public void testBase() {
-    doTest();
-  }
-
-  public void testSuitableReturnType1() {
-    doTest();
-  }
-
-  public void testSuitableReturnType2() {
-    doTest();
-  }
-
-  public void testSuitableReturnType3() {
-    doTest();
-  }
-
-  public void testNonSuitableReturnType() {
-    doTest(false);
-  }
-
-  public void testNonSuitableReturnType2() {
-    doTest(false);
-  }
-
-  public void testNonSuitableMethodParameterType() {
-    doTest(false);
-  }
-
-  public void testStopMethods() {
-    doTest(false);
-  }
-
-  public void testLocalVariable() {
-    doTest();
-  }
-
-  public void testInsideLambda() {
-    doTest();
-  }
-
-  private void doTest() {
-    doTest(true);
-  }
-
-  private void doTest(boolean quickFixMustBeFound) {
-    myFixture.configureByFile(getTestName(true) + ".java");
-    myFixture.enableInspections(new GuavaFluentIterableInspection());
-    final QuickFixWrapper quickFix = myFixture.getAvailableIntentions()
-      .stream()
-      .filter(QuickFixWrapper.class::isInstance)
-      .map(action -> (QuickFixWrapper)action)
-      .filter(action -> action.getFix() instanceof GuavaFluentIterableInspection.ConvertGuavaFluentIterableQuickFix)
-      .findFirst().orElse(null);
-    if (quickFix != null) {
-      myFixture.launchAction(quickFix);
-    }
-    assertTrue(!quickFixMustBeFound || quickFix != null);
-    if (quickFixMustBeFound) {
-      myFixture.checkResultByFile(getTestName(true) + "_after.java");
-    }
-  }
-}
index b9150686fcbdf14cd6426265eaeff5e8c8bd8359..a388ab0a7852c899a685ed31bbe714654bf3d94d 100644 (file)
                      groupName="Performance issues" enabledByDefault="false" level="WARNING"
                      implementationClass="com.intellij.codeInspection.CollectionAddAllCanBeReplacedWithConstructorInspection"
                      displayName="Collection.addAll() can be replaced with parametrized constructor"/>
-    <localInspection groupPath="Java" language="JAVA" shortName="GuavaFluentIterable"
-                     groupBundle="messages.InspectionsBundle"
-                     groupName="Java language level migration aids" enabledByDefault="false" level="WARNING"
-                     implementationClass="com.intellij.codeInspection.java18StreamApi.GuavaFluentIterableInspection"
-                     displayName="Guava's FluentIterable can be replaced by java.util.stream.Stream"/>
+
     <intentionAction>
       <className>com.intellij.codeInsight.daemon.quickFix.RedundantLambdaParameterTypeIntention</className>
       <category>Java/Declaration</category>