vcs: Convert "ReformatBeforeCheckinHandler" to kotlin

GitOrigin-RevId: 386ed7a13c93afccbc8c54bdab8a2148278f07e4
This commit is contained in:
Konstantin Kolosovsky
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent c0258824f5
commit 4103c2ccd8
2 changed files with 35 additions and 81 deletions
@@ -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<VirtualFile> 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()?
}
}
}
@@ -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);
}
}