Skip to content

Commit 28a7200

Browse files
piotrtomiakintellij-monorepo-bot
authored andcommitted
[tasks] IJPL-214046 Migrate TaskCheckinHandlerFactory to Kotlin
(cherry picked from commit 5133d6ab525f90d3ba4b32b3c4a66a6274edfc02) IJ-CR-179796 GitOrigin-RevId: 5ec8cfeade40c73950a7bd7cb6b0b2a83af9eab8
1 parent 79424ac commit 28a7200

1 file changed

Lines changed: 41 additions & 64 deletions

File tree

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,50 @@
11
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
2-
package com.intellij.tasks.impl;
3-
4-
import com.intellij.openapi.application.ApplicationManager;
5-
import com.intellij.openapi.project.DumbAware;
6-
import com.intellij.openapi.project.Project;
7-
import com.intellij.openapi.vcs.CheckinProjectPanel;
8-
import com.intellij.openapi.vcs.changes.CommitContext;
9-
import com.intellij.openapi.vcs.checkin.CheckinHandler;
10-
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory;
11-
import com.intellij.tasks.LocalTask;
12-
import com.intellij.tasks.Task;
13-
import com.intellij.tasks.TaskManager;
14-
import com.intellij.tasks.TaskRepository;
15-
import com.intellij.tasks.context.WorkingContextManager;
16-
import org.jetbrains.annotations.NotNull;
17-
import org.jetbrains.annotations.Nullable;
18-
19-
import java.util.Date;
20-
21-
public class TaskCheckinHandlerFactory extends CheckinHandlerFactory {
22-
23-
@Override
24-
public @NotNull CheckinHandler createHandler(final @NotNull CheckinProjectPanel panel, final @NotNull CommitContext commitContext) {
25-
return new TaskCheckinHandler(panel);
26-
}
27-
28-
private static class TaskCheckinHandler extends CheckinHandler implements DumbAware {
29-
final @NotNull CheckinProjectPanel panel;
30-
31-
private TaskCheckinHandler(@NotNull CheckinProjectPanel panel) {
32-
this.panel = panel;
33-
}
34-
35-
@Override
36-
public void checkinSuccessful() {
37-
final String message = panel.getCommitMessage();
38-
final Project project = panel.getProject();
39-
final TaskManagerImpl manager = (TaskManagerImpl)TaskManager.getManager(project);
2+
package com.intellij.tasks.impl
3+
4+
import com.intellij.openapi.application.ApplicationManager
5+
import com.intellij.openapi.project.DumbAware
6+
import com.intellij.openapi.vcs.CheckinProjectPanel
7+
import com.intellij.openapi.vcs.changes.CommitContext
8+
import com.intellij.openapi.vcs.checkin.CheckinHandler
9+
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory
10+
import com.intellij.tasks.Task
11+
import com.intellij.tasks.TaskManager
12+
import com.intellij.tasks.context.WorkingContextManager
13+
import java.util.*
14+
15+
class TaskCheckinHandlerFactory : CheckinHandlerFactory() {
16+
override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler =
17+
TaskCheckinHandler(panel)
18+
19+
private class TaskCheckinHandler(val panel: CheckinProjectPanel) : CheckinHandler(), DumbAware {
20+
override fun checkinSuccessful() {
21+
val message = panel.getCommitMessage()
22+
val project = panel.getProject()
23+
val manager = TaskManager.getManager(project) as TaskManagerImpl
4024
if (manager.getState().saveContextOnCommit) {
41-
Task task = findTaskInRepositories(message, manager);
42-
if (task == null) {
43-
task = manager.createLocalTask(message);
44-
((LocalTaskImpl)task).setClosed(true);
45-
}
46-
LocalTask localTask = manager.addTask(task);
47-
localTask.setUpdated(new Date());
48-
49-
ApplicationManager.getApplication().invokeLater(() -> WorkingContextManager.getInstance(project).saveContext(localTask), project.getDisposed());
25+
val task = findTaskInRepositories(message, manager)
26+
?: manager.createLocalTask(message)
27+
.also { (it as LocalTaskImpl).isClosed = true }
28+
val localTask = manager.addTask(task)
29+
localTask.setUpdated(Date())
30+
31+
ApplicationManager.getApplication().invokeLater(
32+
{ WorkingContextManager.getInstance(project).saveContext(localTask) }, project.getDisposed())
5033
}
5134
}
5235
}
36+
}
5337

54-
private static @Nullable Task findTaskInRepositories(String message, TaskManager manager) {
55-
TaskRepository[] repositories = manager.getAllRepositories();
56-
for (TaskRepository repository : repositories) {
57-
String id = repository.extractId(message);
58-
if (id == null) continue;
59-
LocalTask localTask = manager.findTask(id);
60-
if (localTask != null) return localTask;
61-
try {
62-
Task task = repository.findTask(id);
63-
if (task != null) {
64-
return task;
65-
}
66-
}
67-
catch (Exception ignore) {
68-
69-
}
38+
private fun findTaskInRepositories(message: String, manager: TaskManager): Task? {
39+
val repositories = manager.getAllRepositories()
40+
for (repository in repositories) {
41+
val id = repository.extractId(message) ?: continue
42+
manager.findTask(id)?.let { return it }
43+
try {
44+
repository.findTask(id)?.let { return it }
45+
}
46+
catch (_: Exception) {
7047
}
71-
return null;
7248
}
49+
return null
7350
}

0 commit comments

Comments
 (0)