From ae3cd600caaa50e04fc8ac2c31b12816d73af902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Marks?= Date: Thu, 4 Oct 2018 19:17:34 +0200 Subject: [PATCH] Reintroduces ignored formatter tests --- .../utils/CodeStyleConfigurator.kt | 37 +++++++++++++------ .../formatter/KotlinIdeaFormatActionTest.java | 37 +------------------ 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/CodeStyleConfigurator.kt b/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/CodeStyleConfigurator.kt index 232f6ef3a..133aa1c64 100644 --- a/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/CodeStyleConfigurator.kt +++ b/kotlin-eclipse-test-framework/src/org/jetbrains/kotlin/testframework/utils/CodeStyleConfigurator.kt @@ -4,6 +4,7 @@ import org.eclipse.core.resources.IProject import org.eclipse.core.resources.ProjectScope import org.jetbrains.kotlin.core.formatting.KotlinCodeStyleManager import org.jetbrains.kotlin.core.preferences.KotlinCodeStyleProperties +import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings import java.util.* import kotlin.reflect.KFunction @@ -21,16 +22,24 @@ object CodeStyleConfigurator { KotlinCodeStyleManager.getOrCreate(generatedId) { val kotlinSettings = getCustomSettings(KotlinCodeStyleSettings::class.java) + val commonSettings = getCommonSettings(KotlinLanguage.INSTANCE) + + fun setDynamic(prop: String, value: Any) { + kotlinSettings.setDynamic(prop, value) or commonSettings.setDynamic(prop, value) + } InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_TRUE:") - .forEach { kotlinSettings[it] = true } + .forEach { setDynamic(it, true) } InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_FALSE:") - .forEach { kotlinSettings[it] = false } + .forEach { setDynamic(it, false) } InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_INT:") .map { it.split("=", limit = 2) } - .forEach { (prop, value) -> kotlinSettings[prop] = value.toInt() } + .forEach { (prop, value) -> setDynamic(prop, value.trim().toInt()) } + + InTextDirectivesUtils.findStringWithPrefixes(fileText, "RIGHT_MARGIN: ") + ?.also { commonSettings.RIGHT_MARGIN = it.trim().toInt() } } } @@ -42,13 +51,17 @@ object CodeStyleConfigurator { } } - private operator fun Any.set(name: String, value: Any) { - this::class.members.single { it.name in setOf(name) }.let { - when (it) { - is KMutableProperty -> it.setter.call(this, value) - is KFunction -> it.call(this, value) - else -> throw AssertionError("Field or method with name $name does not exist") - } - } - } + private fun Any.setDynamic(name: String, value: Any): Boolean = + this::class.members.singleOrNull { it.name in setOf(name) } + ?.let { + when (it) { + is KMutableProperty -> it.setter + is KFunction -> it + else -> null + } + } + ?.call(this, value) + ?.let { true } + ?: false + } \ No newline at end of file diff --git a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinIdeaFormatActionTest.java b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinIdeaFormatActionTest.java index 0491ba2ba..5e9c8d88a 100644 --- a/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinIdeaFormatActionTest.java +++ b/kotlin-eclipse-ui-test/src/org/jetbrains/kotlin/ui/tests/editors/formatter/KotlinIdeaFormatActionTest.java @@ -1,6 +1,5 @@ package org.jetbrains.kotlin.ui.tests.editors.formatter; -import org.junit.Ignore; import org.junit.Test; public class KotlinIdeaFormatActionTest extends KotlinFormatActionTestCase { @@ -34,25 +33,21 @@ public void ArrayAccess() { doAutoTest(); } - @Ignore @Test public void BinaryExpressionAlignmentSpread() { doAutoTest(); } - @Ignore @Test public void BinaryExpressions() { doAutoTest(); } - @Ignore @Test public void BinaryExpressionsBoolean() { doAutoTest(); } - @Ignore @Test public void BinaryExpressionsWithoutAlignment() { doAutoTest(); @@ -63,7 +58,6 @@ public void BlockFor() { doAutoTest(); } - @Ignore @Test public void CatchFinallyOnNewLine() { doAutoTest(); @@ -94,19 +88,6 @@ public void CommentInFunctionLiteral() { doAutoTest(); } - @Ignore - @Test - public void ConsecutiveCalls() { - doAutoTest(); - } - - @Ignore - @Test - public void ConsecutiveSafeCallsIndent() { - doAutoTest(); - } - - @Ignore @Test public void DelegationList() { doAutoTest(); @@ -127,13 +108,11 @@ public void DoWhileSpacing() { doAutoTest(); } - @Ignore @Test public void ElseOnNewLine() { doAutoTest(); } - @Ignore @Test public void Elvis() { doAutoTest(); @@ -164,7 +143,6 @@ public void EmptyLineBetweenClasses() { doAutoTest(); } - @Ignore @Test public void EmptyLineBetweenEnumEntries() { doAutoTest(); @@ -190,13 +168,11 @@ public void ForLineBreak() { doAutoTest(); } - @Ignore @Test public void FormatFirstColumnComments() { doAutoTest(); } - @Ignore @Test public void FormatFirstColumnCommentsBeforeDeclaration() { doAutoTest(); @@ -217,7 +193,6 @@ public void FunctionalType() { doAutoTest(); } - @Ignore @Test public void FunctionCallParametersAlign() { doAutoTest(); @@ -237,13 +212,7 @@ public void FunctionExpression() { public void FunctionLineBreak() { doAutoTest(); } - - @Ignore - @Test - public void FunctionLiteralsInChainCalls() { - doAutoTest(); - } - + @Test public void FunctionWithInference() { doAutoTest(); @@ -364,7 +333,6 @@ public void ReturnExpression() { doAutoTest(); } - @Ignore @Test public void RightBracketOnNewLine() { doAutoTest(); @@ -415,13 +383,11 @@ public void SpacedInsideParans() { doAutoTest(); } - @Ignore @Test public void SpacesAroundOperations() { doAutoTest(); } - @Ignore @Test public void SpacesAroundUnaryOperations() { doAutoTest(); @@ -482,7 +448,6 @@ public void WhileLineBreak() { doAutoTest(); } - @Ignore @Test public void WhileOnNewLine() { doAutoTest();