diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml index c122734b079..ec87967af16 100644 --- a/.idea/inspectionProfiles/idea_default.xml +++ b/.idea/inspectionProfiles/idea_default.xml @@ -115,6 +115,7 @@ + diff --git a/compiler/psi/src/org/jetbrains/kotlin/idea/KotlinLanguage.java b/compiler/psi/src/org/jetbrains/kotlin/idea/KotlinLanguage.java index 771eda4b1bd..b5d15b01de2 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/idea/KotlinLanguage.java +++ b/compiler/psi/src/org/jetbrains/kotlin/idea/KotlinLanguage.java @@ -20,6 +20,7 @@ import com.intellij.lang.Language; import org.jetbrains.annotations.NotNull; public class KotlinLanguage extends Language { + @NotNull public static final KotlinLanguage INSTANCE = new KotlinLanguage(); public static final String NAME = "Kotlin"; diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index fc412d1278d..6d68261bd79 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -635,18 +635,25 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - Caret caret = editor.getCaretModel().getCurrentCaret(); - int selectionStart = caret.getSelectionStart(); - int selectionEnd = caret.getSelectionEnd(); + assertEqualsToFile(expectedFile, editor, true); + } - String afterText = TagsTestDataUtil.insertTagsInText( - Lists.newArrayList( - new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), - new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), - new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), - editor.getDocument().getText() + public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor, Boolean enableSelectionTags) { + Caret caret = editor.getCaretModel().getCurrentCaret(); + List tags = Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret") ); + if (enableSelectionTags) { + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + tags.add(new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection")); + tags.add(new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")); + } + + String afterText = TagsTestDataUtil.insertTagsInText(tags, editor.getDocument().getText()); + assertEqualsToFile(expectedFile, afterText); } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 index 9830c40f87b..04cf71916d2 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 @@ -631,18 +631,25 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - Caret caret = editor.getCaretModel().getCurrentCaret(); - int selectionStart = caret.getSelectionStart(); - int selectionEnd = caret.getSelectionEnd(); + assertEqualsToFile(expectedFile, editor, true); + } - String afterText = TagsTestDataUtil.insertTagsInText( - Lists.newArrayList( - new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), - new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), - new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), - editor.getDocument().getText() + public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor, Boolean enableSelectionTags) { + Caret caret = editor.getCaretModel().getCurrentCaret(); + List tags = Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret") ); + if (enableSelectionTags) { + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + tags.add(new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection")); + tags.add(new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")); + } + + String afterText = TagsTestDataUtil.insertTagsInText(tags, editor.getDocument().getText()); + assertEqualsToFile(expectedFile, afterText); } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 index 43052895878..c78eb4c6e0f 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 @@ -631,18 +631,25 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - Caret caret = editor.getCaretModel().getCurrentCaret(); - int selectionStart = caret.getSelectionStart(); - int selectionEnd = caret.getSelectionEnd(); + assertEqualsToFile(expectedFile, editor, true); + } - String afterText = TagsTestDataUtil.insertTagsInText( - Lists.newArrayList( - new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), - new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), - new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), - editor.getDocument().getText() + public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor, Boolean enableSelectionTags) { + Caret caret = editor.getCaretModel().getCurrentCaret(); + List tags = Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret") ); + if (enableSelectionTags) { + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + tags.add(new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection")); + tags.add(new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")); + } + + String afterText = TagsTestDataUtil.insertTagsInText(tags, editor.getDocument().getText()); + assertEqualsToFile(expectedFile, afterText); } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 index 29934b07cb8..5a8b2cc0c29 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 @@ -631,18 +631,25 @@ public class KotlinTestUtils { } public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) { - Caret caret = editor.getCaretModel().getCurrentCaret(); - int selectionStart = caret.getSelectionStart(); - int selectionEnd = caret.getSelectionEnd(); + assertEqualsToFile(expectedFile, editor, true); + } - String afterText = TagsTestDataUtil.insertTagsInText( - Lists.newArrayList( - new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret"), - new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection"), - new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")), - editor.getDocument().getText() + public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor, Boolean enableSelectionTags) { + Caret caret = editor.getCaretModel().getCurrentCaret(); + List tags = Lists.newArrayList( + new TagsTestDataUtil.TagInfo<>(caret.getOffset(), true, "caret") ); + if (enableSelectionTags) { + int selectionStart = caret.getSelectionStart(); + int selectionEnd = caret.getSelectionEnd(); + + tags.add(new TagsTestDataUtil.TagInfo<>(selectionStart, true, "selection")); + tags.add(new TagsTestDataUtil.TagInfo<>(selectionEnd, false, "selection")); + } + + String afterText = TagsTestDataUtil.insertTagsInText(tags, editor.getDocument().getText()); + assertEqualsToFile(expectedFile, afterText); } diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index a83121bf5f9..39c7c56f67b 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -441,6 +441,7 @@ + diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/CodeStyleSettingsProviderCompat.java b/idea/src/org/jetbrains/kotlin/idea/formatter/CodeStyleSettingsProviderCompat.java new file mode 100644 index 00000000000..ff80f7b9d3f --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/CodeStyleSettingsProviderCompat.java @@ -0,0 +1,30 @@ +/* + * Copyright 2010-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/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.formatter; + +import com.intellij.openapi.options.Configurable; +import com.intellij.psi.codeStyle.CodeStyleConfigurable; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsProvider; +import org.jetbrains.annotations.NotNull; + +// Additional method is introduced in 183 instead of deprecated one +// BUNCH: 182 +@SuppressWarnings("IncompatibleAPI") +public abstract class CodeStyleSettingsProviderCompat extends CodeStyleSettingsProvider { + // Can't use @Override because it's going to be an error in 182 + @SuppressWarnings("override") + @NotNull + public abstract CodeStyleConfigurable createConfigurable(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings modelSettings); + + // Should be implemented or it's going to be error in 182 + @SuppressWarnings("deprecation") + @Override + @NotNull + public Configurable createSettingsPage(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings modelSettings) { + return createConfigurable(settings, modelSettings); + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleGenerationConfigurable.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleGenerationConfigurable.kt new file mode 100644 index 00000000000..d8f12076230 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleGenerationConfigurable.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2010-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/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.formatter + +import com.intellij.application.options.codeStyle.CommenterForm +import com.intellij.openapi.application.ApplicationBundle +import com.intellij.psi.codeStyle.CodeStyleConfigurable +import com.intellij.psi.codeStyle.CodeStyleSettings +import com.intellij.psi.codeStyle.DisplayPriority +import com.intellij.ui.IdeBorderFactory +import com.intellij.util.ui.JBInsets +import org.jetbrains.kotlin.idea.KotlinLanguage +import javax.swing.BoxLayout +import javax.swing.JComponent +import javax.swing.JPanel + +class KotlinGenerationSettingsProvider : CodeStyleSettingsProviderCompat() { + override fun createConfigurable(settings: CodeStyleSettings, modelSettings: CodeStyleSettings): CodeStyleConfigurable { + return KotlinCodeStyleGenerationConfigurable(settings) + } + + override fun getConfigurableDisplayName(): String = ApplicationBundle.message("title.code.generation") + override fun getPriority(): DisplayPriority = DisplayPriority.CODE_SETTINGS + override fun hasSettingsPage() = false + override fun getLanguage() = KotlinLanguage.INSTANCE +} + +class KotlinCodeStyleGenerationConfigurable(private val mySettings: CodeStyleSettings) : CodeStyleConfigurable { + private val myCommenterForm: CommenterForm = CommenterForm(KotlinLanguage.INSTANCE) + + override fun getDisplayName(): String = ApplicationBundle.message("title.code.generation") + + override fun createComponent(): JComponent { + return JPanel().apply { + layout = BoxLayout(this, BoxLayout.Y_AXIS) + border = IdeBorderFactory.createEmptyBorder(JBInsets(0, 10, 10, 10)) + add(myCommenterForm.commenterPanel) + } + } + + override fun isModified(): Boolean { + return myCommenterForm.isModified(mySettings) + } + + override fun apply() { + apply(mySettings) + } + + override fun reset() { + reset(mySettings) + } + + override fun reset(settings: CodeStyleSettings) { + myCommenterForm.reset(settings) + } + + override fun apply(settings: CodeStyleSettings) { + myCommenterForm.apply(settings) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java index a4f26ce1a61..aa7d72b1c45 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java @@ -20,7 +20,7 @@ import com.intellij.application.options.CodeStyleAbstractConfigurable; import com.intellij.application.options.CodeStyleAbstractPanel; import com.intellij.application.options.TabbedLanguageCodeStylePanel; import com.intellij.lang.Language; -import com.intellij.openapi.options.Configurable; +import com.intellij.psi.codeStyle.CodeStyleConfigurable; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsProvider; import com.intellij.psi.codeStyle.CustomCodeStyleSettings; @@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.KotlinLanguage; import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings; -public class KotlinCodeStyleSettingsProvider extends CodeStyleSettingsProvider { +public class KotlinCodeStyleSettingsProvider extends CodeStyleSettingsProviderCompat { @Override public String getConfigurableDisplayName() { @@ -47,8 +47,8 @@ public class KotlinCodeStyleSettingsProvider extends CodeStyleSettingsProvider { @NotNull @Override - public Configurable createSettingsPage(CodeStyleSettings settings, CodeStyleSettings originalSettings) { - return new CodeStyleAbstractConfigurable(settings, originalSettings, KotlinLanguage.NAME) { + public CodeStyleConfigurable createConfigurable(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings modelSettings) { + return new CodeStyleAbstractConfigurable(settings, modelSettings, KotlinLanguage.NAME) { @Override protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) { return new TabbedLanguageCodeStylePanel(KotlinLanguage.INSTANCE, getCurrentSettings(), settings) { @@ -60,6 +60,14 @@ public class KotlinCodeStyleSettingsProvider extends CodeStyleSettingsProvider { addWrappingAndBracesTab(settings); addBlankLinesTab(settings); addTab(new ImportSettingsPanelWrapper(settings)); + + //noinspection IncompatibleAPI + for (CodeStyleSettingsProvider provider : CodeStyleSettingsProvider.EXTENSION_POINT_NAME.getExtensions()) { + if (provider.getLanguage() == KotlinLanguage.INSTANCE && !provider.hasSettingsPage()) { + createTab(provider); + } + } + addTab(new KotlinSaveStylePanel(settings)); } }; diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt index 94b1500ac36..7108b129bc7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt @@ -369,6 +369,9 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide CodeStyleSettingsCustomizable.BLANK_LINES ) } + LanguageCodeStyleSettingsProvider.SettingsType.COMMENTER_SETTINGS -> { + consumer.showAllStandardOptions(); + } else -> consumer.showStandardOptions() } } diff --git a/idea/testData/editor/commenter/notFirstColumnWithSpace.kt b/idea/testData/editor/commenter/notFirstColumnWithSpace.kt new file mode 100644 index 00000000000..a5e7ff5c60f --- /dev/null +++ b/idea/testData/editor/commenter/notFirstColumnWithSpace.kt @@ -0,0 +1,6 @@ +fun test() { + println() +} + +// SET_FALSE: LINE_COMMENT_AT_FIRST_COLUMN +// SET_TRUE: LINE_COMMENT_ADD_SPACE \ No newline at end of file diff --git a/idea/testData/editor/commenter/notFirstColumnWithSpace_after.kt b/idea/testData/editor/commenter/notFirstColumnWithSpace_after.kt new file mode 100644 index 00000000000..7f66077448b --- /dev/null +++ b/idea/testData/editor/commenter/notFirstColumnWithSpace_after.kt @@ -0,0 +1,6 @@ +fun test() { + // println() +} + +// SET_FALSE: LINE_COMMENT_AT_FIRST_COLUMN +// SET_TRUE: LINE_COMMENT_ADD_SPACE \ No newline at end of file diff --git a/idea/testData/editor/commenter/notFirstColumnWithoutSpace.kt b/idea/testData/editor/commenter/notFirstColumnWithoutSpace.kt new file mode 100644 index 00000000000..7e6be513265 --- /dev/null +++ b/idea/testData/editor/commenter/notFirstColumnWithoutSpace.kt @@ -0,0 +1,6 @@ +fun test() { + println() +} + +// SET_FALSE: LINE_COMMENT_AT_FIRST_COLUMN +// SET_FALSE: LINE_COMMENT_ADD_SPACE \ No newline at end of file diff --git a/idea/testData/editor/commenter/notFirstColumnWithoutSpace_after.kt b/idea/testData/editor/commenter/notFirstColumnWithoutSpace_after.kt new file mode 100644 index 00000000000..52342c86ba2 --- /dev/null +++ b/idea/testData/editor/commenter/notFirstColumnWithoutSpace_after.kt @@ -0,0 +1,6 @@ +fun test() { + //println() +} + +// SET_FALSE: LINE_COMMENT_AT_FIRST_COLUMN +// SET_FALSE: LINE_COMMENT_ADD_SPACE \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java b/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java index 72e51a1427d..f3c3c40b792 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java @@ -141,23 +141,25 @@ public abstract class AbstractFormatterTest extends LightIdeaTestCase { String testFileName = expectedFileNameWithExtension.substring(0, expectedFileNameWithExtension.indexOf(".")); String testFileExtension = expectedFileNameWithExtension.substring(expectedFileNameWithExtension.lastIndexOf(".")); String originalFileText = FileUtil.loadFile(new File(testFileName + testFileExtension), true); + CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(); + try { + Integer rightMargin = InTextDirectivesUtils.getPrefixedInt(originalFileText, "// RIGHT_MARGIN: "); + if (rightMargin != null) { + codeStyleSettings.setRightMargin(KotlinLanguage.INSTANCE, rightMargin); + } - Integer rightMargin = InTextDirectivesUtils.getPrefixedInt(originalFileText, "// RIGHT_MARGIN: "); - if (rightMargin != null) { - codeStyleSettings.setRightMargin(KotlinLanguage.INSTANCE, rightMargin); + SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, codeStyleSettings); + if (!inverted) { + configurator.configureSettings(); + } + else { + configurator.configureInvertedSettings(); + } + + doTextTest(originalFileText, new File(expectedFileNameWithExtension), testFileExtension); + } finally { + codeStyleSettings.clearCodeStyleSettings(); } - - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, codeStyleSettings); - if (!inverted) { - configurator.configureSettings(); - } - else { - configurator.configureInvertedSettings(); - } - - doTextTest(originalFileText, new File(expectedFileNameWithExtension), testFileExtension); - - codeStyleSettings.clearCodeStyleSettings(); } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java b/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java index bcaf0565bc5..9c69d29087b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java @@ -17,9 +17,13 @@ package org.jetbrains.kotlin.idea.editor; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.testFramework.EditorTestUtil; import com.intellij.testFramework.LightCodeInsightTestCase; +import org.jetbrains.kotlin.formatter.FormatSettingsUtil; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.SettingsConfigurator; import java.io.File; @@ -39,21 +43,53 @@ public class KotlinCommenterTest extends LightCodeInsightTestCase { doNewLineTypingTest(); } + public void testNotFirstColumnWithSpace() throws Exception { + doLineCommentTest(); + } + + public void testNotFirstColumnWithoutSpace() throws Exception { + doLineCommentTest(); + } + private void doNewLineTypingTest() throws Exception { configure(); EditorTestUtil.performTypingAction(getEditor(), '\n'); check(); } + private void doLineCommentTest() throws Exception { + configure(); + + CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(); + try { + String text = myFile.getText(); + + SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(text, codeStyleSettings); + configurator.configureSettings(); + + executeAction("CommentByLineComment"); + } finally { + codeStyleSettings.clearCodeStyleSettings(); + } + + check(); + } + private void configure() throws Exception { configureFromFileText("a.kt", loadFile(getTestName(true) + ".kt")); } - private void check() throws Exception { - checkResultByText(loadFile(getTestName(true) + "_after.kt")); + private void check() { + File afterFile = getTestFile(getTestName(true) + "_after.kt"); + KotlinTestUtils.assertEqualsToFile(afterFile, getEditor(), false); } - protected static String loadFile(String name) throws Exception { - return FileUtil.loadFile(new File(BASE_PATH, name), true); + private static File getTestFile(String name) { + return new File(BASE_PATH, name); + } + + private static String loadFile(String name) throws Exception { + File file = getTestFile(name); + return FileUtil.loadFile(file, true); } }