Java Code Examples for com.google.javascript.rhino.jstype.JSType#isEquivalent()

The following examples show how to use com.google.javascript.rhino.jstype.JSType#isEquivalent() . 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: Nopol2017_0028_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 2
Source File: Nopol2017_0040_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING) {
    int quoted1 = this.getIntProp(QUOTED_PROP);
    int quoted2 = node.getIntProp(QUOTED_PROP);
    if (quoted1 != quoted2) {
      return false;
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 3
Source File: Nopol2017_0012_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recur Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @param shallow If true, the method doesn't recur into inner functions.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(
    Node node, boolean compareJsType, boolean recur, boolean shallow) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recur) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(
          n2, compareJsType, !(shallow && n.isFunction()), shallow)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 4
Source File: Nopol2017_0036_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 5
Source File: Nopol2017_008_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 6
Source File: Nopol2017_0042_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING) {
    int quoted1 = this.getIntProp(QUOTED_PROP);
    int quoted2 = node.getIntProp(QUOTED_PROP);
    if (quoted1 != quoted2) {
      return false;
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 7
Source File: Nopol2017_0021_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recur Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @param shallow If true, the method doesn't recur into inner functions.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(
    Node node, boolean compareJsType, boolean recur, boolean shallow) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recur) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(
          n2, compareJsType, !(shallow && n.isFunction()), shallow)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 8
Source File: Nopol2017_0012_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recur Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @param shallow If true, the method doesn't recur into inner functions.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(
    Node node, boolean compareJsType, boolean recur, boolean shallow) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recur) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(
          n2, compareJsType, !(shallow && n.isFunction()), shallow)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 9
Source File: Nopol2017_0017_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recur Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @param shallow If true, the method doesn't recur into inner functions.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(
    Node node, boolean compareJsType, boolean recur, boolean shallow) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recur) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(
          n2, compareJsType, !(shallow && n.isFunction()), shallow)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 10
Source File: Nopol2017_0054_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || getNodeClass(this) != getNodeClass(node)) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.ARRAYLIT) {
    try {
      int[] indices1 = (int[]) getProp(Node.SKIP_INDEXES_PROP);
      int[] indices2 = (int[]) node.getProp(Node.SKIP_INDEXES_PROP);
      if (indices1 == null) {
        if (indices2 != null) {
          return false;
        }
      } else if (indices2 == null) {
        return false;
      } else if (indices1.length != indices2.length) {
        return false;
      } else {
        for (int i = 0; i < indices1.length; i++) {
          if (indices1[i] != indices2[i]) {
            return false;
          }
        }
      }
    } catch (Exception e) {
      return false;
    }
  } else if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING) {
    int quoted1 = this.getIntProp(QUOTED_PROP);
    int quoted2 = node.getIntProp(QUOTED_PROP);
    if (quoted1 != quoted2) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 11
Source File: Nopol2017_0034_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 12
Source File: Nopol2017_0011_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recur Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @param shallow If true, the method doesn't recur into inner functions.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(
    Node node, boolean compareJsType, boolean recur, boolean shallow) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recur) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(
          n2, compareJsType, !(shallow && n.isFunction()), shallow)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 13
Source File: Nopol2017_0017_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recur Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @param shallow If true, the method doesn't recur into inner functions.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(
    Node node, boolean compareJsType, boolean recur, boolean shallow) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recur) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(
          n2, compareJsType, !(shallow && n.isFunction()), shallow)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 14
Source File: Nopol2017_0023_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 15
Source File: Nopol2017_0030_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 16
Source File: Nopol2017_0056_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || getNodeClass(this) != getNodeClass(node)) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.ARRAYLIT) {
    try {
      int[] indices1 = (int[]) getProp(Node.SKIP_INDEXES_PROP);
      int[] indices2 = (int[]) node.getProp(Node.SKIP_INDEXES_PROP);
      if (indices1 == null) {
        if (indices2 != null) {
          return false;
        }
      } else if (indices2 == null) {
        return false;
      } else if (indices1.length != indices2.length) {
        return false;
      } else {
        for (int i = 0; i < indices1.length; i++) {
          if (indices1[i] != indices2[i]) {
            return false;
          }
        }
      }
    } catch (Exception e) {
      return false;
    }
  } else if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING) {
    int quoted1 = this.getIntProp(QUOTED_PROP);
    int quoted2 = node.getIntProp(QUOTED_PROP);
    if (quoted1 != quoted2) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 17
Source File: Nopol2017_008_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 18
Source File: Nopol2017_0057_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 19
Source File: Nopol2017_0052_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recurse Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(Node node, boolean compareJsType, boolean recurse) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || getNodeClass(this) != getNodeClass(node)) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.ARRAYLIT) {
    try {
      int[] indices1 = (int[]) getProp(Node.SKIP_INDEXES_PROP);
      int[] indices2 = (int[]) node.getProp(Node.SKIP_INDEXES_PROP);
      if (indices1 == null) {
        if (indices2 != null) {
          return false;
        }
      } else if (indices2 == null) {
        return false;
      } else if (indices1.length != indices2.length) {
        return false;
      } else {
        for (int i = 0; i < indices1.length; i++) {
          if (indices1[i] != indices2[i]) {
            return false;
          }
        }
      }
    } catch (Exception e) {
      return false;
    }
  } else if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING) {
    int quoted1 = this.getIntProp(QUOTED_PROP);
    int quoted2 = node.getIntProp(QUOTED_PROP);
    if (quoted1 != quoted2) {
      return false;
    }
  }

  if (recurse) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(n2, compareJsType, true)) {
        return false;
      }
    }
  }

  return true;
}
 
Example 20
Source File: Nopol2017_0011_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param compareJsType Whether to compare the JSTypes of the nodes.
 * @param recur Whether to compare the children of the current node, if
 *    not only the the count of the children are compared.
 * @param shallow If true, the method doesn't recur into inner functions.
 * @return Whether this node is equivalent semantically to the provided node.
 */
boolean isEquivalentTo(
    Node node, boolean compareJsType, boolean recur, boolean shallow) {
  if (type != node.getType()
      || getChildCount() != node.getChildCount()
      || this.getClass() != node.getClass()) {
    return false;
  }

  if (compareJsType && !JSType.isEquivalent(jsType, node.getJSType())) {
    return false;
  }

  if (type == Token.INC || type == Token.DEC) {
    int post1 = this.getIntProp(INCRDECR_PROP);
    int post2 = node.getIntProp(INCRDECR_PROP);
    if (post1 != post2) {
      return false;
    }
  } else if (type == Token.STRING || type == Token.STRING_KEY) {
    if (type == Token.STRING_KEY) {
      int quoted1 = this.getIntProp(QUOTED_PROP);
      int quoted2 = node.getIntProp(QUOTED_PROP);
      if (quoted1 != quoted2) {
        return false;
      }
    }

    int slashV1 = this.getIntProp(SLASH_V);
    int slashV2 = node.getIntProp(SLASH_V);
    if (slashV1 != slashV2) {
      return false;
    }
  } else if (type == Token.CALL) {
    if (this.getBooleanProp(FREE_CALL) != node.getBooleanProp(FREE_CALL)) {
      return false;
    }
  }

  if (recur) {
    Node n, n2;
    for (n = first, n2 = node.first;
         n != null;
         n = n.next, n2 = n2.next) {
      if (!n.isEquivalentTo(
          n2, compareJsType, !(shallow && n.isFunction()), shallow)) {
        return false;
      }
    }
  }

  return true;
}