Java Code Examples for com.google.javascript.jscomp.ExpressionDecomposer.DecompositionType#DECOMPOSABLE

The following examples show how to use com.google.javascript.jscomp.ExpressionDecomposer.DecompositionType#DECOMPOSABLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 1_FunctionInjector.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determine which, if any, of the supported types the call site is.
 */
private CallSiteType classifyCallSite(Node callNode) {
  Node parent = callNode.getParent();
  Node grandParent = parent.getParent();

  // Verify the call site:
  if (NodeUtil.isExprCall(parent)) {
    // This is a simple call?  Example: "foo();".
    return CallSiteType.SIMPLE_CALL;
  } else if (NodeUtil.isExprAssign(grandParent)
      && !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
      && parent.getFirstChild().isName()
      && !NodeUtil.isConstantName(parent.getFirstChild())) {
    // This is a simple assignment.  Example: "x = foo();"
    return CallSiteType.SIMPLE_ASSIGNMENT;
  } else if (parent.isName()
      && !NodeUtil.isConstantName(parent)
      && grandParent.isVar()
      && grandParent.hasOneChild()) {
    // This is a var declaration.  Example: "var x = foo();"
    // TODO(johnlenz): Should we be checking for constants on the
    // left-hand-side of the assignments and handling them as EXPRESSION?
    return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
  } else {
    Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
    if (expressionRoot != null) {
      ExpressionDecomposer decomposer = new ExpressionDecomposer(
          compiler, safeNameIdSupplier, knownConstants);
      DecompositionType type = decomposer.canExposeExpression(
          callNode);
      if (type == DecompositionType.MOVABLE) {
        return CallSiteType.EXPRESSION;
      } else if (type == DecompositionType.DECOMPOSABLE) {
        return CallSiteType.DECOMPOSABLE_EXPRESSION;
      } else {
        Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
      }
    }
  }

  return CallSiteType.UNSUPPORTED;
}
 
Example 2
Source File: 1_FunctionInjector.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determine which, if any, of the supported types the call site is.
 */
private CallSiteType classifyCallSite(Node callNode) {
  Node parent = callNode.getParent();
  Node grandParent = parent.getParent();

  // Verify the call site:
  if (NodeUtil.isExprCall(parent)) {
    // This is a simple call?  Example: "foo();".
    return CallSiteType.SIMPLE_CALL;
  } else if (NodeUtil.isExprAssign(grandParent)
      && !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
      && parent.getFirstChild().isName()
      && !NodeUtil.isConstantName(parent.getFirstChild())) {
    // This is a simple assignment.  Example: "x = foo();"
    return CallSiteType.SIMPLE_ASSIGNMENT;
  } else if (parent.isName()
      && !NodeUtil.isConstantName(parent)
      && grandParent.isVar()
      && grandParent.hasOneChild()) {
    // This is a var declaration.  Example: "var x = foo();"
    // TODO(johnlenz): Should we be checking for constants on the
    // left-hand-side of the assignments and handling them as EXPRESSION?
    return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
  } else {
    Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
    if (expressionRoot != null) {
      ExpressionDecomposer decomposer = new ExpressionDecomposer(
          compiler, safeNameIdSupplier, knownConstants);
      DecompositionType type = decomposer.canExposeExpression(
          callNode);
      if (type == DecompositionType.MOVABLE) {
        return CallSiteType.EXPRESSION;
      } else if (type == DecompositionType.DECOMPOSABLE) {
        return CallSiteType.DECOMPOSABLE_EXPRESSION;
      } else {
        Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
      }
    }
  }

  return CallSiteType.UNSUPPORTED;
}
 
Example 3
Source File: Closure_116_FunctionInjector_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Determine which, if any, of the supported types the call site is.
 */
private CallSiteType classifyCallSite(Node callNode) {
  Node parent = callNode.getParent();
  Node grandParent = parent.getParent();

  // Verify the call site:
  if (NodeUtil.isExprCall(parent)) {
    // This is a simple call?  Example: "foo();".
    return CallSiteType.SIMPLE_CALL;
  } else if (NodeUtil.isExprAssign(grandParent)
      && !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
      && parent.getFirstChild().isName()
      && !NodeUtil.isConstantName(parent.getFirstChild())) {
    // This is a simple assignment.  Example: "x = foo();"
    return CallSiteType.SIMPLE_ASSIGNMENT;
  } else if (parent.isName()
      && !NodeUtil.isConstantName(parent)
      && grandParent.isVar()
      && grandParent.hasOneChild()) {
    // This is a var declaration.  Example: "var x = foo();"
    // TODO(johnlenz): Should we be checking for constants on the
    // left-hand-side of the assignments and handling them as EXPRESSION?
    return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
  } else {
    Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
    if (expressionRoot != null) {
      ExpressionDecomposer decomposer = new ExpressionDecomposer(
          compiler, safeNameIdSupplier, knownConstants);
      DecompositionType type = decomposer.canExposeExpression(
          callNode);
      if (type == DecompositionType.MOVABLE) {
        return CallSiteType.EXPRESSION;
      } else if (type == DecompositionType.DECOMPOSABLE) {
        return CallSiteType.DECOMPOSABLE_EXPRESSION;
      } else {
        Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
      }
    }
  }

  return CallSiteType.UNSUPPORTED;
}
 
Example 4
Source File: Closure_116_FunctionInjector_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Determine which, if any, of the supported types the call site is.
 */
private CallSiteType classifyCallSite(Node callNode) {
  Node parent = callNode.getParent();
  Node grandParent = parent.getParent();

  // Verify the call site:
  if (NodeUtil.isExprCall(parent)) {
    // This is a simple call?  Example: "foo();".
    return CallSiteType.SIMPLE_CALL;
  } else if (NodeUtil.isExprAssign(grandParent)
      && !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
      && parent.getFirstChild().isName()
      && !NodeUtil.isConstantName(parent.getFirstChild())) {
    // This is a simple assignment.  Example: "x = foo();"
    return CallSiteType.SIMPLE_ASSIGNMENT;
  } else if (parent.isName()
      && !NodeUtil.isConstantName(parent)
      && grandParent.isVar()
      && grandParent.hasOneChild()) {
    // This is a var declaration.  Example: "var x = foo();"
    // TODO(johnlenz): Should we be checking for constants on the
    // left-hand-side of the assignments and handling them as EXPRESSION?
    return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
  } else {
    Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
    if (expressionRoot != null) {
      ExpressionDecomposer decomposer = new ExpressionDecomposer(
          compiler, safeNameIdSupplier, knownConstants);
      DecompositionType type = decomposer.canExposeExpression(
          callNode);
      if (type == DecompositionType.MOVABLE) {
        return CallSiteType.EXPRESSION;
      } else if (type == DecompositionType.DECOMPOSABLE) {
        return CallSiteType.DECOMPOSABLE_EXPRESSION;
      } else {
        Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
      }
    }
  }

  return CallSiteType.UNSUPPORTED;
}
 
Example 5
Source File: Closure_115_FunctionInjector_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Determine which, if any, of the supported types the call site is.
 */
private CallSiteType classifyCallSite(Node callNode) {
  Node parent = callNode.getParent();
  Node grandParent = parent.getParent();

  // Verify the call site:
  if (NodeUtil.isExprCall(parent)) {
    // This is a simple call?  Example: "foo();".
    return CallSiteType.SIMPLE_CALL;
  } else if (NodeUtil.isExprAssign(grandParent)
      && !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
      && parent.getFirstChild().isName()
      && !NodeUtil.isConstantName(parent.getFirstChild())) {
    // This is a simple assignment.  Example: "x = foo();"
    return CallSiteType.SIMPLE_ASSIGNMENT;
  } else if (parent.isName()
      && !NodeUtil.isConstantName(parent)
      && grandParent.isVar()
      && grandParent.hasOneChild()) {
    // This is a var declaration.  Example: "var x = foo();"
    // TODO(johnlenz): Should we be checking for constants on the
    // left-hand-side of the assignments and handling them as EXPRESSION?
    return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
  } else {
    Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
    if (expressionRoot != null) {
      ExpressionDecomposer decomposer = new ExpressionDecomposer(
          compiler, safeNameIdSupplier, knownConstants);
      DecompositionType type = decomposer.canExposeExpression(
          callNode);
      if (type == DecompositionType.MOVABLE) {
        return CallSiteType.EXPRESSION;
      } else if (type == DecompositionType.DECOMPOSABLE) {
        return CallSiteType.DECOMPOSABLE_EXPRESSION;
      } else {
        Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
      }
    }
  }

  return CallSiteType.UNSUPPORTED;
}
 
Example 6
Source File: Closure_115_FunctionInjector_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Determine which, if any, of the supported types the call site is.
 */
private CallSiteType classifyCallSite(Node callNode) {
  Node parent = callNode.getParent();
  Node grandParent = parent.getParent();

  // Verify the call site:
  if (NodeUtil.isExprCall(parent)) {
    // This is a simple call?  Example: "foo();".
    return CallSiteType.SIMPLE_CALL;
  } else if (NodeUtil.isExprAssign(grandParent)
      && !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
      && parent.getFirstChild().isName()
      && !NodeUtil.isConstantName(parent.getFirstChild())) {
    // This is a simple assignment.  Example: "x = foo();"
    return CallSiteType.SIMPLE_ASSIGNMENT;
  } else if (parent.isName()
      && !NodeUtil.isConstantName(parent)
      && grandParent.isVar()
      && grandParent.hasOneChild()) {
    // This is a var declaration.  Example: "var x = foo();"
    // TODO(johnlenz): Should we be checking for constants on the
    // left-hand-side of the assignments and handling them as EXPRESSION?
    return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
  } else {
    Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
    if (expressionRoot != null) {
      ExpressionDecomposer decomposer = new ExpressionDecomposer(
          compiler, safeNameIdSupplier, knownConstants);
      DecompositionType type = decomposer.canExposeExpression(
          callNode);
      if (type == DecompositionType.MOVABLE) {
        return CallSiteType.EXPRESSION;
      } else if (type == DecompositionType.DECOMPOSABLE) {
        return CallSiteType.DECOMPOSABLE_EXPRESSION;
      } else {
        Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
      }
    }
  }

  return CallSiteType.UNSUPPORTED;
}
 
Example 7
Source File: FunctionInjector.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determine which, if any, of the supported types the call site is.
 */
private CallSiteType classifyCallSite(Node callNode) {
  Node parent = callNode.getParent();
  Node grandParent = parent.getParent();

  // Verify the call site:
  if (NodeUtil.isExprCall(parent)) {
    // This is a simple call?  Example: "foo();".
    return CallSiteType.SIMPLE_CALL;
  } else if (NodeUtil.isExprAssign(grandParent)
      && !NodeUtil.isVarOrSimpleAssignLhs(callNode, parent)
      && parent.getFirstChild().isName()
      && !NodeUtil.isConstantName(parent.getFirstChild())) {
    // This is a simple assignment.  Example: "x = foo();"
    return CallSiteType.SIMPLE_ASSIGNMENT;
  } else if (parent.isName()
      && !NodeUtil.isConstantName(parent)
      && grandParent.isVar()
      && grandParent.hasOneChild()) {
    // This is a var declaration.  Example: "var x = foo();"
    // TODO(johnlenz): Should we be checking for constants on the
    // left-hand-side of the assignments and handling them as EXPRESSION?
    return CallSiteType.VAR_DECL_SIMPLE_ASSIGNMENT;
  } else {
    Node expressionRoot = ExpressionDecomposer.findExpressionRoot(callNode);
    if (expressionRoot != null) {
      ExpressionDecomposer decomposer = new ExpressionDecomposer(
          compiler, safeNameIdSupplier, knownConstants);
      DecompositionType type = decomposer.canExposeExpression(
          callNode);
      if (type == DecompositionType.MOVABLE) {
        return CallSiteType.EXPRESSION;
      } else if (type == DecompositionType.DECOMPOSABLE) {
        return CallSiteType.DECOMPOSABLE_EXPRESSION;
      } else {
        Preconditions.checkState(type == DecompositionType.UNDECOMPOSABLE);
      }
    }
  }

  return CallSiteType.UNSUPPORTED;
}