mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix redundant returns deletion in type migration to void
This commit is contained in:
@@ -121,7 +121,7 @@ public class MakeVoidQuickFix implements LocalQuickFix {
|
||||
}
|
||||
if (returnStatement != null && returnStatement.getReturnValue() != null) {
|
||||
returnStatement.getReturnValue().delete();
|
||||
if (UnnecessaryReturnInspection.isReturnRedundant(returnStatement, false, null)) {
|
||||
if (UnnecessaryReturnInspection.isReturnRedundant(returnStatement, false, true, null)) {
|
||||
returnStatement.delete();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class VoidConversionRule extends TypeConversionRule {
|
||||
final Project project = expression.getProject();
|
||||
if (parent instanceof PsiReturnStatement) {
|
||||
final PsiReturnStatement replaced = (PsiReturnStatement)parent.replace(JavaPsiFacade.getElementFactory(project).createStatementFromText("return;", null));
|
||||
if (UnnecessaryReturnInspection.isReturnRedundant(replaced, false, null)) {
|
||||
if (UnnecessaryReturnInspection.isReturnRedundant(replaced, false, false, null)) {
|
||||
DeleteUnnecessaryStatementFix.deleteUnnecessaryStatement(replaced);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -88,7 +88,7 @@ public class UnnecessaryReturnInspection extends BaseInspection {
|
||||
public void visitReturnStatement(@NotNull PsiReturnStatement statement) {
|
||||
super.visitReturnStatement(statement);
|
||||
final Ref<Boolean> constructorRef = Ref.create();
|
||||
if (isReturnRedundant(statement, ignoreInThenBranch, constructorRef)) {
|
||||
if (isReturnRedundant(statement, ignoreInThenBranch, true, constructorRef)) {
|
||||
registerStatementError(statement, constructorRef.get());
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,7 @@ public class UnnecessaryReturnInspection extends BaseInspection {
|
||||
|
||||
public static boolean isReturnRedundant(@NotNull PsiReturnStatement statement,
|
||||
boolean ignoreInThenBranch,
|
||||
boolean checkReturnType,
|
||||
@Nullable Ref<Boolean> isInConstructorRef) {
|
||||
if (statement.getReturnValue() != null) {
|
||||
return false;
|
||||
@@ -109,7 +110,7 @@ public class UnnecessaryReturnInspection extends BaseInspection {
|
||||
if (isInConstructorRef != null) {
|
||||
isInConstructorRef.set(method.isConstructor());
|
||||
}
|
||||
if (!method.isConstructor() && !PsiType.VOID.equals(method.getReturnType())) {
|
||||
if (checkReturnType && !method.isConstructor() && !PsiType.VOID.equals(method.getReturnType())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +119,7 @@ public class UnnecessaryReturnInspection extends BaseInspection {
|
||||
isInConstructorRef.set(false);
|
||||
}
|
||||
final PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)methodParent;
|
||||
if (!PsiType.VOID.equals(LambdaUtil.getFunctionalInterfaceReturnType(lambdaExpression))) {
|
||||
if (checkReturnType && !PsiType.VOID.equals(LambdaUtil.getFunctionalInterfaceReturnType(lambdaExpression))) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement lambdaBody = lambdaExpression.getBody();
|
||||
|
||||
Reference in New Issue
Block a user