Browse Source

ktlint fixes

pull/1768/head
thelumiereguy 3 years ago
parent
commit
e64e68b929
  1. 5
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/remove_composable/RemoveComposableIntention.kt
  2. 7
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/remove_parent_composable/RemoveParentComposableIntention.kt
  3. 1
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/composable_finder/DeepComposableFunctionFinder.kt
  4. 1
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/composable_finder/NestedComposableFinder.kt
  5. 11
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/get_root_element/GetRootElement.kt
  6. 3
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/is_intention_available/IsIntentionAvailable.kt
  7. 3
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/is_psi_element_composable/IsPsiElementComposable.kt
  8. 5
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/wrap_with_composable/WrapWithComposableIntentionGroup.kt
  9. 6
      idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/wrap_with_composable/wrap_with_actions/BaseWrapWithComposableAction.kt
  10. 18
      idea-plugin/src/test/kotlin/org/jetbrains/compose/intentions/utils/get_root_element/GetRootElementTest.kt

5
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/remove_composable/RemoveComposableIntention.kt

@ -6,12 +6,12 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiElement
import javax.swing.Icon
import org.jetbrains.compose.desktop.ide.preview.PreviewIcons
import org.jetbrains.compose.intentions.utils.is_intention_available.IsIntentionAvailable
import org.jetbrains.compose.intentions.utils.composable_finder.ComposableFunctionFinder
import org.jetbrains.compose.intentions.utils.composable_finder.DeepComposableFunctionFinder
import org.jetbrains.compose.intentions.utils.get_root_element.GetRootElement
import org.jetbrains.compose.intentions.utils.is_intention_available.IsIntentionAvailable
import javax.swing.Icon
class RemoveComposableIntention : PsiElementBaseIntentionAction(), Iconable, LowPriorityAction, IsIntentionAvailable {
@ -36,5 +36,4 @@ class RemoveComposableIntention : PsiElementBaseIntentionAction(), Iconable, Low
}
override fun getIcon(flags: Int): Icon = PreviewIcons.COMPOSE
}

7
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/remove_parent_composable/RemoveParentComposableIntention.kt

@ -7,16 +7,17 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiElement
import com.intellij.psi.util.parentOfType
import javax.swing.Icon
import org.jetbrains.compose.desktop.ide.preview.PreviewIcons
import org.jetbrains.compose.intentions.utils.is_intention_available.IsIntentionAvailable
import org.jetbrains.compose.intentions.utils.composable_finder.ComposableFunctionFinder
import org.jetbrains.compose.intentions.utils.composable_finder.NestedComposableFinder
import org.jetbrains.compose.intentions.utils.is_intention_available.IsIntentionAvailable
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import org.jetbrains.kotlin.psi.KtValueArgumentList
import javax.swing.Icon
class RemoveParentComposableIntention : PsiElementBaseIntentionAction(),
class RemoveParentComposableIntention :
PsiElementBaseIntentionAction(),
Iconable,
PriorityAction,
IsIntentionAvailable {

1
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/composable_finder/DeepComposableFunctionFinder.kt

@ -24,7 +24,6 @@ class DeepComposableFunctionFinder : ComposableFunctionFinder, IsPsiElementCompo
}
}
/**
* To handle both property and property delegates
*/

1
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/composable_finder/NestedComposableFinder.kt

@ -6,7 +6,6 @@ import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtLambdaArgument
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
class NestedComposableFinder : ComposableFunctionFinder, IsPsiElementComposable {
override fun isFunctionComposable(psiElement: PsiElement): Boolean {

11
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/get_root_element/GetRootElement.kt

@ -1,7 +1,12 @@
package org.jetbrains.compose.intentions.utils.get_root_element
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPropertyDelegate
import org.jetbrains.kotlin.psi.KtValueArgumentList
/**
* KtValueArgumentList -> Parent -> KtNameReferenceExpression -> Parent -> KtCallExpression -> Parent -> KtPropertyDelegate -> Parent -> Property
@ -28,8 +33,8 @@ class GetRootElement {
is KtCallExpression -> {
when (element.parent) {
is KtProperty,
is KtDotQualifiedExpression -> invoke(element.parent, iteration + 1) //composable dot expression
is KtPropertyDelegate -> invoke(element.parent.parent, iteration + 1) //composable dot expression
is KtDotQualifiedExpression -> invoke(element.parent, iteration + 1) // composable dot expression
is KtPropertyDelegate -> invoke(element.parent.parent, iteration + 1) // composable dot expression
else -> element
}
}

3
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/is_intention_available/IsIntentionAvailable.kt

@ -21,5 +21,4 @@ interface IsIntentionAvailable {
composableFunctionFinder.isFunctionComposable(parentPsiElement)
} ?: false
}
}
}

3
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/utils/is_psi_element_composable/IsPsiElementComposable.kt

@ -17,5 +17,4 @@ interface IsPsiElementComposable {
val ktNamedFunction = resolve() as? KtNamedFunction ?: return false
return ktNamedFunction.isComposableFunction()
}
}
}

5
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/wrap_with_composable/WrapWithComposableIntentionGroup.kt

@ -9,7 +9,6 @@ import com.intellij.openapi.ui.popup.util.BaseListPopupStep
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiFile
import com.intellij.ui.popup.list.ListPopupImpl
import javax.swing.Icon
import org.jetbrains.compose.desktop.ide.preview.PreviewIcons
import org.jetbrains.compose.intentions.wrap_with_composable.wrap_with_actions.BaseWrapWithComposableAction
import org.jetbrains.compose.intentions.wrap_with_composable.wrap_with_actions.WrapWithBoxIntention
@ -18,6 +17,7 @@ import org.jetbrains.compose.intentions.wrap_with_composable.wrap_with_actions.W
import org.jetbrains.compose.intentions.wrap_with_composable.wrap_with_actions.WrapWithLzyColumnIntention
import org.jetbrains.compose.intentions.wrap_with_composable.wrap_with_actions.WrapWithLzyRowIntention
import org.jetbrains.compose.intentions.wrap_with_composable.wrap_with_actions.WrapWithRowIntention
import javax.swing.Icon
class WrapWithComposableIntentionGroup :
IntentionActionGroup<BaseWrapWithComposableAction>(
@ -29,7 +29,8 @@ class WrapWithComposableIntentionGroup :
WrapWithLzyColumnIntention(),
WrapWithLzyRowIntention()
)
), Iconable {
),
Iconable {
private fun createPopup(
project: Project,

6
idea-plugin/src/main/kotlin/org/jetbrains/compose/intentions/wrap_with_composable/wrap_with_actions/BaseWrapWithComposableAction.kt

@ -7,12 +7,13 @@ import com.intellij.codeInsight.template.impl.TemplateImpl
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.compose.intentions.utils.is_intention_available.IsIntentionAvailable
import org.jetbrains.compose.intentions.utils.composable_finder.ComposableFunctionFinder
import org.jetbrains.compose.intentions.utils.composable_finder.DeepComposableFunctionFinder
import org.jetbrains.compose.intentions.utils.get_root_element.GetRootElement
import org.jetbrains.compose.intentions.utils.is_intention_available.IsIntentionAvailable
abstract class BaseWrapWithComposableAction : PsiElementBaseIntentionAction(),
abstract class BaseWrapWithComposableAction :
PsiElementBaseIntentionAction(),
HighPriorityAction,
IsIntentionAvailable {
@ -50,5 +51,4 @@ abstract class BaseWrapWithComposableAction : PsiElementBaseIntentionAction(),
}
protected abstract fun getTemplate(): TemplateImpl?
}

18
idea-plugin/src/test/kotlin/org/jetbrains/compose/intentions/utils/get_root_element/GetRootElementTest.kt

@ -14,7 +14,6 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
@ -27,7 +26,7 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
@Language("Kotlin")
val template = """
val systemUiController = rememberSystemUiController()
""".trimIndent()
""".trimIndent()
.trim()
val file = ktPsiFactory.createFile(template)
@ -39,7 +38,6 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
TestCase.assertEquals(property, getRootElement(ktNameReferenceExpression))
}
@Test
fun `when a name reference expression is selected, with a call expression as root, call expression should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@ -59,7 +57,7 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
}
}
""".trimIndent().trim()
""".trimIndent().trim()
val file = ktPsiFactory.createFile(template)
@ -73,7 +71,6 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
)
}
@Test
fun `when an argument list element is selected, with a call expression as root, call expression should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@ -93,7 +90,7 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
} // Name Reference Expression
}
""".trimIndent().trim()
""".trimIndent().trim()
val file = ktPsiFactory.createFile(template)
@ -109,7 +106,6 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
)
}
@Test
fun `when a name reference expression is selected, with a delegated property as root, property should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@ -122,7 +118,7 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
var isComposable by remember {
true
}
""".trimIndent().trim()
""".trimIndent().trim()
val file = ktPsiFactory.createFile(template)
@ -158,7 +154,7 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
)
)
)
""".trimIndent().trim()
""".trimIndent().trim()
val file = ktPsiFactory.createFile(template)
@ -174,7 +170,6 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
)
}
@Test
fun `when a name reference expression is selected, with a property and dot qualified expression as root, property should be returned`() {
val ktPsiFactory = KtPsiFactory(project)
@ -197,7 +192,7 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
)
)
)
""".trimIndent().trim()
""".trimIndent().trim()
val file = ktPsiFactory.createFile(template)
@ -212,5 +207,4 @@ class GetRootElementTest : LightJavaCodeInsightFixtureTestCase() {
getRootElement(referenceExpression)
)
}
}

Loading…
Cancel
Save