mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-131445 (Inspection "Memory issues | Return of instance of anonymous, local or inner class" should have an option to ignore non-public methods.)
This commit is contained in:
+1
@@ -2121,6 +2121,7 @@ return.of.inner.class.display.name=Return of instance of anonymous, local or inn
|
||||
return.of.anonymous.class.problem.descriptor=Return of instance of anonymous class #loc
|
||||
return.of.local.class.problem.descriptor=Return of instance of local class <code>{0}</code> #loc
|
||||
return.of.inner.class.problem.descriptor=Return of instance of non-static inner class <code>{0}</code> #loc
|
||||
return.of.inner.class.ignore.non.public.option=Ignore returns from non-public methods
|
||||
parameter.type.prevents.overriding.display.name=Parameter type prevents overriding
|
||||
parameter.type.prevents.overriding.problem.descriptor=Parameter type <code>#ref</code> is located in ''{0}'' while super method parameter type is located in ''{1}'' preventing overriding
|
||||
parameter.type.prevents.overriding.quickfix=Change type of parameter to ''{0}''
|
||||
|
||||
+18
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.memory;
|
||||
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -24,12 +25,17 @@ import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class ReturnOfInnerClassInspection extends BaseInspection {
|
||||
|
||||
@SuppressWarnings("PublicField") public boolean ignoreNonPublic = false;
|
||||
|
||||
private enum ClassType { ANONYMOUS_CLASS, LOCAL_CLASS, INNER_CLASS }
|
||||
|
||||
@Nls
|
||||
@@ -58,12 +64,19 @@ public class ReturnOfInnerClassInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("return.of.inner.class.ignore.non.public.option"),
|
||||
this, "ignoreNonPublic");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new ReturnOfInnerClassVisitor();
|
||||
}
|
||||
|
||||
private static class ReturnOfInnerClassVisitor extends BaseInspectionVisitor {
|
||||
private class ReturnOfInnerClassVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitReturnStatement(PsiReturnStatement statement) {
|
||||
@@ -76,6 +89,10 @@ public class ReturnOfInnerClassInspection extends BaseInspection {
|
||||
if (method == null || method.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
return;
|
||||
}
|
||||
else if (ignoreNonPublic &&
|
||||
(method.hasModifierProperty(PsiModifier.PROTECTED) || method.hasModifierProperty(PsiModifier.PACKAGE_LOCAL))) {
|
||||
return;
|
||||
}
|
||||
if (expression instanceof PsiNewExpression) {
|
||||
final PsiNewExpression newExpression = (PsiNewExpression)expression;
|
||||
final PsiAnonymousClass anonymousClass = newExpression.getAnonymousClass();
|
||||
|
||||
@@ -5,6 +5,9 @@ Such instances keep an implicit reference to the outer instance.
|
||||
Which means the instance can prevent the outer instance from being garbage collected.
|
||||
Any caller of a method which returns such an instance might cause a memory leak by holding on to the instance returned.
|
||||
<p>
|
||||
Use the checkbox below to ignore returns from <b>protected</b> or package-local methods.
|
||||
Returns from <b>private</b> methods are always ignored.
|
||||
<p>
|
||||
<small>New in 14</small>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user