From d16e067beff523f2bfed39cd8212bfe27041b49c Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Wed, 13 Jun 2018 19:08:24 +0300 Subject: [PATCH] PY-29717 Utilize try-with-resources to load documentation for keywords --- .../documentation/PyDocumentationBuilder.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java b/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java index e4e3aeda7de9..a6094385e2c2 100644 --- a/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java +++ b/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java @@ -52,7 +52,6 @@ import one.util.streamex.StreamEx; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.*; @@ -165,24 +164,14 @@ public class PyDocumentationBuilder { } } - private void buildForKeyword(@NotNull final String name) { + private void buildForKeyword(@NotNull String name) { try { - final FileReader reader = new FileReader(PythonHelpersLocator.getHelperPath("/tools/python_keywords/" + name)); - try { + try (FileReader reader = new FileReader(PythonHelpersLocator.getHelperPath("/tools/python_keywords/" + name))) { final String text = FileUtil.loadTextAndClose(reader); myContent.addItem(StringUtil.convertLineSeparators(text, "\n")); } - catch (IOException ignored) { - } - finally { - try { - reader.close(); - } - catch (IOException ignored) { - } - } } - catch (FileNotFoundException ignored) { + catch (IOException ignored) { } }