mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
IDEA-161007 Add new inspection to make comparator lambdas use Comparator.comparing() combinators (Currently only simple comparators supported)
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with Comparator.comparing" "true"
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
String getName();
|
||||
}
|
||||
|
||||
void sort(List<Person> persons) {
|
||||
persons.sort(Comparator.comparing(Person::getName));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with Comparator.comparing" "false"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
String getName();
|
||||
}
|
||||
|
||||
void sort(List<Person> persons) {
|
||||
persons.sort((p1, p2) -> p2.getNam<caret>e().compareTo(p1.getName()));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with Comparator.comparing" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
String getName();
|
||||
}
|
||||
|
||||
void sort(List<Person> persons) {
|
||||
persons.sort((p1, p2) -> p1.getNam<caret>e().compareTo(p2.getName()));
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInspection.ComparatorCombinatorsInspection;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class ComparatorCombinatorsInspectionTest extends LightQuickFixParameterizedTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{
|
||||
new ComparatorCombinatorsInspection()
|
||||
};
|
||||
}
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/comparatorCombinators";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user