mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Handle 'throws' clause in the inspection "Non-accessible type is exposed" (IDEA-162768)
This commit is contained in:
+13
-3
@@ -86,6 +86,12 @@ public class Java9NonAccessibleTypeExposedInspection extends BaseJavaLocalInspec
|
||||
for (PsiParameter parameter : method.getParameterList().getParameters()) {
|
||||
checkType(parameter.getType(), parameter.getTypeElement());
|
||||
}
|
||||
for (PsiJavaCodeReferenceElement referenceElement : method.getThrowsList().getReferenceElements()) {
|
||||
PsiElement resolved = referenceElement.resolve();
|
||||
if (resolved instanceof PsiClass) {
|
||||
checkType((PsiClass)resolved, referenceElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,9 +127,13 @@ public class Java9NonAccessibleTypeExposedInspection extends BaseJavaLocalInspec
|
||||
private void checkType(@Nullable PsiType type, @Nullable PsiTypeElement typeElement) {
|
||||
if (typeElement != null) {
|
||||
PsiClass psiClass = PsiUtil.resolveClassInType(type);
|
||||
if (psiClass != null && isInModuleSource(psiClass) && !isModulePublicApi(psiClass)) {
|
||||
myHolder.registerProblem(typeElement, CLASS_IS_NOT_EXPORTED);
|
||||
}
|
||||
checkType(psiClass, typeElement);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkType(PsiClass psiClass, @NotNull PsiElement typeElement) {
|
||||
if (psiClass != null && isInModuleSource(psiClass) && !isModulePublicApi(psiClass)) {
|
||||
myHolder.registerProblem(typeElement, CLASS_IS_NOT_EXPORTED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
@@ -197,6 +197,23 @@ public class Highlighted {
|
||||
""")
|
||||
}
|
||||
|
||||
fun testThrows() {
|
||||
add("apiPkg", "PublicException", "public class PublicException extends Exception {}")
|
||||
add("apiPkg", "PackageLocalException", "class PackageLocalException extends Exception {}")
|
||||
add("otherPkg", "OtherException", "public class OtherException extends Exception {}")
|
||||
add("implPkg", "NotExportedException", "public class NotExportedException extends Exception {}")
|
||||
highlight("""package apiPkg;
|
||||
import otherPkg.*;
|
||||
import implPkg.*;
|
||||
public class Highlighted {
|
||||
public void throwsPublic() throws PublicException {}
|
||||
public void throwsPackageLocal() throws <warning descr="The class is not exported from the module">PackageLocalException</warning> {}
|
||||
public void throwsOther() throws OtherException {}
|
||||
public void throwsNotExported() throws <warning descr="The class is not exported from the module">NotExportedException</warning> {}
|
||||
}
|
||||
""")
|
||||
}
|
||||
|
||||
fun testPublicAnnotation() {
|
||||
add("apiPkg", "MyAnnotation", "public @interface MyAnnotation {}")
|
||||
highlight("""package apiPkg;
|
||||
|
||||
Reference in New Issue
Block a user