Java: Improved messages and documentation for the inspection "Non-accessible class is exposed" (IDEA-166535)

This commit is contained in:
Pavel Dolgov
2017-02-08 17:19:01 +03:00
parent b88bca1cb8
commit 82abcad979
4 changed files with 54 additions and 42 deletions
@@ -73,13 +73,13 @@ public class Highlighted {
highlight("""package apiPkg;
public class Highlighted {
static { PackageLocal tmp = new PackageLocal(); System.out.println(tmp);}
public <warning descr="Class is not exported from the module">PackageLocal</warning> myVar;
public <warning descr="Class 'PackageLocal' is not exported from the module 'MAIN'">PackageLocal</warning> myVar;
protected Highlighted() {}
public Highlighted(<warning descr="Class is not exported from the module">PackageLocal</warning> var) {
public Highlighted(<warning descr="Class 'PackageLocal' is not exported from the module 'MAIN'">PackageLocal</warning> var) {
PackageLocal tmp = new PackageLocal(); myVar = var!= null ? var : tmp;
}
public <warning descr="Class is not exported from the module">PackageLocal</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class is not exported from the module">PackageLocal</warning> var) {myVar = var;}
public <warning descr="Class 'PackageLocal' is not exported from the module 'MAIN'">PackageLocal</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class 'PackageLocal' is not exported from the module 'MAIN'">PackageLocal</warning> var) {myVar = var;}
}
""")
}
@@ -174,13 +174,13 @@ public class Highlighted {
public class Highlighted {
class PackageLocalNested {}
{ PackageLocalNested tmp = new PackageLocalNested(); System.out.println(tmp);}
public <warning descr="Class is not exported from the module">PackageLocalNested</warning> myVar;
public <warning descr="Class 'PackageLocalNested' is not exported from the module 'MAIN'">PackageLocalNested</warning> myVar;
protected Highlighted() {}
public Highlighted(<warning descr="Class is not exported from the module">PackageLocalNested</warning> var) {
public Highlighted(<warning descr="Class 'PackageLocalNested' is not exported from the module 'MAIN'">PackageLocalNested</warning> var) {
PackageLocalNested tmp = new PackageLocalNested(); myVar = var!= null ? var : tmp;
}
public <warning descr="Class is not exported from the module">PackageLocalNested</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class is not exported from the module">PackageLocalNested</warning> var) {myVar = var;}
public <warning descr="Class 'PackageLocalNested' is not exported from the module 'MAIN'">PackageLocalNested</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class 'PackageLocalNested' is not exported from the module 'MAIN'">PackageLocalNested</warning> var) {myVar = var;}
}
""")
}
@@ -188,9 +188,9 @@ public class Highlighted {
fun testPackageLocalInInterface() {
highlight("""package apiPkg;
public interface Highlighted {
<warning descr="Class is not exported from the module">PackageLocal</warning> myVar = new PackageLocal();
<warning descr="Class is not exported from the module">PackageLocal</warning> getVar();
void setVar(<warning descr="Class is not exported from the module">PackageLocal</warning> var);
<warning descr="Class 'PackageLocal' is not exported from the module 'MAIN'">PackageLocal</warning> myVar = new PackageLocal();
<warning descr="Class 'PackageLocal' is not exported from the module 'MAIN'">PackageLocal</warning> getVar();
void setVar(<warning descr="Class 'PackageLocal' is not exported from the module 'MAIN'">PackageLocal</warning> var);
}
""")
}
@@ -210,11 +210,11 @@ public interface Highlighted {
highlight("""package apiPkg;
import implPkg.NotExported;
public class Highlighted {
public <warning descr="Class is not exported from the module">NotExported</warning> myVar;
public <warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning> myVar;
protected Highlighted() {}
public Highlighted(<warning descr="Class is not exported from the module">NotExported</warning> var) {setVar(var);}
public <warning descr="Class is not exported from the module">NotExported</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class is not exported from the module">NotExported</warning> var) {myVar = var;}
public Highlighted(<warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning> var) {setVar(var);}
public <warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning> var) {myVar = var;}
}
""")
}
@@ -229,8 +229,8 @@ public class Highlighted {
import apiPkg.PublicOuter.PackageLocal;
public class Highlighted {
private PackageLocal.DoubleNested myVar;
public <warning descr="Class is not exported from the module">PackageLocal.DoubleNested</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class is not exported from the module">PackageLocal.DoubleNested</warning> var) {myVar = var;}
public <warning descr="Class 'PackageLocal.DoubleNested' is not exported from the module 'MAIN'">PackageLocal.DoubleNested</warning> getVar() {return myVar;}
protected void setVar(<warning descr="Class 'PackageLocal.DoubleNested' is not exported from the module 'MAIN'">PackageLocal.DoubleNested</warning> var) {myVar = var;}
}
""")
}
@@ -255,11 +255,11 @@ public class Highlighted {
import implPkg.NotExported;
import java.util.*;
public class Highlighted {
public <warning descr="Class is not exported from the module">NotExported</warning>[] myVar;
protected Highlighted(List<<warning descr="Class is not exported from the module">NotExported</warning>[]> list) {Iterator<NotExported[]> it = list.iterator(); myVar = it.next();}
public Highlighted(<warning descr="Class is not exported from the module">NotExported</warning>[] var) {myVar = var;}
public <warning descr="Class is not exported from the module">NotExported</warning>[] getVar() {return myVar;}
protected void setVar(<warning descr="Class is not exported from the module">NotExported</warning>[][] var) {myVar = var[0];}
public <warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning>[] myVar;
protected Highlighted(List<<warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning>[]> list) {Iterator<NotExported[]> it = list.iterator(); myVar = it.next();}
public Highlighted(<warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning>[] var) {myVar = var;}
public <warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning>[] getVar() {return myVar;}
protected void setVar(<warning descr="Class 'NotExported' is not exported from the module 'MAIN'">NotExported</warning>[][] var) {myVar = var[0];}
}""")
}
@@ -273,9 +273,9 @@ import otherPkg.*;
import implPkg.*;
public class Highlighted {
public void throwsPublic() throws PublicException {}
public void throwsPackageLocal() throws <warning descr="Class is not exported from the module">PackageLocalException</warning> {}
public void throwsPackageLocal() throws <warning descr="Class 'PackageLocalException' is not exported from the module 'MAIN'">PackageLocalException</warning> {}
public void throwsOther() throws OtherException {}
public void throwsNotExported() throws <warning descr="Class is not exported from the module">NotExportedException</warning> {}
public void throwsNotExported() throws <warning descr="Class 'NotExportedException' is not exported from the module 'MAIN'">NotExportedException</warning> {}
}
""")
}
@@ -314,16 +314,16 @@ import java.util.*;
import implPkg.*;
public class Highlighted<T extends MyInterface> {
protected Set<T> get1() { return new HashSet<>();}
public Set<<warning descr="Class is not exported from the module">MyClass</warning>> get2() { return new HashSet<MyClass>();}
protected Set<? extends <warning descr="Class is not exported from the module">MyClass</warning>> get3() { return new HashSet<>();}
public <X extends Object&<warning descr="Class is not exported from the module">MyInterface</warning>> Set<X> get4() { return new HashSet<>();}
public Map<String, Set<<warning descr="Class is not exported from the module">MyInterface</warning>>> get5() {return new HashMap<>();}
public void copy1(Set<<warning descr="Class is not exported from the module">MyInterface</warning>> s) {}
public void copy2(Set<? super <warning descr="Class is not exported from the module">MyClass</warning>> s) {}
public Set<<warning descr="Class 'MyClass' is not exported from the module 'MAIN'">MyClass</warning>> get2() { return new HashSet<MyClass>();}
protected Set<? extends <warning descr="Class 'MyClass' is not exported from the module 'MAIN'">MyClass</warning>> get3() { return new HashSet<>();}
public <X extends Object&<warning descr="Class 'MyInterface' is not exported from the module 'MAIN'">MyInterface</warning>> Set<X> get4() { return new HashSet<>();}
public Map<String, Set<<warning descr="Class 'MyInterface' is not exported from the module 'MAIN'">MyInterface</warning>>> get5() {return new HashMap<>();}
public void copy1(Set<<warning descr="Class 'MyInterface' is not exported from the module 'MAIN'">MyInterface</warning>> s) {}
public void copy2(Set<? super <warning descr="Class 'MyClass' is not exported from the module 'MAIN'">MyClass</warning>> s) {}
public static class Nested1<T extends MyClass&
Iterable<MyInterface>> {
public Iterator<<warning descr="Class is not exported from the module">MyInterface</warning>> iterator() {return null;}
public Iterator<<warning descr="Class 'MyInterface' is not exported from the module 'MAIN'">MyInterface</warning>> iterator() {return null;}
}
public static class Nested2<T extends MyInterface&AutoCloseable> {
public void close() {}