From 4103c2ccd8e732d8a326194f2ae3f9d532efef09 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Sat, 29 Jun 2019 20:12:45 +0300 Subject: [PATCH] vcs: Convert "ReformatBeforeCheckinHandler" to kotlin GitOrigin-RevId: 386ed7a13c93afccbc8c54bdab8a2148278f07e4 --- .../checkin/ReformatBeforeCheckinHandler.kt | 84 ++++++++----------- .../ReformatCheckinHandlerFactory.java | 32 ------- 2 files changed, 35 insertions(+), 81 deletions(-) delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatCheckinHandlerFactory.java diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.kt index 791d8d3dc249..639475c9e444 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.kt @@ -1,62 +1,48 @@ -// Copyright 2000-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 file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.openapi.vcs.checkin; +package com.intellij.openapi.vcs.checkin -import com.intellij.codeInsight.actions.ReformatCodeProcessor; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.CheckinProjectPanel; -import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.VcsConfiguration; -import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption; -import com.intellij.openapi.vcs.ui.RefreshableOnComponent; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.formatter.FormatterUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.intellij.codeInsight.actions.ReformatCodeProcessor +import com.intellij.openapi.fileEditor.FileDocumentManager +import com.intellij.openapi.project.DumbService +import com.intellij.openapi.project.Project +import com.intellij.openapi.vcs.CheckinProjectPanel +import com.intellij.openapi.vcs.VcsBundle.message +import com.intellij.openapi.vcs.VcsConfiguration +import com.intellij.openapi.vcs.changes.CommitContext +import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption +import com.intellij.openapi.vcs.checkin.CheckinHandlerUtil.getPsiFiles +import com.intellij.openapi.vcs.ui.RefreshableOnComponent +import com.intellij.psi.formatter.FormatterUtil.REFORMAT_BEFORE_COMMIT_COMMAND_NAME -import java.util.Collection; +open class ReformatCheckinHandlerFactory : CheckinHandlerFactory() { + override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler = + ReformatBeforeCheckinHandler(panel.project, panel) +} -public class ReformatBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler { - protected final Project myProject; - private final CheckinProjectPanel myPanel; +open class ReformatBeforeCheckinHandler( + @JvmField protected val myProject: Project, + private val panel: CheckinProjectPanel +) : CheckinHandler(), + CheckinMetaHandler { - public ReformatBeforeCheckinHandler(final Project project, final CheckinProjectPanel panel) { - myProject = project; - myPanel = panel; - } + private val settings get() = VcsConfiguration.getInstance(myProject) - @Override - @Nullable - public RefreshableOnComponent getBeforeCheckinConfigurationPanel() { - return new BooleanCommitOption(myPanel, VcsBundle.message("checkbox.checkin.options.reformat.code"), true, - () -> getSettings().REFORMAT_BEFORE_PROJECT_COMMIT, - value -> getSettings().REFORMAT_BEFORE_PROJECT_COMMIT = value); - } + override fun getBeforeCheckinConfigurationPanel(): RefreshableOnComponent = + BooleanCommitOption(panel, message("checkbox.checkin.options.reformat.code"), true, settings::REFORMAT_BEFORE_PROJECT_COMMIT) - protected VcsConfiguration getSettings() { - return VcsConfiguration.getInstance(myProject); - } + override fun runCheckinHandlers(runnable: Runnable) { + val saveAndContinue = { + FileDocumentManager.getInstance().saveAllDocuments() + runnable.run() + } - @Override - public void runCheckinHandlers(@NotNull final Runnable finishAction) { - final VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); - final Collection files = myPanel.getVirtualFiles(); - - final Runnable performCheckoutAction = () -> { - FileDocumentManager.getInstance().saveAllDocuments(); - finishAction.run(); - }; - - if (configuration.REFORMAT_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(myProject)) { - new ReformatCodeProcessor( - myProject, CheckinHandlerUtil.getPsiFiles(myProject, files), FormatterUtil.REFORMAT_BEFORE_COMMIT_COMMAND_NAME, performCheckoutAction, true - ).run(); + if (settings.REFORMAT_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(myProject)) { + ReformatCodeProcessor(myProject, getPsiFiles(myProject, panel.virtualFiles), REFORMAT_BEFORE_COMMIT_COMMAND_NAME, saveAndContinue, + true).run() } else { - performCheckoutAction.run(); + saveAndContinue() // TODO just runnable.run()? } - } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatCheckinHandlerFactory.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatCheckinHandlerFactory.java deleted file mode 100644 index 28c6e82135b3..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatCheckinHandlerFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.openapi.vcs.checkin; - -import com.intellij.openapi.vcs.CheckinProjectPanel; -import com.intellij.openapi.vcs.changes.CommitContext; -import org.jetbrains.annotations.NotNull; - -/** - * @author yole - */ -public class ReformatCheckinHandlerFactory extends CheckinHandlerFactory { - @Override - @NotNull - public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) { - return new ReformatBeforeCheckinHandler(panel.getProject(), panel); - } -} \ No newline at end of file