Java slicing: support -> this/-> paramN contracts

Fixes IDEA-121571 Feature request: A Contract Annotation that indicates that a method returns its argument
This commit is contained in:
Tagir Valeev
2018-05-08 11:53:19 +07:00
parent 50268274cd
commit a93cb6b9a5
12 changed files with 139 additions and 62 deletions
@@ -0,0 +1,6 @@
class Test {
StringBuilder builder(StringBuilder <flown1111>sb) {
StringBuilder foo = <flown111><flown11><flown1>sb.append("foo").append(123);
return <caret>foo;
}
}
@@ -10,11 +10,11 @@ class WW {
}
{
x(<flown111111>"zzz");
x(<flown1211><flown111111>"zzz");
}
String x(String <flown11111>g) {
String d = <flown1>foo(<flown1111>g);
String x(String <flown121><flown11111>g) {
String d = <flown1>foo(<flown12><flown1111>g);
return <caret>d;
}
@@ -0,0 +1,21 @@
class Test {
private String <flown1>s;
private String s2;
void test(String <flown112111><flown1111>s, String s2) {
this.s = <flown11>requireNonNull(<flown11211><flown111>s);
this.s2 = requireNonNull(s2);
}
String foo() {
return <caret>s;
}
public static <T> T requireNonNull(T <flown1121>obj) {
if (obj == null)
throw new NullPointerException();
return <flown112>obj;
}
}
@@ -0,0 +1,6 @@
class Test {
StringBuilder <flown111111>builder(StringBuilder <caret>sb) {
StringBuilder <flown1111>foo = <flown111><flown11><flown1>sb.append("foo").append(1);
return <flown11111>foo;
}
}
@@ -0,0 +1,16 @@
class Test {
private String <flown111>s;
private String s2;
void test(String <caret>s, String s2) {
this.s = <flown11>requireNonNull(<flown1>s);
this.s2 = requireNonNull(s2);
}
String <flown11111>foo() {
return <flown1111>s;
}
@org.jetbrains.annotations.Contract("null -> fail; !null -> param1")
public static native <T> T requireNonNull(T <flown12>obj);
}