fixture-based NullableStuffInspectionTest

This commit is contained in:
peter
2014-02-10 17:25:33 +01:00
parent 3104edd1b9
commit 4757fc901f
18 changed files with 244 additions and 598 deletions

View File

@@ -0,0 +1,67 @@
import org.jetbrains.annotations.NotNull;
class B {
@NotNull
B b;
public B <warning descr="Getter for @NotNull field might be annotated @NotNull itself">getB</warning>() {
return b;
}
public void setB(B <warning descr="Setter parameter for @NotNull field might be annotated @NotNull itself">b</warning>) {
this.b = b;
}
@NotNull
private String bug = "true";
public boolean getBug() {
return Boolean.valueOf(bug);
}
}
class C {
@NotNull C c;
C(C <warning descr="Constructor parameter for @NotNull field might be annotated @NotNull itself">c</warning>) {
this.c = c;
}
C(@<error descr="Cannot resolve symbol 'Nullable'">Nullable</error> C <warning descr="Constructor parameter for @NotNull field might be annotated @NotNull itself">c</warning>, int i) {
this.c = c;
}
@<error descr="Cannot resolve symbol 'Nullable'">Nullable</error>
public C <warning descr="Getter for @NotNull field might be annotated @NotNull itself">getC</warning>() {
return c;
}
public void setC(@<error descr="Cannot resolve symbol 'Nullable'">Nullable</error> C <warning descr="Setter parameter for @NotNull field might be annotated @NotNull itself">c</warning>) {
this.c = c;
}
@NotNull C c1;
@org.jetbrains.annotations.Nullable
public C getC1() {
if (c1 != null) {
return null;
}
return c1;
}
}
class D {
@<error descr="Cannot resolve symbol 'Nullable'">Nullable</error> Long myL;
D(long l) {
myL = l;
}
}
class E {
final @NotNull C c;
E(C <warning descr="Constructor parameter for @NotNull field might be annotated @NotNull itself">c</warning>) {
this.c = c;
}
}

View File

@@ -5,7 +5,7 @@ class Test {
@Nullable private final String baseFile1;
public Test(@NotNull String baseFile) {
public Test(@NotNull String <warning descr="Constructor parameter for @Nullable field is annotated @NotNull">baseFile</warning>) {
this.baseFile = baseFile;
this.baseFile1 = null;
}

View File

@@ -0,0 +1,53 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
abstract class P2 {
<warning descr="Overridden methods are not annotated">@NotNull</warning>
String foo(<warning descr="Overridden method parameters are not annotated">@NotNull</warning> <error descr="Cannot resolve symbol 'P'">P</error> p) {
return "";
}
}
class PPP extends P2 {
String <warning descr="Not annotated method overrides method annotated with @NotNull">foo</warning>(<error descr="Cannot resolve symbol 'P'">P</error> <warning descr="Not annotated parameter overrides @NotNull parameter">p</warning>) {
return super.foo(p);
}
}
class PPP2 extends P2 {
String <warning descr="Not annotated method overrides method annotated with @NotNull">foo</warning>(<error descr="Cannot resolve symbol 'P'">P</error> <warning descr="Not annotated parameter overrides @NotNull parameter">p</warning>) {
return super.foo(p);
}
}
/////// in library
interface Foo {
@NotNull
String getTitle();
}
<error descr="Unhandled exception: java.awt.HeadlessException">class FooImpl extends java.awt.Frame implements Foo</error> {
// public String getTitle() {
// return super.getTitle(); //To change body of overridden methods use File | Settings | File Templates.
// }
}
interface I1 {
@Nullable
Object foo();
}
interface I2 extends I1 {
@NotNull
Object foo();
}
class A implements I1 {
@Override
public Object foo() {
// returns something
<error descr="Missing return statement">}</error>
}
class B extends A implements I2 {
}

View File

@@ -0,0 +1,26 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class B {
public void f(@NotNull String p){}
@NotNull
public String nn(@Nullable String param) {
return "";
}
}
public class Y extends B {
<warning descr="Cannot annotate with both @Nullable and @NotNull">@NotNull</warning> <warning descr="Cannot annotate with both @Nullable and @NotNull">@Nullable</warning> String s;
public void f(String <warning descr="Not annotated parameter overrides @NotNull parameter">p</warning>){}
public String <warning descr="Not annotated method overrides method annotated with @NotNull">nn</warning>(<warning descr="Parameter annotated @NotNull must not override @Nullable parameter">@NotNull</warning> String param) {
return "";
}
void p(<warning descr="Cannot annotate with both @Nullable and @NotNull">@NotNull</warning> <warning descr="Cannot annotate with both @Nullable and @NotNull">@Nullable</warning> String p2){}
<warning descr="Primitive type members cannot be annotated">@Nullable</warning> int f;
<warning descr="Primitive type members cannot be annotated">@NotNull</warning> void vf(){}
void t(<warning descr="Primitive type members cannot be annotated">@NotNull</warning> double d){}
}

View File

@@ -0,0 +1,24 @@
import org.jetbrains.annotations.*;
class C {
public static C C = null;
@NotNull public C getC() {return C;}
@NotNull public C getC2() {return C;}
public void f1(@Nullable C p) {}
public void f2(@NotNull C p) {}
public void f3(@Nullable C p) {}
public void f4(@NotNull C p) {}
}
class CC extends C {
<warning descr="Method annotated with @Nullable must not override @NotNull method">@Nullable</warning> public C getC() {return C;}
public C <warning descr="Not annotated method overrides method annotated with @NotNull">getC2</warning>() {return C;}
public void f1(<warning descr="Parameter annotated @NotNull must not override @Nullable parameter">@NotNull</warning> C p) {}
public void f2(@NotNull C p) {}
public void f3(@Nullable C p) {}
public void f4(@Nullable C p) {}
<warning descr="Cannot annotate with both @Nullable and @NotNull">@Nullable</warning> <warning descr="Cannot annotate with both @Nullable and @NotNull">@NotNull</warning> String f() { return null;}
}

View File

@@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>11</line>
<method>
<name>void setB(B b)</name>
<display_name>setB(B)</display_name>
<package>&lt;default&gt;</package>
<class>
<name>B</name>
<display_name>B</display_name>
</class>
</method>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Setter parameter for @NotNull field might be annotated @NotNull itself</description>
</problem>
<problem>
<file>Test.java</file>
<line>7</line>
<method>
<name>B getB()</name>
<display_name>getB()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>B</name>
<display_name>B</display_name>
</class>
</method>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Getter for @NotNull field might be annotated @NotNull itself</description>
</problem>
<problem>
<file>Test.java</file>
<line>25</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Constructor parameter for @NotNull field might be annotated @NotNull itself</description>
</problem>
<problem>
<file>Test.java</file>
<line>38</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Setter parameter for @NotNull field might be annotated @NotNull itself</description>
</problem>
<problem>
<file>Test.java</file>
<line>34</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Getter for @NotNull field might be annotated @NotNull itself</description>
</problem>
<problem>
<file>Test.java</file>
<line>29</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Constructor parameter for @NotNull field might be annotated @NotNull itself</description>
</problem>
<problem>
<file>Test.java</file>
<line>63</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Constructor parameter for @NotNull field might be annotated @NotNull itself</description>
</problem>
</problems>

View File

@@ -1,67 +0,0 @@
import org.jetbrains.annotations.NotNull;
class B {
@NotNull
B b;
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
@NotNull
private String bug = "true";
public boolean getBug() {
return Boolean.valueOf(bug);
}
}
class C {
@NotNull C c;
C(C c) {
this.c = c;
}
C(@Nullable C c, int i) {
this.c = c;
}
@Nullable
public C getC() {
return c;
}
public void setC(@Nullable C c) {
this.c = c;
}
@NotNull C c1;
@org.jetbrains.annotations.Nullable
public C getC1() {
if (c1 != null) {
return null;
}
return c1;
}
}
class D {
@Nullable Long myL;
D(long l) {
myL = l;
}
}
class E {
final @NotNull C c;
E(C c) {
this.c = c;
}
}

View File

@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Constructor parameter for @Nullable field is annotated @NotNull</description>
</problem>
</problems>

View File

@@ -1,43 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>18</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Not annotated method overrides method annotated with @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>18</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Not annotated parameter overrides @NotNull parameter</description>
</problem>
<problem>
<file>Test.java</file>
<line>5</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Overridden methods are not annotated</description>
</problem>
<problem>
<file>Test.java</file>
<line>6</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Overridden method parameters are not annotated</description>
</problem>
<problem>
<file>Test.java</file>
<line>12</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Not annotated method overrides method annotated with @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>12</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Not annotated parameter overrides @NotNull parameter</description>
</problem></problems>

View File

@@ -1,53 +0,0 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
abstract class P2 {
@NotNull
String foo(@NotNull P p) {
return "";
}
}
class PPP extends P2 {
String foo(P p) {
return super.foo(p);
}
}
class PPP2 extends P2 {
String foo(P p) {
return super.foo(p);
}
}
/////// in library
interface Foo {
@NotNull
String getTitle();
}
class FooImpl extends java.awt.Frame implements Foo {
// public String getTitle() {
// return super.getTitle(); //To change body of overridden methods use File | Settings | File Templates.
// }
}
interface I1 {
@Nullable
Object foo();
}
interface I2 extends I1 {
@NotNull
Object foo();
}
class A implements I1 {
@Override
public Object foo() {
// returns something
}
}
class B extends A implements I2 {
}

View File

@@ -1,169 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>14</line>
<method>
<name>void f(String p)</name>
<display_name>f(String)</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</method>
<description>Not annotated parameter overrides @NotNull parameter</description>
</problem>
<problem>
<file>Test.java</file>
<line>17</line>
<text_range start="361" end="363" />
<method>
<name>String nn(String param)</name>
<display_name>nn(String)</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</method>
<description>Not annotated method overrides method annotated with @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>17</line>
<text_range start="380" end="385" />
<method>
<name>String nn(String param)</name>
<display_name>nn(String)</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</method>
<description>Parameter annotated @NotNull must not override @Nullable parameter</description>
</problem>
<problem>
<file>Test.java</file>
<line>13</line>
<text_range start="291" end="292" />
<field>
<name>String s</name>
<display_name>s</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</field>
<description>Cannot annotate with both @Nullable and @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>13</line>
<field>
<name>String s</name>
<display_name>s</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</field>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Cannot annotate with both @Nullable and @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>20</line>
<text_range start="452" end="454" />
<method>
<name>void p(String p2)</name>
<display_name>p(String)</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</method>
<description>Cannot annotate with both @Nullable and @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>23</line>
<text_range start="476" end="477" />
<field>
<name>int f</name>
<display_name>f</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</field>
<description>Primitive type members cannot be annotated</description>
</problem>
<problem>
<file>Test.java</file>
<line>24</line>
<text_range start="492" end="496" />
<method>
<name>void vf()</name>
<display_name>vf()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</method>
<description>Primitive type members cannot be annotated</description>
</problem>
<problem>
<file>Test.java</file>
<line>25</line>
<text_range start="531" end="532" />
<method>
<name>void t(double d)</name>
<display_name>t(double)</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</method>
<description>Primitive type members cannot be annotated</description>
</problem>
<problem>
<file>Test.java</file>
<line>20</line>
<method>
<name>void p(String p2)</name>
<name>p(String)</name>
<package>&lt;default&gt;</package>
<class>
<name>Y</name>
<display_name>Y</display_name>
</class>
</method>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Cannot annotate with both @Nullable and @NotNull</description>
</problem>
</problems>

View File

@@ -1,26 +0,0 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class B {
public void f(@NotNull String p){}
@NotNull
public String nn(@Nullable String param) {
return "";
}
}
public class Y extends B {
@NotNull @Nullable String s;
public void f(String p){}
public String nn(@NotNull String param) {
return "";
}
void p(@NotNull @Nullable String p2){}
@Nullable int f;
@NotNull void vf(){}
void t(@NotNull double d){}
}

View File

@@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>23</line>
<text_range start="556" end="557" />
<method>
<name>String f()</name>
<display_name>f()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>CC</name>
<display_name>CC</display_name>
</class>
</method>
<description>Cannot annotate with both @Nullable and @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>23</line>
<method>
<name>String f()</name>
<name>f()</name>
<package>&lt;default&gt;</package>
<class>
<name>CC</name>
<display_name>CC</display_name>
</class>
</method>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
<description>Cannot annotate with both @Nullable and @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>16</line>
<text_range start="368" end="373" />
<method>
<name>C getC2()</name>
<display_name>getC2()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>CC</name>
<display_name>CC</display_name>
</class>
</method>
<description>Not annotated method overrides method annotated with @NotNull</description>
</problem>
<problem>
<file>Test.java</file>
<line>18</line>
<text_range start="417" end="418" />
<method>
<name>void f1(C p)</name>
<display_name>f1(C)</display_name>
<package>&lt;default&gt;</package>
<class>
<name>CC</name>
<display_name>CC</display_name>
</class>
</method>
<description>Parameter annotated @NotNull must not override @Nullable parameter</description>
</problem>
<problem>
<file>Test.java</file>
<line>15</line>
<text_range start="338" end="342" />
<method>
<name>C getC()</name>
<display_name>getC()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>CC</name>
<display_name>CC</display_name>
</class>
</method>
<description>Method annotated with @Nullable must not override @NotNull method</description>
</problem>
</problems>

View File

@@ -1,24 +0,0 @@
import org.jetbrains.annotations.*;
class C {
public static C C = null;
@NotNull public C getC() {return C;}
@NotNull public C getC2() {return C;}
public void f1(@Nullable C p) {}
public void f2(@NotNull C p) {}
public void f3(@Nullable C p) {}
public void f4(@NotNull C p) {}
}
class CC extends C {
@Nullable public C getC() {return C;}
public C getC2() {return C;}
public void f1(@NotNull C p) {}
public void f2(@NotNull C p) {}
public void f3(@Nullable C p) {}
public void f4(@Nullable C p) {}
@Nullable @NotNull String f() { return null;}
}