From 5c2b8e0afe27a90892a1d64ee5526fc63308baf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 27 Jan 2019 16:59:22 +0100 Subject: [PATCH] Fix merge --- .../pmd/internal/util/IteratorUtil.java | 43 +++++++++++++++++++ .../fxdesigner/NodeInfoPanelController.java | 3 +- .../fxdesigner/SourceEditorController.java | 2 - .../fxdesigner/util/DesignerIteratorUtil.java | 34 +-------------- .../fxdesigner/util/controls/ASTTreeView.java | 6 +-- .../util/controls/NodeParentageCrumbBar.java | 7 +-- 6 files changed, 53 insertions(+), 42 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/IteratorUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/IteratorUtil.java index b7ae345175..3a8fabf260 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/IteratorUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/IteratorUtil.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.ListIterator; /** @@ -46,4 +47,46 @@ public final class IteratorUtil { }; } + + /** Counts the items in this iterator, exhausting it. */ + public static int count(Iterator it) { + int count = 0; + while (it.hasNext()) { + it.next(); + count++; + } + return count; + } + + + public static Iterable asReversed(final List lst) { + + return new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + + ListIterator li = lst.listIterator(lst.size()); + + + @Override + public boolean hasNext() { + return li.hasPrevious(); + } + + + @Override + public T next() { + return li.previous(); + } + + + @Override + public void remove() { + li.remove(); + } + }; + } + }; + } } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/NodeInfoPanelController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/NodeInfoPanelController.java index 2cf1d62a31..56fc4c5e41 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/NodeInfoPanelController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/NodeInfoPanelController.java @@ -18,6 +18,7 @@ import java.util.stream.Collectors; import org.reactfx.EventStreams; import org.reactfx.value.Var; +import net.sourceforge.pmd.internal.util.IteratorUtil; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.xpath.Attribute; import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider; @@ -209,7 +210,7 @@ public class NodeInfoPanelController extends AbstractController { // Otherwise, when you select a node in the scope tree, since focus of the app is shifted to that // node, the scope hierarchy is reset and you lose the selection - even though obviously the node // you selected is in its own scope hierarchy so it looks buggy. - int maxDepth = DesignerIteratorUtil.count(DesignerIteratorUtil.parentIterator(previousSelection, true)); + int maxDepth = IteratorUtil.count(DesignerIteratorUtil.parentIterator(previousSelection, true)); rootScope.tryFindNode(previousSelection.getValue(), maxDepth) .ifPresent(scopeHierarchyTreeView.getSelectionModel()::select); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java index 37af364184..395b509168 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java @@ -71,8 +71,6 @@ public class SourceEditorController extends AbstractController { @FXML private ASTTreeView astTreeView; @FXML - private ToolbarTitledPane astViewTitledPane; - @FXML private HighlightLayerCodeArea codeEditorArea; @FXML private NodeParentageCrumbBar focusNodeParentageCrumbBar; diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/DesignerIteratorUtil.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/DesignerIteratorUtil.java index 74a7d6f4e8..84126c88d6 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/DesignerIteratorUtil.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/DesignerIteratorUtil.java @@ -7,8 +7,6 @@ package net.sourceforge.pmd.util.fxdesigner.util; import static net.sourceforge.pmd.internal.util.IteratorUtil.toIterable; import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; import java.util.function.Function; import java.util.function.Predicate; @@ -25,42 +23,12 @@ public final class DesignerIteratorUtil { // TODO move that into PMD core with Java 8 + private DesignerIteratorUtil() { } - /** Counts the items in this iterator, exhausting it. */ - public static int count(Iterator it) { - int count = 0; - while (it.hasNext()) { - it.next(); - count++; - } - return count; - } - - - public static Iterable asReversed(List lst) { - - return () -> new Iterator() { - - ListIterator li = lst.listIterator(lst.size()); - - - @Override - public boolean hasNext() { - return li.hasPrevious(); - } - - - @Override - public T next() { - return li.previous(); - } - }; - } - public static boolean isParent(Node parent, Node child) { return any(parentIterator(child, false), p -> parent == p); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/ASTTreeView.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/ASTTreeView.java index 97bfd7ee72..02fbd58ddd 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/ASTTreeView.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/ASTTreeView.java @@ -4,8 +4,8 @@ package net.sourceforge.pmd.util.fxdesigner.util.controls; -import static net.sourceforge.pmd.util.fxdesigner.util.IteratorUtil.parentIterator; -import static net.sourceforge.pmd.util.fxdesigner.util.IteratorUtil.toIterable; +import static net.sourceforge.pmd.internal.util.IteratorUtil.toIterable; +import static net.sourceforge.pmd.util.fxdesigner.util.DesignerIteratorUtil.parentIterator; import java.util.Objects; import java.util.Optional; @@ -111,7 +111,7 @@ public class ASTTreeView extends TreeView { * Returns true if the item at the given index * is visible in the TreeView. */ - public boolean isIndexVisible(int index) { + private boolean isIndexVisible(int index) { return myWrapper.isIndexVisible(index); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/NodeParentageCrumbBar.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/NodeParentageCrumbBar.java index af794998b3..fe2db8a007 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/NodeParentageCrumbBar.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/NodeParentageCrumbBar.java @@ -4,9 +4,10 @@ package net.sourceforge.pmd.util.fxdesigner.util.controls; -import static net.sourceforge.pmd.util.fxdesigner.util.IteratorUtil.asReversed; -import static net.sourceforge.pmd.util.fxdesigner.util.IteratorUtil.count; -import static net.sourceforge.pmd.util.fxdesigner.util.IteratorUtil.parentIterator; + +import static net.sourceforge.pmd.internal.util.IteratorUtil.asReversed; +import static net.sourceforge.pmd.internal.util.IteratorUtil.count; +import static net.sourceforge.pmd.util.fxdesigner.util.DesignerIteratorUtil.parentIterator; import java.util.function.Consumer; import java.util.function.Function;