PY-17265 Cleanup related to transition to Java 8
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Tue, 18 Oct 2016 14:48:17 +0000 (17:48 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Mon, 24 Oct 2016 21:03:49 +0000 (00:03 +0300)
Not all results of refactorings like transforming anonymous classes
into lambdas and replacing explicit type parameters with diamonds where
applied during rebase on the updated master.

python/src/com/jetbrains/python/PyBundle.properties
python/src/com/jetbrains/python/refactoring/move/PyMoveSymbolDelegate.java
python/src/com/jetbrains/python/refactoring/move/makeFunctionTopLevel/PyBaseMakeFunctionTopLevelProcessor.java
python/src/com/jetbrains/python/refactoring/move/makeFunctionTopLevel/PyMakeMethodTopLevelProcessor.java
python/src/com/jetbrains/python/refactoring/move/moduleMembers/PyMoveModuleMembersDialog.java
python/src/com/jetbrains/python/refactoring/move/moduleMembers/PyMoveSymbolProcessor.java
python/testSrc/com/jetbrains/python/refactoring/PyMakeFunctionTopLevelTest.java

index fa6b36ba76d78291ef2a06a200bfd750e224671f..5b0883f3a994bdf3150f26bf13fa05227a8b33e4 100644 (file)
@@ -667,6 +667,7 @@ refactoring.make.method.top.level.dialog.description=Create top-level function f
 
 refactoring.make.local.function.top.level.dialog.title=Make Local Function Top-Level
 refactoring.make.local.function.top.level.dialog.description=Create top-level function from the local function {0}
+
 refactoring.make.function.top.level.error.nonlocal.writes=Cannot move function with nonlocal writes
 refactoring.make.function.top.level.error.self.reads=Cannot move function that contains usages of "self" parameter from outer scope
 refactoring.make.function.top.level.error.outer.scope.reads=Cannon move method that references names from the outer scope
index 8506665181f821d33301b6d07d857c1edc9b95bf..39275aac3bbd7d67cb6d31961ead85990e4e3d26 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.SelectionModel;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
index d5463514f004ff0bb22b4433ec13f8238090afad..995947d1977cb6afcb7f497d3678f05e267594cd 100644 (file)
@@ -18,7 +18,6 @@ package com.jetbrains.python.refactoring.move.makeFunctionTopLevel;
 import com.intellij.codeInsight.controlflow.ControlFlow;
 import com.intellij.codeInsight.controlflow.Instruction;
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
@@ -64,7 +63,7 @@ public abstract class PyBaseMakeFunctionTopLevelProcessor extends BaseRefactorin
   protected final PyResolveContext myResolveContext;
   protected final PyElementGenerator myGenerator;
   protected final String myDestinationPath;
-  protected final List<PsiElement> myExternalReads = new ArrayList<PsiElement>();
+  protected final List<PsiElement> myExternalReads = new ArrayList<>();
 
   public PyBaseMakeFunctionTopLevelProcessor(@NotNull PyFunction targetFunction, @NotNull String destinationPath) {
     super(targetFunction.getProject());
@@ -130,15 +129,12 @@ public abstract class PyBaseMakeFunctionTopLevelProcessor extends BaseRefactorin
   }
 
   private boolean importsRequired(@NotNull UsageInfo[] usages, final PyFile targetFile) {
-    return ContainerUtil.exists(usages, new Condition<UsageInfo>() {
-      @Override
-      public boolean value(UsageInfo info) {
-        final PsiElement element = info.getElement();
-        if (element == null) {
-          return false;
-        }
-        return !belongsToFunction(element) && info.getFile() != targetFile;
+    return ContainerUtil.exists(usages, info -> {
+      final PsiElement element = info.getElement();
+      if (element == null) {
+        return false;
       }
+      return !belongsToFunction(element) && info.getFile() != targetFile;
     });
   }
 
@@ -148,7 +144,7 @@ public abstract class PyBaseMakeFunctionTopLevelProcessor extends BaseRefactorin
 
 
   private void updateImports(@NotNull PyFunction newFunction, @NotNull UsageInfo[] usages) {
-    final Set<PsiFile> usageFiles = new HashSet<PsiFile>();
+    final Set<PsiFile> usageFiles = new HashSet<>();
     for (UsageInfo usage : usages) {
       usageFiles.add(usage.getFile());
     }
index 2e42facb8d6902b928eb2cb0d42e7a4777d45272..735e8f801e4f256c8ce4f1d0ca2705fc00b301df 100644 (file)
@@ -21,7 +21,6 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.usageView.UsageInfo;
-import com.intellij.util.Function;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.containers.HashSet;
@@ -89,7 +88,7 @@ public class PyMakeMethodTopLevelProcessor extends PyBaseMakeFunctionTopLevelPro
           PyExpression instanceExpr = qualifier;
           final PyArgumentList argumentList = callExpr.getArgumentList();
           
-          // Class.method(instance) -> method(instance)
+          // Class.method(instance) -> method(instance.attr)
           if (resolvesToClass(qualifier)) {
             final PyExpression[] arguments = argumentList.getArguments();
             if (arguments.length > 0) {
index 5a564f0ce7092b950294561822dbac14baefa133..6cbfe865a45a311f5879eaf01ff11d943fe94bc5 100644 (file)
@@ -19,13 +19,13 @@ import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapperPeer;
 import com.intellij.psi.PsiNamedElement;
+import com.intellij.refactoring.classMembers.MemberInfoBase;
 import com.intellij.refactoring.classMembers.MemberInfoChange;
 import com.intellij.refactoring.classMembers.MemberInfoModel;
 import com.intellij.refactoring.ui.AbstractMemberSelectionTable;
 import com.intellij.ui.HideableDecorator;
 import com.intellij.ui.RowIcon;
 import com.intellij.ui.components.JBScrollPane;
-import com.intellij.util.Function;
 import com.intellij.util.containers.ContainerUtil;
 import com.jetbrains.python.PyBundle;
 import com.jetbrains.python.psi.PyClass;
@@ -44,7 +44,6 @@ import javax.swing.event.TableModelEvent;
 import javax.swing.event.TableModelListener;
 import java.awt.*;
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -174,14 +173,14 @@ public class PyMoveModuleMembersDialog extends PyBaseMoveDialog {
   @NotNull
   public List<PyElement> getSelectedTopLevelSymbols() {
     final Collection<PyModuleMemberInfo> selectedMembers = myMemberSelectionTable.getSelectedMemberInfos();
-    final List<PyElement> selectedElements = ContainerUtil.map(selectedMembers, info -> info.getMember());
+    final List<PyElement> selectedElements = ContainerUtil.map(selectedMembers, MemberInfoBase::getMember);
     return ContainerUtil.sorted(selectedElements, (e1, e2) -> PyPsiUtils.isBefore(e1, e2) ? -1 : 1);
   }
 
   @NotNull
   private static List<PyModuleMemberInfo> collectModuleMemberInfos(@NotNull PyFile pyFile) {
     final List<PyElement> moduleMembers = PyMoveModuleMembersHelper.getTopLevelModuleMembers(pyFile);
-    return ContainerUtil.mapNotNull(moduleMembers, element -> new PyModuleMemberInfo(element));
+    return ContainerUtil.mapNotNull(moduleMembers, PyModuleMemberInfo::new);
   }
 
   static class TopLevelSymbolsSelectionTable extends AbstractMemberSelectionTable<PyElement, PyModuleMemberInfo> {
index f1b9fa82f704ee2e682e7aad5cd8a7e87b9f2fc2..90c08728029180e8a2da78eb8d08e6d225fbbbac 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.jetbrains.python.refactoring.move.moduleMembers;
 
-import com.intellij.openapi.util.Condition;
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiUtilCore;
@@ -116,7 +115,7 @@ public class PyMoveSymbolProcessor {
     if (topLevelAtDestination.isEmpty()) {
       return null;
     }
-    return Collections.min(topLevelAtDestination, (e1, e2) -> PsiUtilCore.compareElementsByPosition(e1, e2));
+    return Collections.min(topLevelAtDestination, PsiUtilCore::compareElementsByPosition);
   }
 
   @Nullable
index b279c52f1b3b818362d609220039ea745973643d..c0da5618c7be7340d666c9e062967ef6c124fcfb 100644 (file)
@@ -66,15 +66,12 @@ public class PyMakeFunctionTopLevelTest extends PyTestCase {
     assertNotNull(destination);
     final String finalDestination = destination;
     try {
-      WriteCommandAction.runWriteCommandAction(myFixture.getProject(), new Runnable() {
-        @Override
-        public void run() {
-          if (function.getContainingClass() != null) {
-            new PyMakeMethodTopLevelProcessor(function, finalDestination).run();
-          }
-          else {
-            new PyMakeLocalFunctionTopLevelProcessor(function, finalDestination).run();
-          }
+      WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
+        if (function.getContainingClass() != null) {
+          new PyMakeMethodTopLevelProcessor(function, finalDestination).run();
+        }
+        else {
+          new PyMakeLocalFunctionTopLevelProcessor(function, finalDestination).run();
         }
       });
     }
@@ -156,7 +153,7 @@ public class PyMakeFunctionTopLevelTest extends PyTestCase {
 
   // PY-6637
   public void testLocalFunctionNonlocalReferencesInInnerFunction() {
-    runWithLanguageLevel(LanguageLevel.PYTHON30, () -> doTestSuccess());
+    runWithLanguageLevel(LanguageLevel.PYTHON30, this::doTestSuccess);
   }
 
   // PY-6637