mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RedundantCast15: missing testdata files restored
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
//This is a test for JDK_15 LanguageLevel
|
||||
class Test {
|
||||
private Integer foo(String s, Integer i) {
|
||||
return s == null ? i : (Integer)2;
|
||||
}
|
||||
|
||||
private int foo1(String s, Integer i) {
|
||||
return s == null ? i : (<warning descr="Casting '2' to 'Integer' is redundant">Integer</warning>)2;
|
||||
}
|
||||
}
|
||||
|
||||
class RedundantCastTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Integer foo = 5;
|
||||
Integer bar = null;
|
||||
print(args == null || args.length == 0 ? bar : (Integer) 1);
|
||||
int i = args == null || args.length == 0 ? bar : (<warning descr="Casting '1' to 'Integer' is redundant">Integer</warning>) 1;
|
||||
}
|
||||
|
||||
private static void print(Integer i) {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//This is a test for JDK_15 LanguageLevel
|
||||
class Test {
|
||||
void foo () {
|
||||
int x = 4;
|
||||
((Integer) x).toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class TestCasting
|
||||
{
|
||||
public void testRedundantCast() throws Exception
|
||||
{
|
||||
Object o = getObject();
|
||||
double d = 0.0;
|
||||
|
||||
if( o instanceof Integer )
|
||||
{
|
||||
d = (double) (Integer)o;
|
||||
}
|
||||
|
||||
System.out.println( "d = " + d );
|
||||
}
|
||||
|
||||
private Object getObject()
|
||||
{
|
||||
return new Integer(42);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public class RedundantCast{
|
||||
void m(IOEx e) throws IOEx {
|
||||
throw <error descr="Inconvertible types; cannot cast 'RedundantCast.IOEx' to 'RedundantCast.FileNotFoundEx'">(<warning descr="Casting 'e' to 'FileNotFoundEx' is redundant">FileNotFoundEx</warning>)e</error>;
|
||||
}
|
||||
|
||||
void foo(RuntimeException e) {
|
||||
throw (<warning descr="Casting 'e' to 'Ex' is redundant">Ex</warning>)e;
|
||||
}
|
||||
|
||||
static class Ex extends RuntimeException {}
|
||||
static class IOEx extends Exception {}
|
||||
static class FileNotFoundEx extends Exception {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
{
|
||||
Map<Number, String> map1 = null;
|
||||
Map<Integer, String> map2 = (Map<Integer, String>) (Map<?, ?>) map1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class A {
|
||||
static String doit(A a) {
|
||||
String d = ((<warning descr="Casting 'a' to 'AA' is redundant">AA</warning>)a).danuna();
|
||||
String notNull = ((AA)a).doadd();
|
||||
return notNull + d;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String doadd() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String danuna() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
class AA extends A {
|
||||
@NotNull
|
||||
String doadd() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
String danuna() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
enum Test {
|
||||
A((<warning descr="Casting '\"\"' to 'String' is redundant">String</warning>) "");
|
||||
|
||||
Test(String s) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class RedundantCast {
|
||||
void redundantCasts() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String s : (<warning descr="Casting 'list' to 'ArrayList<String>' is redundant">ArrayList<String></warning>) list) {}
|
||||
|
||||
Object o = new ArrayList<>();
|
||||
for (String s : (ArrayList<String>) o) {}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class SomeClass {
|
||||
public void test() {
|
||||
List<?> objects = new ArrayList<>();
|
||||
for (String value : (Iterable<? extends String>) objects) {
|
||||
System.out.println(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class B { }
|
||||
class A extends B { }
|
||||
|
||||
class C {
|
||||
void m(Class<? extends A> c) {}
|
||||
|
||||
void x(B b) {
|
||||
m(((A)b).getClass());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class RedundantIntCast
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
Integer i = 8;
|
||||
method((int)i, 1); // int cast is marked as redundant
|
||||
}
|
||||
|
||||
static void method(Object o, Object o1) {
|
||||
System.out.println("this method works on objects");
|
||||
}
|
||||
|
||||
static void method(int i, int i1) {
|
||||
System.out.println("this method works on ints");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.Map;
|
||||
class Test2 {
|
||||
public String s;
|
||||
public void maina(Object key, Map parameters) {
|
||||
s = ((String[]) parameters.get(key))[0];
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
static class SomeClass {
|
||||
public <T> T getX() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//cast is needed for 'String' to be infered!
|
||||
System.getProperty((String)new SomeClass().getX());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.util.Set;
|
||||
|
||||
final class Pair<A, B> {
|
||||
public final A first;
|
||||
public final B second;
|
||||
|
||||
public Pair(A first, B second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public final A getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public final B getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
public static <A, B> Pair<A, B> create(A first, B second) {
|
||||
return new Pair<A, B>(first, second);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
final Set<String> strings = null;
|
||||
final Pair<Set<String>, Set<String>> x = Boolean.TRUE.booleanValue()
|
||||
? Pair.create(strings, strings)
|
||||
: Pair.create(((Set<String>) null), (Set<String>) null); //these casts are not redundant
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.util.Set;
|
||||
|
||||
final class Pair<A, B> {
|
||||
public final A first;
|
||||
public final B second;
|
||||
|
||||
public Pair(A first, B second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public final A getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public final B getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
public static <A> Pair<A, A> create(A first, A second) {
|
||||
return new Pair<A, A>(first, second);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
final Set<String> strings = null;
|
||||
final Pair<Set<String>, Set<String>> x = Boolean.TRUE.booleanValue()
|
||||
? Pair.create(strings, strings)
|
||||
: Pair.create(((<warning descr="Casting 'null' to 'Set<String>' is redundant">Set<String></warning>) null), (<warning descr="Casting 'null' to 'Set<String>' is redundant">Set<String></warning>) null); //both casts are marked, but one is required for correct inference
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
class Test {
|
||||
|
||||
{
|
||||
f((Bar) getComponent());
|
||||
f1((<warning descr="Casting 'getComponent()' to 'Bar' is redundant">Bar</warning>) getComponent());
|
||||
Bar b = (<warning descr="Casting 'getComponent()' to 'Bar' is redundant">Bar</warning>) getComponent();
|
||||
}
|
||||
|
||||
private <J extends Bar> void f(J j) {}
|
||||
|
||||
private <J> void f1(J j) {}
|
||||
|
||||
private <T> T getComponent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
static class Bar {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class RedundantCast {
|
||||
boolean redundantCasts(Object o) {
|
||||
int p = 0;
|
||||
if ((Number)p instanceof Integer) {}
|
||||
return (<warning descr="Casting 'o' to 'List' is redundant">List</warning>)o instanceof ArrayList;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
void f(Class... classes) {
|
||||
}
|
||||
|
||||
void g() {
|
||||
f(((Class[])null));
|
||||
f(((Class)null));
|
||||
f(((<warning descr="Casting 'null' to 'Class' is redundant">Class</warning>)null),
|
||||
((<warning descr="Casting 'null' to 'Class' is redundant">Class</warning>)null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Properties properties = new Properties();
|
||||
|
||||
Map<String, String> map = (Map) properties;
|
||||
System.out.println(map);
|
||||
}
|
||||
}
|
||||
|
||||
interface I {}
|
||||
class C implements I {}
|
||||
class U {
|
||||
void foo() {
|
||||
List<C> listOfC = null;
|
||||
List<I> listOfI = (List) listOfC;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
{
|
||||
class TypedQuery<T> {}
|
||||
class TemporalDataDTO<K> {}
|
||||
class FOLDER_ID {}
|
||||
|
||||
TypedQuery<TemporalDataDTO> h = null;
|
||||
TypedQuery<TemporalDataDTO<FOLDER_ID>> typedQuery = (TypedQuery<TemporalDataDTO<FOLDER_ID>>) (TypedQuery<?>)h;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.*;
|
||||
|
||||
class RedundantCast{
|
||||
<T> void foo2(List<Object[]> x) {
|
||||
for (Object[] l : x) {
|
||||
String[] s = (String[]) l;
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
abstract class Foo<T extends Foo<T>> {
|
||||
private int field;
|
||||
|
||||
public int bar(T t){
|
||||
return ((Foo<T>)t).field;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
Integer J = 4;
|
||||
Integer I = new Integer(4);
|
||||
|
||||
System.out.println(I == J);
|
||||
System.out.println((int) I == J);
|
||||
int j = (<warning descr="Casting 'J' to 'int' is redundant">int</warning>)J;
|
||||
System.out.println((<warning descr="Casting 'I' to 'int' is redundant">int</warning>) I == j);
|
||||
|
||||
int p = 555555;
|
||||
Integer W = (<warning descr="Casting 'p' to 'Integer' is redundant">Integer</warning>) p;
|
||||
System.out.println((Integer) p == W);
|
||||
int w = W;
|
||||
System.out.println((<warning descr="Casting 'p' to 'Integer' is redundant">Integer</warning>) p == w);
|
||||
|
||||
Integer test = 10;
|
||||
double d = ((double)test/100);
|
||||
|
||||
Double number = Double.valueOf(3);
|
||||
long integerPart = (long) (double) number;
|
||||
|
||||
Long lnumber = Long.valueOf(3);
|
||||
long integerPartL = (<warning descr="Casting '(long)lnumber' to 'long' is redundant">long</warning>) (<warning descr="Casting 'lnumber' to 'long' is redundant">long</warning>) lnumber;
|
||||
}
|
||||
}
|
||||
|
||||
class Foo<T> {
|
||||
T foo() {
|
||||
return (T)(Object)1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user