diff --git a/src/main/java/org/cqfn/astranaut/core/Info.java b/src/main/java/org/cqfn/astranaut/core/Info.java index 0db0d0f..57bba39 100644 --- a/src/main/java/org/cqfn/astranaut/core/Info.java +++ b/src/main/java/org/cqfn/astranaut/core/Info.java @@ -25,7 +25,6 @@ /** * This class provides static information about the library, such as the version. - * * @since 1.0.6 */ public final class Info { diff --git a/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java b/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java index d74e921..76127cb 100644 --- a/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java +++ b/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java @@ -36,7 +36,6 @@ import org.cqfn.astranaut.core.base.Node; import org.cqfn.astranaut.core.base.Pattern; import org.cqfn.astranaut.core.base.PatternNode; -import org.cqfn.astranaut.core.base.PrototypeBasedNode; import org.cqfn.astranaut.core.base.Replace; import org.cqfn.astranaut.core.base.Tree; @@ -105,7 +104,7 @@ Set match(final Pattern pattern) { @SuppressWarnings("PMD.UnusedFormalParameter") private boolean checkNode(final Node node, final Node parent, final Node pattern) { final Node sample; - final Action action = Matcher.nodeToAction(pattern); + final Action action = Action.toAction(pattern); if (action instanceof Replace || action instanceof Delete) { sample = action.getBefore(); } else { @@ -142,7 +141,7 @@ private boolean checkChildren(final Node node, final Node sample) { Node current = null; while (result && offset < right && iterator.hasNext()) { final Node child = iterator.next(); - final Action action = Matcher.nodeToAction(child); + final Action action = Action.toAction(child); if (action instanceof Insert) { this.actions.insertNodeAfter(action.getAfter(), node, current); } else if (index + offset >= left) { @@ -160,22 +159,4 @@ private boolean checkChildren(final Node node, final Node sample) { } return result; } - - /** - * Converts a node reference to an action reference if the node is an action - * or the node prototype is an action. - * @param node Node - * @return Action or {@code null} if the node is not an action - */ - private static Action nodeToAction(final Node node) { - final Action action; - if (node instanceof Action) { - action = (Action) node; - } else if (node instanceof PrototypeBasedNode) { - action = Matcher.nodeToAction(((PrototypeBasedNode) node).getPrototype()); - } else { - action = null; - } - return action; - } } diff --git a/src/main/java/org/cqfn/astranaut/core/base/Action.java b/src/main/java/org/cqfn/astranaut/core/base/Action.java index 3a92706..8e7a365 100644 --- a/src/main/java/org/cqfn/astranaut/core/base/Action.java +++ b/src/main/java/org/cqfn/astranaut/core/base/Action.java @@ -25,9 +25,26 @@ /** * A node that represents an action that can be performed on another node. - * This type of nodes is necessary for the construction of difference trees. - * + * This type of nodes is necessary for the construction of difference trees. * @since 1.1.0 */ +@SuppressWarnings("PMD.ProhibitPublicStaticMethods") public interface Action extends DiffTreeItem, PatternItem { + /** + * Converts a node reference to an action reference if the node is an action + * or the node prototype is an action. + * @param node Node + * @return Action or {@code null} if the node is not an action + */ + static Action toAction(final Node node) { + final Action action; + if (node instanceof Action) { + action = (Action) node; + } else if (node instanceof PrototypeBasedNode) { + action = Action.toAction(((PrototypeBasedNode) node).getPrototype()); + } else { + action = null; + } + return action; + } }