From 05043bf2159d93f93a92d4a987dcf3afd58329ae Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Sun, 24 Mar 2024 17:40:59 +0100 Subject: [PATCH] [vcs-log-graph] convert controller classes to kotlin GitOrigin-RevId: 4d2a16b55201bf2076748de488fc5361b12b4c27 --- .../collapsing/BranchFilterController.kt | 81 ++++--------- .../graph/impl/facade/CascadeController.kt | 90 +++++--------- .../graph/impl/facade/FilteredController.kt | 112 ++++++------------ 3 files changed, 83 insertions(+), 200 deletions(-) diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/collapsing/BranchFilterController.kt b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/collapsing/BranchFilterController.kt index b27506cfb533..c7d909815160 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/collapsing/BranchFilterController.kt +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/collapsing/BranchFilterController.kt @@ -1,71 +1,36 @@ -/* - * Copyright 2000-2015 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.vcs.log.graph.collapsing; +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.log.graph.collapsing -import com.intellij.vcs.log.graph.api.LinearGraph; -import com.intellij.vcs.log.graph.api.elements.GraphElement; -import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo; -import com.intellij.vcs.log.graph.impl.facade.CascadeController; -import com.intellij.vcs.log.graph.impl.facade.LinearGraphController; -import com.intellij.vcs.log.graph.utils.GraphUtilKt; -import com.intellij.vcs.log.graph.utils.UnsignedBitSet; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.intellij.vcs.log.graph.api.elements.GraphElement +import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo +import com.intellij.vcs.log.graph.impl.facade.CascadeController +import com.intellij.vcs.log.graph.impl.facade.LinearGraphController +import com.intellij.vcs.log.graph.utils.getReachableNodes -import java.util.Set; +class BranchFilterController(delegateLinearGraphController: LinearGraphController, + permanentGraphInfo: PermanentGraphInfo<*>, + idsOfVisibleBranches: Set?) : CascadeController(delegateLinearGraphController, permanentGraphInfo) { + private var collapsedGraph: CollapsedGraph + private val visibility = permanentGraphInfo.linearGraph.getReachableNodes(idsOfVisibleBranches) -public class BranchFilterController extends CascadeController { - @NotNull private CollapsedGraph myCollapsedGraph; - @NotNull private final UnsignedBitSet myVisibility; - - public BranchFilterController(@NotNull LinearGraphController delegateLinearGraphController, - @NotNull PermanentGraphInfo permanentGraphInfo, - @Nullable Set idsOfVisibleBranches) { - super(delegateLinearGraphController, permanentGraphInfo); - myVisibility = GraphUtilKt.getReachableNodes(myPermanentGraphInfo.getLinearGraph(), idsOfVisibleBranches); - myCollapsedGraph = update(); + init { + collapsedGraph = update() } - @NotNull - private CollapsedGraph update() { - return CollapsedGraph.newInstance(getDelegateController().getCompiledGraph(), myVisibility); + private fun update(): CollapsedGraph { + return CollapsedGraph.newInstance(delegateController.compiledGraph, visibility) } - @NotNull - @Override - protected LinearGraphAnswer delegateGraphChanged(@NotNull LinearGraphAnswer delegateAnswer) { - if (delegateAnswer.getGraphChanges() != null) myCollapsedGraph = update(); - return delegateAnswer; + override fun delegateGraphChanged(delegateAnswer: LinearGraphController.LinearGraphAnswer): LinearGraphController.LinearGraphAnswer { + if (delegateAnswer.graphChanges != null) collapsedGraph = update() + return delegateAnswer } - @Nullable - @Override - protected LinearGraphAnswer performAction(@NotNull LinearGraphAction action) { - return null; - } + override fun performAction(action: LinearGraphController.LinearGraphAction) = null - @NotNull - @Override - public LinearGraph getCompiledGraph() { - return myCollapsedGraph.getCompiledGraph(); - } + override fun getCompiledGraph() = collapsedGraph.compiledGraph - @Nullable - @Override - protected GraphElement convertToDelegate(@NotNull GraphElement graphElement) { - return CollapsedController.convertToDelegate(graphElement, myCollapsedGraph); + override fun convertToDelegate(graphElement: GraphElement): GraphElement? { + return CollapsedController.convertToDelegate(graphElement, collapsedGraph) } } diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/CascadeController.kt b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/CascadeController.kt index bedd4d419f06..d4a2e8f88f02 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/CascadeController.kt +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/CascadeController.kt @@ -1,76 +1,40 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.vcs.log.graph.impl.facade; +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.log.graph.impl.facade -import com.intellij.vcs.log.graph.api.elements.GraphElement; -import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo; -import com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.intellij.vcs.log.graph.api.elements.GraphElement +import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo +import com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement -import java.util.function.Function; - -public abstract class CascadeController implements LinearGraphController { - private final @NotNull LinearGraphController myDelegateController; - @NotNull protected final PermanentGraphInfo myPermanentGraphInfo; - - protected CascadeController(@NotNull LinearGraphController delegateController, @NotNull PermanentGraphInfo permanentGraphInfo) { - myDelegateController = delegateController; - myPermanentGraphInfo = permanentGraphInfo; +abstract class CascadeController protected constructor(protected val delegateController: LinearGraphController, + val permanentGraphInfo: PermanentGraphInfo<*>) : LinearGraphController { + override fun performLinearGraphAction(action: LinearGraphController.LinearGraphAction): LinearGraphController.LinearGraphAnswer { + val answer = performAction(action) + if (answer != null) return answer + val delegateAction = VisibleGraphImpl.LinearGraphActionImpl(convertToDelegate(action.affectedElement), action.type) + return delegateGraphChanged(delegateController.performLinearGraphAction(delegateAction)) } - @NotNull - @Override - public LinearGraphAnswer performLinearGraphAction(@NotNull LinearGraphAction action) { - LinearGraphAnswer answer = performAction(action); - if (answer != null) { - return answer; + internal fun performAction(action: (CascadeController) -> GraphChanges?): GraphChanges? { + val graphChanges = action(this) + if (graphChanges != null) return graphChanges + + if (delegateController is CascadeController) { + val result = delegateController.performAction(action) ?: return null + return delegateGraphChanged(LinearGraphController.LinearGraphAnswer(result)).graphChanges } - VisibleGraphImpl.LinearGraphActionImpl delegateAction = - new VisibleGraphImpl.LinearGraphActionImpl(convertToDelegate(action.getAffectedElement()), action.getType()); - return delegateGraphChanged(myDelegateController.performLinearGraphAction(delegateAction)); + return null } - @Nullable - GraphChanges performAction(@NotNull Function> action) { - GraphChanges graphChanges = action.apply(this); - if (graphChanges != null) return graphChanges; - - if (myDelegateController instanceof CascadeController) { - GraphChanges result = ((CascadeController)myDelegateController).performAction(action); - if (result != null) { - return delegateGraphChanged(new LinearGraphController.LinearGraphAnswer(result)).getGraphChanges(); - } - } - return null; + private fun convertToDelegate(element: PrintElementWithGraphElement?): PrintElementWithGraphElement? { + if (element == null) return null + val convertedGraphElement = convertToDelegate(element.graphElement) ?: return null + return PrintElementWithGraphElement.converted(element, convertedGraphElement) } - @Nullable - private PrintElementWithGraphElement convertToDelegate(@Nullable PrintElementWithGraphElement element) { - if (element == null) return null; - GraphElement convertedGraphElement = convertToDelegate(element.getGraphElement()); - if (convertedGraphElement == null) return null; - return PrintElementWithGraphElement.converted(element, convertedGraphElement); - } + protected open fun convertToDelegate(graphElement: GraphElement): GraphElement? = graphElement - @Nullable - protected GraphElement convertToDelegate(@NotNull GraphElement graphElement) { - return graphElement; - } - - @NotNull - protected LinearGraphController getDelegateController() { - return myDelegateController; - } - - @NotNull - public PermanentGraphInfo getPermanentGraphInfo() { - return myPermanentGraphInfo; - } - - @NotNull - protected abstract LinearGraphAnswer delegateGraphChanged(@NotNull LinearGraphAnswer delegateAnswer); + protected abstract fun delegateGraphChanged(delegateAnswer: LinearGraphController.LinearGraphAnswer): LinearGraphController.LinearGraphAnswer // null mean that this action must be performed by delegateGraphController - @Nullable - protected abstract LinearGraphAnswer performAction(@NotNull LinearGraphAction action); + protected abstract fun performAction(action: LinearGraphController.LinearGraphAction): LinearGraphController.LinearGraphAnswer? } diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/FilteredController.kt b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/FilteredController.kt index 57bf1d0913d3..0d24ab52de40 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/FilteredController.kt +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/FilteredController.kt @@ -1,100 +1,54 @@ -/* - * Copyright 2000-2015 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.vcs.log.graph.impl.facade; +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.log.graph.impl.facade -import com.intellij.vcs.log.graph.api.LinearGraph; -import com.intellij.vcs.log.graph.api.elements.GraphElement; -import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo; -import com.intellij.vcs.log.graph.collapsing.CollapsedGraph; -import com.intellij.vcs.log.graph.collapsing.DottedFilterEdgesGenerator; -import com.intellij.vcs.log.graph.utils.DfsWalk; -import com.intellij.vcs.log.graph.utils.LinearGraphUtils; -import com.intellij.vcs.log.graph.utils.UnsignedBitSet; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.intellij.vcs.log.graph.api.elements.GraphElement +import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo +import com.intellij.vcs.log.graph.collapsing.CollapsedGraph +import com.intellij.vcs.log.graph.collapsing.DottedFilterEdgesGenerator.Companion.update +import com.intellij.vcs.log.graph.utils.DfsWalk +import com.intellij.vcs.log.graph.utils.LinearGraphUtils +import com.intellij.vcs.log.graph.utils.UnsignedBitSet -import java.util.Set; +open class FilteredController(delegateLinearGraphController: LinearGraphController, + permanentGraphInfo: PermanentGraphInfo<*>, + matchedIds: Set, + visibleHeadsIds: Set? = null) : + CascadeController(delegateLinearGraphController, permanentGraphInfo) { -public class FilteredController extends CascadeController { - @NotNull private final CollapsedGraph myCollapsedGraph; + val collapsedGraph: CollapsedGraph - protected FilteredController(@NotNull LinearGraphController delegateLinearGraphController, - @NotNull PermanentGraphInfo permanentGraphInfo, - @NotNull Set matchedIds) { - this(delegateLinearGraphController, permanentGraphInfo, matchedIds, null); - } - - protected FilteredController(@NotNull LinearGraphController delegateLinearGraphController, - @NotNull PermanentGraphInfo permanentGraphInfo, - @NotNull Set matchedIds, - @Nullable Set visibleHeadsIds) { - super(delegateLinearGraphController, permanentGraphInfo); - - UnsignedBitSet initVisibility = new UnsignedBitSet(); + init { + val initVisibility = UnsignedBitSet() if (visibleHeadsIds != null) { - new DfsWalk(visibleHeadsIds, myPermanentGraphInfo.getLinearGraph()).walk(true, node -> { - if (matchedIds.contains(node)) initVisibility.set(node, true); - return true; - }); + DfsWalk(visibleHeadsIds, permanentGraphInfo.linearGraph).walk(true) { node -> + if (matchedIds.contains(node)) initVisibility[node] = true + true + } } else { - for (Integer matchedId : matchedIds) initVisibility.set(matchedId, true); + for (matchedId in matchedIds) initVisibility[matchedId] = true } - myCollapsedGraph = CollapsedGraph.newInstance(delegateLinearGraphController.getCompiledGraph(), initVisibility); - DottedFilterEdgesGenerator.update(myCollapsedGraph, 0, myCollapsedGraph.getDelegatedGraph().nodesCount() - 1); + collapsedGraph = CollapsedGraph.newInstance(delegateLinearGraphController.compiledGraph, initVisibility) + update(collapsedGraph, 0, collapsedGraph.delegatedGraph.nodesCount() - 1) } - @NotNull - @Override - public LinearGraphAnswer performLinearGraphAction(@NotNull LinearGraphAction action) { + override fun performLinearGraphAction(action: LinearGraphController.LinearGraphAction): LinearGraphController.LinearGraphAnswer { // filter prohibits any actions on delegate graph for now - LinearGraphAnswer answer = performAction(action); - if (answer != null) return answer; - return LinearGraphUtils.DEFAULT_GRAPH_ANSWER; + return performAction(action) ?: LinearGraphUtils.DEFAULT_GRAPH_ANSWER } - @Nullable - @Override - protected GraphElement convertToDelegate(@NotNull GraphElement graphElement) { + override fun convertToDelegate(graphElement: GraphElement): GraphElement? { // filter prohibits any actions on delegate graph for now - return null; + return null } - @NotNull - @Override - protected LinearGraphAnswer delegateGraphChanged(@NotNull LinearGraphAnswer delegateAnswer) { - if (delegateAnswer == LinearGraphUtils.DEFAULT_GRAPH_ANSWER) return delegateAnswer; - throw new UnsupportedOperationException(); // todo fix later + override fun delegateGraphChanged(delegateAnswer: LinearGraphController.LinearGraphAnswer): LinearGraphController.LinearGraphAnswer { + if (delegateAnswer === LinearGraphUtils.DEFAULT_GRAPH_ANSWER) return delegateAnswer + throw UnsupportedOperationException() // todo fix later } - @Nullable - @Override - protected LinearGraphAnswer performAction(@NotNull LinearGraphAction action) { - return null; - } + override fun performAction(action: LinearGraphController.LinearGraphAction) = null - @NotNull - @Override - public LinearGraph getCompiledGraph() { - return myCollapsedGraph.getCompiledGraph(); - } - - @NotNull - public CollapsedGraph getCollapsedGraph() { - return myCollapsedGraph; - } + override fun getCompiledGraph() = collapsedGraph.compiledGraph }