candidateParams = ContainerUtil.map(candidate.getParameterList().getParameters(), param -> param.getType());
+ if (candidateParams.size() != methodParams.size()) continue;
+ if (methodParams.subList(1, methodParams.size()).equals(candidateParams.subList(1, candidateParams.size()))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private static class DeleteRedundantFileCreationFix implements LocalQuickFix {
@Nls
@NotNull
@@ -80,19 +102,18 @@ public class RedundantFileCreationInspection extends AbstractBaseJavaLocalInspec
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
- assert element instanceof PsiNewExpression;
+ if (!(element instanceof PsiNewExpression)) return;
- final PsiNewExpression newExpression = (PsiNewExpression)descriptor.getPsiElement();
+ final PsiNewExpression newExpression = (PsiNewExpression)element;
final PsiExpressionList argList = newExpression.getArgumentList();
- assert argList != null;
+ if (argList == null) return;
final PsiExpression[] args = argList.getExpressions();
- assert args.length == 1;
+ if (args.length != 1) return;
CommentTracker commentTracker = new CommentTracker();
- final String argText = commentTracker.text(args[0]);
- PsiReplacementUtil.replaceExpression(newExpression, argText, commentTracker);
+ commentTracker.replace(newExpression, args[0]);
}
}
}
diff --git a/java/java-impl/src/inspectionDescriptions/RedundantFileCreation.html b/java/java-impl/src/inspectionDescriptions/RedundantFileCreation.html
index 55996cafcd93..44ffb080b577 100644
--- a/java/java-impl/src/inspectionDescriptions/RedundantFileCreation.html
+++ b/java/java-impl/src/inspectionDescriptions/RedundantFileCreation.html
@@ -1,8 +1,13 @@
-Redundant File creation in a stream constructor
+Reports redundant file creation when the stream constructor that takes a path could be used.
+The quick-fix replaces the constructor call with a String literal that represents the path, for example:
+
+InputStream is = new FileInputStream(new File("in.txt")); // before
+InputStream is = new FileInputStream("in.txt"); // after
+
+
-
-
\ No newline at end of file
+