Tell if this expression or it's subexpressions can traverse outside
the current subtree.

@return true if traversal outside the context node's subtree can occur.
767177
public boolean canTraverseOutsideSubtree()
  {

    if (null != m_parts)
    {
      int n = m_parts.size();

      for (int i = 0; i < n; i++)
      {
        AVTPart part = (AVTPart) m_parts.elementAt(i);

        if (part.canTraverseOutsideSubtree())
          return true;
      }
    }

    return false;
  }
618426
@SuppressWarnings("TreeToString") // Indented to ignore whitespace, comments, and source position.
  private static boolean isSameExpression(ExpressionTree leftTree, ExpressionTree rightTree) {
    // The left tree and right tree must have the same symbol resolution.
    // This ensures the symbol kind on field, parameter or local var.
    if (ASTHelpers.getSymbol(leftTree) != ASTHelpers.getSymbol(rightTree)) {
      return false;
    }

    String leftTreeTextRepr = stripPrefixIfPresent(leftTree.toString(), "this.");
    String rightTreeTextRepr = stripPrefixIfPresent(rightTree.toString(), "this.");
    return leftTreeTextRepr.contentEquals(rightTreeTextRepr);
  }
615004
public boolean is(ComparisonExpression expr) {
		try {
			if (expr != null) {
				return expr.evaluate(node);
			}
		} catch (MissingNodeException e) {
			return false;
		}

		return false;
	}
102782
function isCallbackExpression(node, parentNode) {

            // ensure the parent node exists and is an expression
            if (!parentNode || parentNode.type !== "ExpressionStatement") {
                return false;
            }

            // cb()
            if (parentNode.expression === node) {
                return true;
            }

            // special case for cb && cb() and similar
            if (parentNode.expression.type === "BinaryExpression" || parentNode.expression.type === "LogicalExpression") {
                if (parentNode.expression.right === node) {
                    return true;
                }
            }

            return false;
        }
135888
protected Boolean _hasSideEffects(XReturnExpression expression, ISideEffectContext context) {
		return hasSideEffects(expression.getExpression(), context);
	}
628016
@Nullable
  private static Node findExpressionRoot(Node subExpression) {
    Node child = subExpression;
    for (Node current : child.getAncestors()) {
      Node parent = current.getParent();
      switch (current.getToken()) {
          // Supported expression roots:
          // SWITCH and IF can have multiple children, but the CASE, DEFAULT,
          // or BLOCK will be encountered first for any of the children other
          // than the condition.
        case EXPR_RESULT:
        case IF:
        case SWITCH:
        case RETURN:
        case THROW:
          Preconditions.checkState(child.isFirstChildOf(current));
          return current;

        case VAR:
          // Normalization will remove LABELs from VARs.
        case LET:
        case CONST:
          if (NodeUtil.isAnyFor(parent)) {
            break; // Name declarations may not be roots if they're for-loop initializers.
          }
          return current;

          // Any of these indicate an unsupported expression:
        case FOR:
          if (child.isFirstChildOf(current)) {
            // Only the initializer of a for-loop could possibly be decomposed since the other
            // statements need to execute each iteration.
            return current;
          }
          // fall through
        case FOR_IN:
        case FOR_OF:
        case FOR_AWAIT_OF:
        case DO:
        case WHILE:
        case SCRIPT:
        case BLOCK:
        case LABEL:
        case CASE:
        case DEFAULT_CASE:
        case PARAM_LIST:
          return null;

        default:
          break;
      }
      child = current;
    }

    throw new IllegalStateException("Unexpected AST structure.");
  }
499900
public boolean isNullOnSomePath() {
        int baseKind = getBaseKind();
        if (NCP_EXTRA_BRANCH) {
            // Note: NCP_EXTRA_BRANCH is an experimental feature
            // to see how many false warnings we get when we allow
            // two branches between an explicit null and a
            // a dereference.
            return baseKind == NSP || baseKind == NCP2;
        } else {
            return baseKind == NSP;
        }
    }
842792
private static boolean expressionsEqual(ExpressionTree expr1, ExpressionTree expr2) {
    if (!expr1.getKind().equals(expr2.getKind())) {
      return false;
    }

    if (!expr1.getKind().equals(Kind.ARRAY_ACCESS)
        && !expr1.getKind().equals(Kind.IDENTIFIER)
        && !(expr1 instanceof LiteralTree)) {
      return false;
    }

    if (expr1.getKind() == Kind.ARRAY_ACCESS) {
      ArrayAccessTree arrayAccessTree1 = (ArrayAccessTree) expr1;
      ArrayAccessTree arrayAccessTree2 = (ArrayAccessTree) expr2;
      return expressionsEqual(arrayAccessTree1.getExpression(), arrayAccessTree2.getExpression())
          && expressionsEqual(arrayAccessTree1.getIndex(), arrayAccessTree2.getIndex());
    }

    if (expr1 instanceof LiteralTree) {
      LiteralTree literalTree1 = (LiteralTree) expr1;
      LiteralTree literalTree2 = (LiteralTree) expr2;
      return literalTree1.getValue().equals(literalTree2.getValue());
    }

    return Objects.equal(ASTHelpers.getSymbol(expr1), ASTHelpers.getSymbol(expr2));
  }
891185
private static void checkNesting(final BooleanExpression expression,
			final List<BooleanExpression> visitedExpressions) {
		if (visitedExpressions.contains(expression)) {
			// Unfortunately, we can't give much more information - even calling toString() will overflow the stack.
			throw new SyntaxException("An expression can not contain itself.");
		}

		visitedExpressions.add(expression);

		if (expression instanceof GroupExpression) {
			GroupExpression group = (GroupExpression) expression;
			for (BooleanExpression operand : group.getOperands()) {
				checkNesting(operand, visitedExpressions);
			}
		}
	}
277676
public boolean isExternalizable() {
        try {
            return env.types.isSubtype(type, env.externalizableSym.type);
        } catch (CompletionFailure ex) {
            // quietly ignore completion failures
            return false;
        }
    }
1169037
protected Boolean _hasSideEffects(XForLoopExpression expression, ISideEffectContext context) {
		context.open();
		if (hasSideEffects(expression.getForExpression(), context)) {
			return true;
		}
		context.close();
		return hasSideEffects(expression.getEachExpression(), context.branch());
	}
1141091
protected boolean _hasSideEffects(XAbstractWhileExpression expression, ISideEffectContext context) {
		context.open();
		if (hasSideEffects(expression.getPredicate(), context)) {
			return true;
		}
		if (hasSideEffects(expression.getBody(), context.branch())) {
			return true;
		}
		context.close();
		return false;
	}
940453
private boolean hasNextLazy() {
        try {
            while (true) {
                switch (this.queryState) {
                    case REGULAR:
                        if (this.elements != null) {
                            return true;
                        } else {
                            if (this.queryResult != null) {
                                iterateRegularQueries();
                                this.first = false;
                            }
                            if (this.elements == null) {
                                closePreparedStatement();
                                //try the next distinctQueryStack
                                if (this.distinctQueriesIterator.hasNext()) {
                                    this.currentDistinctQueryStack = this.distinctQueriesIterator.next();
                                    this.subQueryStacks = SchemaTableTree.splitIntoSubStacks(this.currentDistinctQueryStack);
                                    this.currentRootSchemaTableTree.resetColumnAliasMaps();
                                    //if there are duplicates in the stack we can not execute drop steps.
                                    //execute the query as per normal and the proper DropStep will do the rest.
                                    if (this.currentDistinctQueryStack.getLast().isDrop() && !this.currentRootSchemaTableTree.duplicatesInStack(currentDistinctQueryStack)) {
                                        executeDropQuery();
                                    } else {
                                        executeRegularQuery();
                                    }
                                    this.first = true;
                                } else {
                                    //try the next rootSchemaTableTree
                                    if (this.rootSchemaTableTreeIterator.hasNext()) {
                                        this.currentRootSchemaTableTree = this.rootSchemaTableTreeIterator.next();
                                        this.distinctQueriesIterator = this.currentRootSchemaTableTree.constructDistinctQueries().iterator();
                                    } else {
                                        if (this.currentRootSchemaTableTree != null) {
                                            this.currentRootSchemaTableTree.resetColumnAliasMaps();
                                        }
                                        this.queryState = QUERY.OPTIONAL;
                                        this.rootSchemaTableTreeIterator = this.rootSchemaTableTrees.iterator();
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    case OPTIONAL:
                        if (this.elements != null) {
                            return true;
                        } else {
                            if (this.queryResult != null) {
                                iterateOptionalQueries();
                                this.first = false;
                            }
                            if (this.elements == null) {
                                closePreparedStatement();
                                //try the next distinctQueryStack
                                if (this.optionalLeftJoinResultsIterator.hasNext()) {
                                    this.optionalCurrentLeftJoinResult = this.optionalLeftJoinResultsIterator.next();
                                    this.subQueryStacks = SchemaTableTree.splitIntoSubStacks(this.optionalCurrentLeftJoinResult.getLeft());
                                    this.currentRootSchemaTableTree.resetColumnAliasMaps();
                                    executeOptionalQuery();
                                    this.first = true;
                                } else {
                                    //try the next rootSchemaTableTree
                                    if (this.rootSchemaTableTreeIterator.hasNext()) {
                                        this.currentRootSchemaTableTree = this.rootSchemaTableTreeIterator.next();
                                        List<Pair<LinkedList<SchemaTableTree>, Set<SchemaTableTree>>> leftJoinResult = new ArrayList<>();
                                        SchemaTableTree.constructDistinctOptionalQueries(this.currentRootSchemaTableTree, leftJoinResult);
                                        this.optionalLeftJoinResultsIterator = leftJoinResult.iterator();
                                    } else {
                                        if (this.currentRootSchemaTableTree != null) {
                                            this.currentRootSchemaTableTree.resetColumnAliasMaps();
                                        }
                                        this.queryState = QUERY.EMIT;
                                        this.rootSchemaTableTreeIterator = this.rootSchemaTableTrees.iterator();
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    case EMIT:
                        if (this.elements != null) {
                            return true;
                        } else {
                            if (this.queryResult != null) {
                                iterateEmitQueries();
                                this.first = false;
                            }
                            if (this.elements == null) {
                                closePreparedStatement();
                                //try the next distinctQueryStack
                                if (this.emitLeftJoinResultsIterator.hasNext()) {
                                    this.emitCurrentLeftJoinResult = this.emitLeftJoinResultsIterator.next();
                                    this.subQueryStacks = SchemaTableTree.splitIntoSubStacks(this.emitCurrentLeftJoinResult);
                                    this.currentRootSchemaTableTree.resetColumnAliasMaps();
                                    executeEmitQuery();
                                    this.first = true;
                                } else {
                                    //try the next rootSchemaTableTree
                                    if (this.rootSchemaTableTreeIterator.hasNext()) {
                                        this.currentRootSchemaTableTree = this.rootSchemaTableTreeIterator.next();
                                        List<LinkedList<SchemaTableTree>> leftJoinResult = new ArrayList<>();
                                        SchemaTableTree.constructDistinctEmitBeforeQueries(this.currentRootSchemaTableTree, leftJoinResult);
                                        this.emitLeftJoinResultsIterator = leftJoinResult.iterator();
                                        if (currentRootSchemaTableTree.isFakeEmit()) {
                                            List<Emit<SqlgElement>> fake = new ArrayList<>();
                                            fake.add(new Emit<>());
                                            this.elements = fake;
                                            this.currentRootSchemaTableTree.setFakeEmit(false);
                                        }
                                    } else {
                                        if (this.currentRootSchemaTableTree != null) {
                                            this.currentRootSchemaTableTree.resetColumnAliasMaps();
                                        }
                                        return false;
                                    }
                                }
                            }
                        }
                        break;
                }
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
622224
private boolean validBooleanExpression(Node expr) {
    if (isBooleanOperation(expr)) {
      return validBooleanOperation(expr);
    }

    if (!isOperation(expr)) {
      warnInvalidExpression("boolean", expr);
      return false;
    }
    if (!isValidPredicate(getCallName(expr))) {
      warnInvalid("boolean predicate", expr);
      return false;
    }
    Keywords keyword = nameToKeyword(getCallName(expr));
    if (!checkParameterCount(expr, keyword)) {
      return false;
    }
    switch (keyword.kind) {
      case TYPE_PREDICATE:
        return validTypePredicate(expr, getCallParamCount(expr));
      case STRING_PREDICATE:
        return validStringPredicate(expr, getCallParamCount(expr));
      case TYPEVAR_PREDICATE:
        return validTypevarPredicate(expr, getCallParamCount(expr));
      default:
        throw new IllegalStateException("Invalid boolean expression");
    }
  }
1249348
protected Boolean _hasSideEffects(XIfExpression expression, ISideEffectContext context) {
		if (hasSideEffects(expression.getIf(), context)) {
			return true;
		}
		final Map<String, List<XExpression>> buffer1 = context.createVariableAssignmentBufferForBranch();
		if (hasSideEffects(expression.getThen(), context.branch(buffer1))) {
			return true;
		}
		final Map<String, List<XExpression>> buffer2 = context.createVariableAssignmentBufferForBranch();
		if (hasSideEffects(expression.getElse(), context.branch(buffer2))) {
			return true;
		}
		context.mergeBranchVariableAssignments(Arrays.asList(buffer1, buffer2));
		return false;
	}
93002
public static boolean isExtractable(GroovyExpression expr) {

        HasForbiddenType hasForbiddenTypePredicate = new HasForbiddenType(FACTORY);

        //alias could conflict with alias in parent traversal
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.SIDE_EFFECT);

        //inlining out(), in() steps will change the result of calls after the and/or()
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.FLAT_MAP_TO_ELEMENTS);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.FLAT_MAP_TO_VALUES);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.BARRIER);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.MAP_TO_ELEMENT);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.MAP_TO_VALUE);

        //caller expects to be able to continue the traversal.  We can't end it
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.END);


        //we can't inline child traversals
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.SOURCE);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.START);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.SIDE_EFFECT);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.NONE);
        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.BRANCH);

        ExpressionFinder forbiddenExpressionFinder = new ExpressionFinder(hasForbiddenTypePredicate);
        GremlinQueryOptimizer.visitCallHierarchy(expr, forbiddenExpressionFinder);
        return ! forbiddenExpressionFinder.isExpressionFound();
    }
24697
public boolean isIntentionalEarlyExit(/* @Nullable */ XExpression expression) {
		if (expression == null) {
			return true;
		}
		if (expression instanceof XBlockExpression) {
			XBlockExpression block = (XBlockExpression) expression;
			List<XExpression> children = block.getExpressions();
			for(XExpression child: children) {
				if (isIntentionalEarlyExit(child)) {
					return true;
				}
			}
		} else if (expression instanceof XIfExpression) {
			return isIntentionalEarlyExit(((XIfExpression) expression).getThen()) 
					|| isIntentionalEarlyExit(((XIfExpression) expression).getElse());
		} else if (expression instanceof XSwitchExpression) {
			XSwitchExpression switchExpression = (XSwitchExpression) expression;
			for(XCasePart caseExpression: switchExpression.getCases()) {
				if (isIntentionalEarlyExit(caseExpression.getThen())) {
					return true;
				}
			}
			if (isIntentionalEarlyExit(switchExpression.getDefault())) {
				return true;
			}
		} else if (expression instanceof XTryCatchFinallyExpression) {
			XTryCatchFinallyExpression tryCatchFinally = (XTryCatchFinallyExpression) expression;
			if (isIntentionalEarlyExit(tryCatchFinally.getExpression())) {
				for(XCatchClause catchClause: tryCatchFinally.getCatchClauses()) {
					if (!isIntentionalEarlyExit(catchClause.getExpression()))
						return false;
				}
				return true;
			}
			return false;
		} else if (expression instanceof XAbstractWhileExpression) {
			return isIntentionalEarlyExit(((XAbstractWhileExpression) expression).getBody());
		} else if (expression instanceof XForLoopExpression) {
			return isIntentionalEarlyExit(((XForLoopExpression) expression).getEachExpression());
		} else if (expression instanceof XBasicForLoopExpression) {
			return isIntentionalEarlyExit(((XBasicForLoopExpression) expression).getEachExpression());
		} else if (expression instanceof XSynchronizedExpression) {
			return isIntentionalEarlyExit(((XSynchronizedExpression) expression).getExpression());
		}
		return expression instanceof XReturnExpression || expression instanceof XThrowExpression;
	}