Fix the order of methods passed to PyImplementMethodsQuickFix (PY-25906)

This commit is contained in:
Semyon Proshev
2017-10-19 14:36:24 +03:00
parent b0f3e6c20b
commit 672f71e67f
5 changed files with 61 additions and 51 deletions
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2017 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 com.jetbrains.python.inspections;
import com.intellij.codeInspection.LocalInspectionToolSession;
@@ -30,8 +16,7 @@ import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import static com.jetbrains.python.psi.PyUtil.as;
@@ -61,7 +46,7 @@ public class PyAbstractClassInspection extends PyInspection {
if (isAbstract(pyClass)) {
return;
}
final Set<PyFunction> toImplement = new HashSet<>(PyOverrideImplementUtil.getAllSuperAbstractMethods(pyClass, myTypeEvalContext));
final List<PyFunction> toImplement = PyOverrideImplementUtil.getAllSuperAbstractMethods(pyClass, myTypeEvalContext);
final ASTNode nameNode = pyClass.getNameNode();
if (!toImplement.isEmpty() && nameNode != null) {
registerProblem(nameNode.getPsi(),
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2017 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 com.jetbrains.python.inspections.quickfix;
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
@@ -30,14 +16,14 @@ import com.jetbrains.python.psi.PyFunction;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
import java.util.Collection;
public class PyImplementMethodsQuickFix extends LocalQuickFixOnPsiElement {
@NotNull
private final Set<PyFunction> myToImplement;
private final Collection<PyFunction> myToImplement;
public PyImplementMethodsQuickFix(@NotNull PyClass cls, @NotNull Set<PyFunction> toImplement) {
public PyImplementMethodsQuickFix(@NotNull PyClass cls, @NotNull Collection<PyFunction> toImplement) {
super(cls);
myToImplement = toImplement;
}
@@ -0,0 +1,20 @@
from abc import abstractmethod, ABCMeta
class Abstract:
__metaclass__ = ABCMeta
@abstractmethod
def foo0(self):
pass
@abstractmethod
def foo1(self):
pass
def bar(self):
pass
class F<caret>oo(Abstract):
pass
@@ -0,0 +1,25 @@
from abc import abstractmethod, ABCMeta
class Abstract:
__metaclass__ = ABCMeta
@abstractmethod
def foo0(self):
pass
@abstractmethod
def foo1(self):
pass
def bar(self):
pass
class Foo(Abstract):
def foo0(self):
pass
def foo1(self):
pass
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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.
*/
// Copyright 2000-2017 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 com.jetbrains.python;
import com.intellij.codeInsight.intention.IntentionAction;
@@ -609,6 +595,14 @@ public class PyQuickFixTest extends PyTestCase {
true, true);
}
public void testImplementAbstractOrder() {
doInspectionTest("ImplementAbstractOrder.py",
PyAbstractClassInspection.class,
PyBundle.message("QFIX.NAME.implement.methods"),
true,
true);
}
public void testRemovingUnderscoresInNumericLiterals() {
myFixture.configureByText(PythonFileType.INSTANCE, "1_0_0");