mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
AutoCloseableResourceInspection: invert func, move class : IDEA-CR-28727
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package com.siyeh.ig.resources;
|
||||
package com.intellij.codeInspection.resources;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
+9
-8
@@ -16,6 +16,7 @@
|
||||
package com.siyeh.ig.resources;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.resources.ImplicitResourceCloser;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
@@ -165,7 +166,7 @@ public class AutoCloseableResourceInspectionBase extends ResourceInspection {
|
||||
@Override
|
||||
public void visitNewExpression(PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
if (!isNotSafelyClosedResource(expression)) {
|
||||
if (isSafelyClosedResource(expression)) {
|
||||
return;
|
||||
}
|
||||
registerNewExpressionError(expression, expression.getType(), Boolean.FALSE);
|
||||
@@ -174,7 +175,7 @@ public class AutoCloseableResourceInspectionBase extends ResourceInspection {
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
if (ignoreFromMethodCall || myMethodMatcher.matches(expression) || !isNotSafelyClosedResource(expression)) {
|
||||
if (ignoreFromMethodCall || myMethodMatcher.matches(expression) || isSafelyClosedResource(expression)) {
|
||||
return;
|
||||
}
|
||||
registerMethodCallError(expression, expression.getType(), Boolean.TRUE);
|
||||
@@ -198,16 +199,16 @@ public class AutoCloseableResourceInspectionBase extends ResourceInspection {
|
||||
registerError(expression, type, Boolean.FALSE);
|
||||
}
|
||||
|
||||
private boolean isNotSafelyClosedResource(PsiExpression expression) {
|
||||
private boolean isSafelyClosedResource(PsiExpression expression) {
|
||||
if (!isResourceCreation(expression)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (CLOSE.test(ExpressionUtils.getCallForQualifier(expression))) return false;
|
||||
if (CLOSE.test(ExpressionUtils.getCallForQualifier(expression))) return true;
|
||||
final PsiVariable variable = ResourceInspection.getVariable(expression);
|
||||
if(variable instanceof PsiResourceVariable || isResourceEscapingFromMethod(variable, expression)) return false;
|
||||
if (variable == null) return true;
|
||||
if(variable instanceof PsiResourceVariable || isResourceEscapingFromMethod(variable, expression)) return true;
|
||||
if (variable == null) return false;
|
||||
return StreamEx.of(Extensions.getExtensions(ImplicitResourceCloser.EP_NAME))
|
||||
.noneMatch(closer -> closer.isSafelyClosed(variable));
|
||||
.anyMatch(closer -> closer.isSafelyClosed(variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<extensionPoint qualifiedName="com.intellij.naming.convention.class" interface="com.intellij.codeInspection.naming.NamingConvention"/>
|
||||
<extensionPoint qualifiedName="com.intellij.naming.convention.method" interface="com.intellij.codeInspection.naming.NamingConvention"/>
|
||||
<extensionPoint qualifiedName="com.intellij.naming.convention.field" interface="com.intellij.codeInspection.naming.NamingConvention"/>
|
||||
<extensionPoint qualifiedName="com.intellij.implicit.resource.closer" interface="com.siyeh.ig.resources.ImplicitResourceCloser"/>
|
||||
<extensionPoint qualifiedName="com.intellij.implicit.resource.closer" interface="com.intellij.codeInspection.resources.ImplicitResourceCloser"/>
|
||||
</extensionPoints>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.resources;
|
||||
|
||||
import com.intellij.codeInspection.resources.ImplicitResourceCloser;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
|
||||
Reference in New Issue
Block a user