Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thorough polishing #29

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/org/cqfn/astranaut/core/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

/**
* This class provides static information about the library, such as the version.
*
* @since 1.0.6
*/
public final class Info {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -105,7 +104,7 @@ Set<Node> 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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
21 changes: 19 additions & 2 deletions src/main/java/org/cqfn/astranaut/core/base/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading