redundant throws: do not warn on native methods IDEA-205525

This commit is contained in:
Dmitry Batkovich
2019-01-18 22:19:56 +03:00
parent 4e8575578e
commit 73c618ebfe
4 changed files with 22 additions and 0 deletions
@@ -8,6 +8,7 @@ import com.intellij.codeInsight.daemon.impl.quickfix.MethodThrowsFix;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.reference.*;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.lang.jvm.JvmModifier;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -71,6 +72,9 @@ public class RedundantThrowsDeclarationInspection extends GlobalJavaBatchInspect
PsiElement psiMethod = refMethod.getPsiElement();
if (!(psiMethod instanceof PsiMethod)) return null;
if (((PsiMethod)psiMethod).hasModifier(JvmModifier.NATIVE)) return null;
PsiReferenceList list = ((PsiMethod)psiMethod).getThrowsList();
PsiClassType[] throwsList = list.getReferencedTypes();
PsiJavaCodeReferenceElement[] throwsRefs = list.getReferenceElements();
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,11 @@
import java.io.*;
class Bar {
public native int goDrink(String arg) throws IOException;
public static void main(String[] args) throws IOException {
Bar bar = new Bar();
bar.goDrink("aaa");
}
}
@@ -58,4 +58,8 @@ public class RedundantThrowTest extends InspectionTestCase {
public void testThrownClausesInMethodReference() {
doTest();
}
public void testNativeMethod() {
doTest();
}
}