mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log-graph] convert controller classes to kotlin
GitOrigin-RevId: 4d2a16b55201bf2076748de488fc5361b12b4c27
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b7fca40c44
commit
05043bf215
+23
-58
@@ -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<Int>?) : 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<Integer> 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)
|
||||
}
|
||||
}
|
||||
|
||||
+27
-63
@@ -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<Int>?): GraphChanges<Int>? {
|
||||
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<Integer> performAction(@NotNull Function<? super CascadeController, ? extends GraphChanges<Integer>> action) {
|
||||
GraphChanges<Integer> graphChanges = action.apply(this);
|
||||
if (graphChanges != null) return graphChanges;
|
||||
|
||||
if (myDelegateController instanceof CascadeController) {
|
||||
GraphChanges<Integer> 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?
|
||||
}
|
||||
|
||||
+33
-79
@@ -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<Int>,
|
||||
visibleHeadsIds: Set<Int>? = 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<Integer> matchedIds) {
|
||||
this(delegateLinearGraphController, permanentGraphInfo, matchedIds, null);
|
||||
}
|
||||
|
||||
protected FilteredController(@NotNull LinearGraphController delegateLinearGraphController,
|
||||
@NotNull PermanentGraphInfo permanentGraphInfo,
|
||||
@NotNull Set<Integer> matchedIds,
|
||||
@Nullable Set<Integer> 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user