unused return value: report native methods (IDEA-90127)

This commit is contained in:
Anna Kozlova
2012-09-14 17:22:47 +04:00
parent 3894a2e676
commit 57c547d18c
5 changed files with 26 additions and 3 deletions
@@ -356,7 +356,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
}
public boolean hasSuperMethods() {
return !getSuperMethods().isEmpty() || isLibraryOverride(new HashSet<RefMethod>());
return !getSuperMethods().isEmpty() || isExternalOverride();
}
public boolean isReferenced() {
@@ -30,6 +30,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor;
import com.intellij.refactoring.changeSignature.ParameterInfoImpl;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -56,16 +57,19 @@ public class UnusedReturnValue extends GlobalJavaInspectionTool{
final RefMethod refMethod = (RefMethod)refEntity;
if (refMethod.isConstructor()) return null;
if (refMethod.hasSuperMethods()) return null;
if (!refMethod.getSuperMethods().isEmpty()) return null;
if (refMethod.getInReferences().size() == 0) return null;
if (!refMethod.isReturnValueUsed()) {
final PsiMethod psiMethod = (PsiMethod)refMethod.getElement();
if (IGNORE_BUILDER_PATTERN && PropertyUtil.isSimplePropertySetter(psiMethod)) return null;
final boolean isNative = psiMethod.hasModifierProperty(PsiModifier.NATIVE);
if (refMethod.isExternalOverride() && !isNative) return null;
return new ProblemDescriptor[]{manager.createProblemDescriptor(psiMethod.getNavigationElement(),
InspectionsBundle
.message("inspection.unused.return.value.problem.descriptor"),
getFix(processor), ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
!isNative ? getFix(processor) : null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
false)};
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>2</line>
<description>Return value of the method is never used</description>
</problem>
</problems>
@@ -0,0 +1,7 @@
class Test {
private static native boolean isUnused();
public static void main(String[] args) {
Test.isUnused();
}
}
@@ -31,6 +31,10 @@ public class UnusedReturnValueTest extends InspectionTestCase {
doTest();
}
public void testNative() throws Exception {
doTest();
}
public void testHierarchy() throws Exception {
doTest();
}