redundant cast: move test data; ignore casts to invoke @NotNull methods; ignore suspicious collections method calls

This commit is contained in:
anna
2011-06-24 15:22:54 +04:00
parent b5df7559da
commit d42ef3a864
102 changed files with 1248 additions and 82 deletions
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>AmbigousParm1.java</file>
<line>11</line>
<description>Casting c to A is redundant</description>
</problem>
</problems>
@@ -0,0 +1,13 @@
interface A {}
interface B {}
class C implements A, B {}
public class AmbigousParameter {
public void ua(A a) {}
public void caller(C c) {
ua((A)c);
}
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>AmbigousParm2.java</file>
<line>14</line>
<description>Casting c to A is redundant</description>
</problem>
<problem>
<file>AmbigousParm2.java</file>
<line>15</line>
<description>Casting a to A is redundant</description>
</problem>
</problems>
@@ -0,0 +1,17 @@
interface A {}
interface B {}
class C implements A, B {}
public class AmbigousParameter {
void m(A a) {}
void m(B b) {}
public void caller(C c) {
m((A)c);
m((A)null);
A a = (A)c;
m((A)a);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>AmbigousParm3.java</file>
<line>13</line>
<description>Casting null to A is redundant</description>
</problem>
</problems>
@@ -0,0 +1,15 @@
interface A {}
interface B {}
public class AmbigousParameter {
public void f(A a) {}
public void f(B b) {}
public void f(Object o) {}
public void g(Object o) {}
public void caller() {
f((A)null);
g((A)null);
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,8 @@
import javax.swing.*;
import java.awt.*;
public class AmbigousParameter {
public void caller() {
new JDialog((Frame)null, "Title", true);
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,8 @@
import javax.swing.*;
import java.awt.*;
public class AmbigousParameter {
public void caller() {
new JDialog( ((Frame)null), "Title", true);
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,11 @@
package com;
public class Test {
static void f(Object s, Object o){}
static void f(String s, String o){}
void foo(){
Object o;
f((String)o, (String)o);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Assignment1.java</file>
<line>4</line>
<description>Casting null to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,6 @@
class Test{
static f(){
Object o;
o = (String)null;
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>4</line>
<description>Casting o to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,6 @@
public class Test {
public boolean foo() {
Object o = null;
return (String) o == null;
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,12 @@
class Y {
int size = 4;
}
class Z extends Y {
int size = 5;
public static void main(String[] args) {
Z z = new Z();
System.out.println("z.size = " + ((Y)z).size);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>DoubleCast1.java</file>
<line>7</line>
<description>Casting o to List is redundant</description>
</problem>
</problems>
@@ -0,0 +1,9 @@
import java.util.List;
import java.util.ArrayList;
class Test{
static f(){
Object o;
ArrayList list = (ArrayList)(List)o;
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>DoubleCast2.java</file>
<line>7</line>
<description>Casting o to List is redundant</description>
</problem>
</problems>
@@ -0,0 +1,9 @@
import java.util.List;
import java.util.ArrayList;
class Test{
static f(){
Object o;
ArrayList list = (ArrayList)((List)o);
}
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>DoubleCast3.java</file>
<line>4</line>
<description>Casting '(String) o' to String is redundant</description>
</problem>
<problem>
<file>DoubleCast3.java</file>
<line>4</line>
<description>Casting 'o' to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,6 @@
class Test{
static f(){
Object o;
String s = (String) (String) o;
}
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>DoubleCast4.java</file>
<line>4</line>
<description>Casting '(String) o' to Object is redundant</description>
</problem>
<problem>
<file>DoubleCast4.java</file>
<line>4</line>
<description>Casting 'o' to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,6 @@
class Test{
static f(){
Object o;
Object o2 = (Object) (String) o;
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,5 @@
class Test{
static f(double a){
double b = (double)(int)a / 100;
}
}
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,16 @@
class A {
void foo() throws Exception {}
}
class B extends A {
void foo() {
}
}
class C {
{
A a = new B();
((B) a).foo();
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>A.java</file>
<line>3</line>
<description>Casting 'array' to String[] is redundant</description>
</problem>
</problems>
@@ -0,0 +1,9 @@
public class Test {
public void foo(Object[] array) {
((String[]) array)[0] = " ";
}
public void bar(String[] array) {
((Object[]) array)[0] = new Object();
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>A.java</file>
<line>13</line>
<description>Casting prices.get(null) to BidAsk is redundant</description>
</problem>
</problems>
@@ -0,0 +1,15 @@
class Getter {
BidAsk get(String s) {
return null;
}
}
class BidAsk {
public Object getOpenQuote;
}
public class A {
static Object f(Getter prices) {
return System.currentTimeMillis() == 2.0 ? ((BidAsk) prices.get(null)).getOpenQuote : null;
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>A.java</file>
<line>3</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;null&lt;/code&gt; to &lt;code&gt;String&lt;/code&gt; is redundant</description>
</problem>
</problems>
@@ -0,0 +1,5 @@
class A {
{
String s = true ? "" : (String) null; //cast is needed
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,12 @@
class Entry {
private final Object obj;
protected Entry(Directory parent) {
obj = ((Entry)parent).obj; //cast is needed because 'obj' is not visible with 'Directory' access class
}
}
class Directory extends Entry {
public Directory(Directory parent) {
super(parent);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Initializer1.java</file>
<line>3</line>
<description>Casting null to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,5 @@
class Test{
static f(){
Object o = (String)null;
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,5 @@
class A{
void f(){
double d = (double)1 / 5;
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>CastTest.java</file>
<line>7</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;ct1&lt;/code&gt; to &lt;code&gt;CastTest&lt;/code&gt; is redundant</description>
</problem>
</problems>
@@ -0,0 +1,9 @@
class CastTest
{
public static void main (String[] args) throws CloneNotSupportedException
{
CastTest ct1 = new CastTest ();
// The cast of ct1 is obviously redundant (although the cast of the result is necessary)
CastTest ct2 = (CastTest) ((CastTest)ct1).clone();
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>NestedThings.java</file>
<line>13</line>
<description>Casting "" to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,26 @@
class XXX {
String f() {
new Runnable() {
public void run() {
new Runnable() {
public void run() {
new Runnable() {
public void run() {
new Runnable() {
public void run() {
new Runnable() {
public void run() {
String s = (String)"";
}
};
}
};
}
};
}
};
}
};
return "";
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>New1.java</file>
<line>5</line>
<description>Casting null to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,7 @@
class Test{
Test(Object o){}
static f(){
new Test((String)null);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>OneOfTwo.java</file>
<line>8</line>
<description>Casting o to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,10 @@
package com;
public class Test {
static void f(String s, Object o){}
void foo(){
Object o;
f((String)o, (String)o);
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,9 @@
import java.awt.*;
public class Test {
void foo(){
Component c = null;
((Frame) c).show();
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,21 @@
class RedundantCastProblem {
public abstract static class Top {
public String f(Object o) {
return "Top.f(Object)";
}
}
public static class Sub extends Top {
public String f(String s) {
return "Middle.f(String)";
}
}
public static void main(String[] args) {
Sub sub = new Sub();
String aString = "";
System.out.println(((Top)sub).f(aString));
System.out.println(sub.f(aString));
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>3</line>
<description>Casting new Test() to Test is redundant</description>
</problem>
</problems>
@@ -0,0 +1,5 @@
public class Test {
public void foo(Test t) {
foo(((Test) new Test()));
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,15 @@
public class Test {
class Super {
Object foo() { return new Object(); }
}
class Sub extends Super{
String foo() { return ""; }
}
public String get(final Super obj) {
if (obj instanceof Sub) {
return ((Sub)obj).foo();
} else {
return "The value is " + obj.foo();
}
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>3</line>
<description>Casting s to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,5 @@
public class Test {
public void test(Object s) {
Object o = ((String) s);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>7</line>
<description>Casting null to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,9 @@
public class Test {
void foo(String msg){}
void foo(Object o){}
void method(){
foo((String)null);
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>4</line>
<description>Casting v to short is redundant</description>
</problem>
</problems>
@@ -0,0 +1,7 @@
class Test{
short foo(){
short v = 0;
short s = (short)v;
return s;
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,8 @@
class A{
String toHex(int i) {}
String toHex(short i) {}
void f(){
String result = toHex((short)'i');
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,5 @@
class A{
void f(){
double d = (int) 1.5;
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>VirtualMethod1.java</file>
<line>12</line>
<description>Casting a B is redundant</description>
</problem>
</problems>
@@ -0,0 +1,14 @@
class A{
void f(){}
}
class B extends A{
void f(){}
}
class Test{
static foo(){
A a;
((B)a).f();
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -0,0 +1,14 @@
class A{
private void f(){}
}
class B extends A{
void f(){}
}
class Test{
static foo(){
A a;
((B)a).f();
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>VirtualMethod3.java</file>
<line>4</line>
<description>Casting o to String is redundant</description>
</problem>
</problems>
@@ -0,0 +1,6 @@
class Test{
static foo(){
Object o;
boolean res = ((String)o).equals(null);
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,7 @@
//This is a test for JDK_15 LanguageLevel
public class Test {
void foo () {
int x = 4;
((Integer) x).toString();
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>3</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;&quot;&quot;&lt;/code&gt; to &lt;code&gt;String&lt;/code&gt; is redundant</description>
</problem>
</problems>
@@ -0,0 +1,7 @@
enum Test {
A((String) "");
Test(String s) {
}
}
@@ -0,0 +1,14 @@
<problems>
<problem>
<file>Test.java</file>
<line>11</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;this&lt;/code&gt; to &lt;code&gt;CastPreventsNPEDetection&lt;/code&gt; is redundant</description>
</problem>
<problem>
<file>Suspicious.java</file>
<line>9</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;str&lt;/code&gt; to &lt;code&gt;String&lt;/code&gt; is redundant</description>
</problem>
</problems>
@@ -0,0 +1,12 @@
import java.util.Map;
public class Suspicious {
Map<String, String> map;
void f(Object s){
String str = (String) s;
map.remove((String)s);
map.remove((String)str);
}
}
@@ -0,0 +1,21 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class CastPreventsNPEDetection {
@Nullable Object getParent() {
return null;
}
void f() {
((ChildCastImpl)this).getParent().toString();
((CastPreventsNPEDetection)this).getParent().toString();
}
}
class ChildCastImpl extends CastPreventsNPEDetection {
@NotNull
@Override
Object getParent() {
return super.getParent(); //To change body of overridden methods use File | Settings | File Templates.
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -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];
}
}
public 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,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,32 @@
import java.util.HashSet;
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 = new HashSet<String>();
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,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>31</line>
<description>Casting 'null' to 'Set&lt;String&gt;' is redundant</description>
</problem>
<problem>
<file>Test.java</file>
<line>31</line>
<description>Casting 'null' to 'Set&lt;String&gt;' is redundant</description>
</problem>
</problems>
@@ -0,0 +1,32 @@
import java.util.HashSet;
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 = new HashSet<String>();
final Pair<Set<String>, Set<String>> x = Boolean.TRUE.booleanValue()
? Pair.create(strings, strings)
: Pair.create(((Set<String>) null), (Set<String>) null); //both casts are marked, but one is required for correct inference
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Casting null to Class[] is redundant</description>
</problem>
<problem>
<file>Test.java</file>
<line>9</line>
<description>Casting null to Class[] is redundant</description>
</problem>
</problems>
@@ -0,0 +1,11 @@
class Test {
void f(Class... classes) {
}
void g() {
f(((Class[])null));
f(((Class)null));
f(((Class)null),
((Class)null));
}
}
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,11 @@
import java.util.Map;
import java.util.Properties;
public class Main {
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
Map<String, String> map = (Map) properties;
System.out.println(map);
}
}
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,13 @@
import java.util.List;
class RedundantCasts {
List<TranslatingCompiler> myTranslators;
void t() {
b((List<Compiler>) (List)myTranslators);
}
void b(List<Compiler> l){}
}
interface Compiler{}
interface TranslatingCompiler extends Compiler{}
@@ -0,0 +1,16 @@
interface GenericValue<T> {
T getValue();
}
interface GenericAttValue<T> extends GenericValue<T> {
}
interface Property {
GenericAttValue<Object> getValue();
}
class RedCast {
public GenericValue<String> getDataSourceName(Property property) {
return (GenericValue) property.getValue();
}
}
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>WrapperToPrimitiveCast.java</file>
<line>8</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;J&lt;/code&gt; to &lt;code&gt;int&lt;/code&gt; is redundant</description>
</problem>
<problem>
<file>WrapperToPrimitiveCast.java</file>
<line>9</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;I&lt;/code&gt; to &lt;code&gt;int&lt;/code&gt; is redundant</description>
</problem>
<problem>
<file>WrapperToPrimitiveCast.java</file>
<line>12</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;p&lt;/code&gt; to &lt;code&gt;Integer&lt;/code&gt; is redundant</description>
</problem>
<problem>
<file>WrapperToPrimitiveCast.java</file>
<line>15</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;p&lt;/code&gt; to &lt;code&gt;Integer&lt;/code&gt; is redundant</description>
</problem>
<problem>
<file>WrapperToPrimitiveCast.java</file>
<line>24</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;lnumber&lt;/code&gt; to &lt;code&gt;long&lt;/code&gt; is redundant</description>
</problem>
<problem>
<file>WrapperToPrimitiveCast.java</file>
<line>24</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant type cast</problem_class>
<description>Casting &lt;code&gt;lnumber&lt;/code&gt; to &lt;code&gt;long&lt;/code&gt; is redundant</description>
</problem>
</problems>
@@ -0,0 +1,26 @@
public 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 = (int)J;
System.out.println((int) I == j);
int p = 555555;
Integer W = (Integer) p;
System.out.println((Integer) p == W);
int w = W;
System.out.println((Integer) 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 = (long) (long) lnumber;
}
}
@@ -0,0 +1,47 @@
package com.intellij.codeInspection;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.redundantCast.RedundantCastInspection;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.InspectionTestCase;
public class RedundantCast15Test extends InspectionTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
}
private void doTest() throws Exception {
final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(new RedundantCastInspection());
doTest("redundantCast/generics/" + getTestName(false), tool, "java 1.5");
}
public void testBoxingInRef() throws Exception { doTest(); }
public void testInference1() throws Exception { doTest(); }
public void testInference2() throws Exception { doTest(); }
public void testInference3() throws Exception { doTest(); }
public void testNullInVarargsParameter() throws Exception { doTest(); }
public void testWrapperToPrimitiveCast() throws Exception { doTest(); }
public void testEnumConstant() throws Exception { doTest(); }
public void testRawCast() throws Exception { doTest();}
public void testRawCastsToAvoidIncompatibility() throws Exception { doTest();}
public void testIgnore() throws Exception {
final RedundantCastInspection castInspection = new RedundantCastInspection();
castInspection.IGNORE_ANNOTATED_METHODS = true;
castInspection.IGNORE_SUSPICIOUS_METHOD_CALLS = true;
final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(castInspection);
doTest("redundantCast/generics/" + getTestName(false), tool, "java 1.5");
}
}
@@ -0,0 +1,93 @@
package com.intellij.codeInspection;
import com.intellij.codeInspection.redundantCast.RedundantCastInspection;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.InspectionTestCase;
public class RedundantCastTest extends InspectionTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_3);
}
private void doTest() throws Exception {
doTest("redundantCast/" + getTestName(false), new RedundantCastInspection());
}
public void testAmbigousParm1() throws Exception { doTest(); }
public void testAmbigousParm2() throws Exception { doTest(); }
public void testAmbigousParm3() throws Exception { doTest(); }
public void testAmbigousParm4() throws Exception { doTest(); }
public void testAmbigousParm5() throws Exception { doTest(); }
public void testOneOfTwo() throws Exception { doTest(); }
public void testAnyOfTwo() throws Exception { doTest(); }
public void testNew1() throws Exception { doTest(); }
public void testAssignment1() throws Exception { doTest(); }
public void testInitializer1() throws Exception { doTest(); }
public void testShortToShort() throws Exception { doTest(); }
public void testVirtualMethod1() throws Exception { doTest(); }
public void testVirtualMethod2() throws Exception { doTest(); }
public void testVirtualMethod3() throws Exception { doTest(); }
public void testDoubleCast1() throws Exception { doTest(); }
public void testDoubleCast2() throws Exception { doTest(); }
public void testDoubleCast3() throws Exception { doTest(); }
public void testDoubleCast4() throws Exception { doTest(); }
public void testDoubleCast5() throws Exception { doTest(); }
public void testShortVsInt() throws Exception { doTest(); }
public void testTruncation() throws Exception { doTest(); }
public void testIntToDouble() throws Exception { doTest(); }
public void testSCR6907() throws Exception { doTest(); }
public void testSCR11555() throws Exception { doTest(); }
public void testSCR13397() throws Exception { doTest(); }
public void testSCR14502() throws Exception { doTest(); }
public void testSCR14559() throws Exception { doTest(); }
public void testSCR15236() throws Exception { doTest(); }
public void testComparingToNull() throws Exception { doTest(); }
public void testInaccessible() throws Exception { doTest(); }
public void testInConditional() throws Exception { doTest(); }
public void testDifferentFields() throws Exception { doTest(); }
public void testNestedThings() throws Exception { doTest(); }
public void testIDEADEV6818() throws Exception { doTest(); }
public void testIDEADEV15170() throws Exception { doTest(); }
public void testIDEADEV25675() throws Exception { doTest(); }
public void testNestedCast() throws Exception { doTest(); }
}