Add for getEnclosing* methods
@@ -46,6 +46,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
/**
@@ -2127,6 +2128,7 @@ public final class NodeUtil {
/**
* Gets the closest ancestor to the given node of the provided type.
*/
+ @CheckReturnValue
public static Node getEnclosingType(Node n, final Token type) {
return getEnclosingNode(
n,
@@ -2141,6 +2143,7 @@ public final class NodeUtil {
/**
* Finds the class member function containing the given node.
*/
+ @CheckReturnValue
static Node getEnclosingClassMemberFunction(Node n) {
return getEnclosingType(n, Token.MEMBER_FUNCTION_DEF);
}
@@ -2148,6 +2151,7 @@ public final class NodeUtil {
/**
* Finds the class containing the given node.
*/
+ @CheckReturnValue
public static Node getEnclosingClass(Node n) {
return getEnclosingType(n, Token.CLASS);
}
@@ -2155,6 +2159,7 @@ public final class NodeUtil {
/**
* Finds the function containing the given node.
*/
+ @CheckReturnValue
public static Node getEnclosingFunction(Node n) {
return getEnclosingType(n, Token.FUNCTION);
}
@@ -2162,6 +2167,7 @@ public final class NodeUtil {
/**
* Finds the script containing the given node.
*/
+ @CheckReturnValue
public static Node getEnclosingScript(Node n) {
return getEnclosingType(n, Token.SCRIPT);
}
@@ -2169,14 +2175,17 @@ public final class NodeUtil {
/**
* Finds the block containing the given node.
*/
+ @CheckReturnValue
public static Node getEnclosingBlock(Node n) {
return getEnclosingType(n, Token.BLOCK);
}
+ @CheckReturnValue
public static Node getEnclosingBlockScopeRoot(Node n) {
return getEnclosingNode(n, createsBlockScope);
}
+ @CheckReturnValue
public static Node getEnclosingScopeRoot(Node n) {
return getEnclosingNode(n, createsScope);
}
@@ -2185,10 +2194,12 @@ public final class NodeUtil {
return getEnclosingFunction(n) != null;
}
+ @CheckReturnValue
public static Node getEnclosingStatement(Node n) {
return getEnclosingNode(n, isStatement);
}
+ @CheckReturnValue
public static Node getEnclosingNode(Node n, Predicate<Node> pred) {
Node curr = n;
while (curr != null && !pred.apply(curr)) {
@@ -4723,6 +4734,7 @@ public final class NodeUtil {
/**
* @return the change scope root
*/
+ @CheckReturnValue
static Node getEnclosingChangeScopeRoot(Node n) {
while (n != null && !isChangeScopeRoot(n)) {
n = n.getParent();
