[java-intentions] IDEA-299075 Better quick-fixes when generic method call has mismatched type

GitOrigin-RevId: 6fa73efcfb43cd7da05f95ef66c2cd40a3dc1a14
This commit is contained in:
Tagir Valeev
2022-08-01 18:12:10 +02:00
committed by intellij-monorepo-bot
parent 46c6cb94ad
commit 8a9959167b
33 changed files with 512 additions and 23 deletions

View File

@@ -0,0 +1,8 @@
// "Replace 'Double.class' with 'Integer.class'" "true-preview"
class Demo {
native static <T> T tryCast(Object obj, Class<T> clazz);
void test(Object obj) {
Integer i = tryCast(obj, Integer.class);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace 'Integer.class' with 'String.class'" "true-preview"
import java.util.*;
class Demo {
native static <T> List<T> filterIsInstance(Collection<?> collection, Class<? extends T> aClass);
void test(List<?> list) {
List<String> strings = filterIsInstance(list, String.class);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace 'Integer.class' with 'String.class'" "true-preview"
import java.util.*;
class Demo {
native static <T> List<T> filterIsInstance(Collection<?> collection, Class<? extends T> aClass);
void test(List<?> list) {
List<String> stringsSync = Collections.synchronizedList(filterIsInstance(list, String.class));
}
}

View File

@@ -0,0 +1,8 @@
// "Cast to 'long'" "true-preview"
import java.util.function.*;
class Demo {
void test(Function<String, String> input) {
Function<String, Long> result = input.andThen(s -> (long) s.length());
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.*;
class Demo {
void test() {
List<String> stringList = Collections.nCopies(10, String.valueOf(20));
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.*;
class Demo {
void test() {
List<Set<String>> nCopiesNested = Collections.nCopies(10, Set.of(String.valueOf(20)));
}
}

View File

@@ -0,0 +1,9 @@
// "Adapt using 'new File()'" "true-preview"
import java.util.*;
import java.io.File;
class Demo {
void test(int value) {
Set<File> file = Set.of(new File("/etc/passwd"));
}
}

View File

@@ -0,0 +1,8 @@
// "Cast to 'long'" "true-preview"
import java.util.*;
class Demo {
void test() {
Optional<Long> opt = Optional.of(123L);
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.*;
class Demo {
void test(int value) {
Optional<String> optStr = Optional.of(String.valueOf(value));
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.stream.*;
class Demo {
void test() {
Stream<String> stream = Stream.generate(() -> String.valueOf(Math.random()));
}
}

View File

@@ -0,0 +1,8 @@
// "Adapt using 'Math.toIntExact()'" "true-preview"
import java.util.*;
class Demo {
void test(List<?> list) {
List<Integer> intList = Collections.singletonList(Math.toIntExact(123L));
}
}

View File

@@ -0,0 +1,8 @@
// "Adapt using 'Math.toIntExact()'" "true-preview"
import java.util.*;
class Demo {
void test(List<?> list) {
List<Integer> intList2 = Collections.unmodifiableList(Collections.singletonList(Math.toIntExact(123L)));
}
}

View File

@@ -0,0 +1,8 @@
// "Replace 'Double.class' with 'Integer.class'" "true-preview"
class Demo {
native static <T> T tryCast(Object obj, Class<T> clazz);
void test(Object obj) {
Integer i = <caret>tryCast(obj, Double.class);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace 'Integer.class' with 'String.class'" "true-preview"
import java.util.*;
class Demo {
native static <T> List<T> filterIsInstance(Collection<?> collection, Class<? extends T> aClass);
void test(List<?> list) {
List<String> strings = <caret>filterIsInstance(list, Integer.class);
}
}

View File

@@ -0,0 +1,10 @@
// "Replace 'Integer.class' with 'String.class'" "true-preview"
import java.util.*;
class Demo {
native static <T> List<T> filterIsInstance(Collection<?> collection, Class<? extends T> aClass);
void test(List<?> list) {
List<String> stringsSync = <caret>Collections.synchronizedList(filterIsInstance(list, Integer.class));
}
}

View File

@@ -0,0 +1,8 @@
// "Cast to 'long'" "true-preview"
import java.util.function.*;
class Demo {
void test(Function<String, String> input) {
Function<String, Long> result = input.andThen(s -> <caret>s.length());
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.*;
class Demo {
void test() {
List<String> stringList = Collections.<caret>nCopies(10, 20);
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.*;
class Demo {
void test() {
List<Set<String>> nCopiesNested = Collections.<caret>nCopies(10, Set.of(20));
}
}

View File

@@ -0,0 +1,9 @@
// "Adapt using 'new File()'" "true-preview"
import java.util.*;
import java.io.File;
class Demo {
void test(int value) {
Set<File> file = Set.of("/etc/<caret>passwd");
}
}

View File

@@ -0,0 +1,8 @@
// "Cast to 'long'" "true-preview"
import java.util.*;
class Demo {
void test() {
Optional<Long> opt = <caret>Optional.of(123);
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.*;
class Demo {
void test(int value) {
Optional<String> optStr = <caret>Optional.of(value);
}
}

View File

@@ -0,0 +1,8 @@
// "Wrap using 'String.valueOf()'" "true-preview"
import java.util.stream.*;
class Demo {
void test() {
Stream<String> stream = Stream.generate(() -> <caret>Math.random());
}
}

View File

@@ -0,0 +1,8 @@
// "Adapt using 'Math.toIntExact()'" "true-preview"
import java.util.*;
class Demo {
void test(List<?> list) {
List<Integer> intList = <caret>Collections.singletonList(123L);
}
}

View File

@@ -0,0 +1,8 @@
// "Adapt using 'Math.toIntExact()'" "true-preview"
import java.util.*;
class Demo {
void test(List<?> list) {
List<Integer> intList2 = <caret>Collections.unmodifiableList(Collections.singletonList(123L));
}
}