Search in sources :

Example 1 with SettingsConfigurator

use of org.jetbrains.kotlin.test.SettingsConfigurator in project kotlin by JetBrains.

the class AbstractKotlinFoldingTest method doTestWithSettings.

protected static void doTestWithSettings(@NotNull String fileText, @NotNull Function<String, Void> runnable) {
    JavaCodeFoldingSettings settings = JavaCodeFoldingSettings.getInstance();
    JavaCodeFoldingSettingsImpl restoreSettings = new JavaCodeFoldingSettingsImpl();
    restoreSettings.loadState((JavaCodeFoldingSettingsImpl) settings);
    try {
        SettingsConfigurator configurator = new SettingsConfigurator(fileText, settings);
        configurator.configureSettings();
        runnable.apply(fileText);
    } finally {
        ((JavaCodeFoldingSettingsImpl) JavaCodeFoldingSettings.getInstance()).loadState(restoreSettings);
    }
}
Also used : SettingsConfigurator(org.jetbrains.kotlin.test.SettingsConfigurator) JavaCodeFoldingSettingsImpl(com.intellij.codeInsight.folding.impl.JavaCodeFoldingSettingsImpl) JavaCodeFoldingSettings(com.intellij.codeInsight.folding.JavaCodeFoldingSettings)

Example 2 with SettingsConfigurator

use of org.jetbrains.kotlin.test.SettingsConfigurator in project kotlin by JetBrains.

the class AbstractTypingIndentationTestBase method doNewlineTest.

public void doNewlineTest(String afterFilePath, boolean inverted) throws Exception {
    String testFileName = afterFilePath.substring(0, afterFilePath.indexOf("."));
    String testFileExtension = afterFilePath.substring(afterFilePath.lastIndexOf("."));
    String originFilePath = testFileName + testFileExtension;
    String originalFileText = FileUtil.loadFile(new File(originFilePath), true);
    try {
        SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText);
        if (!inverted) {
            configurator.configureSettings();
        } else {
            configurator.configureInvertedSettings();
        }
        doNewlineTest(originFilePath, afterFilePath);
    } finally {
        getSettings().clearCodeStyleSettings();
    }
}
Also used : SettingsConfigurator(org.jetbrains.kotlin.test.SettingsConfigurator) File(java.io.File)

Example 3 with SettingsConfigurator

use of org.jetbrains.kotlin.test.SettingsConfigurator in project kotlin by JetBrains.

the class AbstractFormatterTest method doTest.

public void doTest(@NotNull String expectedFileNameWithExtension, boolean inverted) throws Exception {
    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();
    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);
    codeStyleSettings.clearCodeStyleSettings();
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) SettingsConfigurator(org.jetbrains.kotlin.test.SettingsConfigurator) File(java.io.File) PsiFile(com.intellij.psi.PsiFile)

Aggregations

SettingsConfigurator (org.jetbrains.kotlin.test.SettingsConfigurator)3 File (java.io.File)2 JavaCodeFoldingSettings (com.intellij.codeInsight.folding.JavaCodeFoldingSettings)1 JavaCodeFoldingSettingsImpl (com.intellij.codeInsight.folding.impl.JavaCodeFoldingSettingsImpl)1 PsiFile (com.intellij.psi.PsiFile)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1