Пример #1
0
  /**
   * @param s the scope we're checking for
   * @return if the scope passed as a parameter starts with the same scope we have here. It should
   *     not be called if the size of the scope we're checking is bigger than the size of 'this'
   *     scope.
   */
  @SuppressWarnings("unchecked")
  private boolean checkIfScopesMatch(ILocalScope s) {
    Iterator<SimpleNode> otIt = s.getScopeStack().iterator();

    for (Iterator<SimpleNode> iter = this.scope.iterator(); iter.hasNext(); ) {
      SimpleNode element = iter.next();
      SimpleNode otElement = otIt.next();

      if (element.beginColumn != otElement.beginColumn) {
        return false;
      }

      if (element.beginLine != otElement.beginLine) {
        return false;
      }

      if (!element.getClass().equals(otElement.getClass())) {
        return false;
      }

      String rep1 = NodeUtils.getFullRepresentationString(element);
      String rep2 = NodeUtils.getFullRepresentationString(otElement);
      if (rep1 == null || rep2 == null) {
        if (rep1 != rep2) {
          return false;
        }

      } else if (!rep1.equals(rep2)) {
        return false;
      }
    }
    return true;
  }
Пример #2
0
  public boolean equals(Object obj) {

    MemoVisitor other = (MemoVisitor) obj;
    Iterator<SimpleNode> iter1 = other.visited.iterator();

    for (Iterator<SimpleNode> iter = visited.iterator(); iter.hasNext(); ) {
      SimpleNode n = (SimpleNode) iter.next();
      SimpleNode n1 = null;
      try {
        n1 = (SimpleNode) iter1.next();
      } catch (NoSuchElementException e) {
        throw new RuntimeException("Just received " + n, e);
      }

      if (n instanceof Expr && n1 instanceof Expr) {
        continue;
      }
      print(n.getClass());
      if (n.getClass().equals(n1.getClass()) == false) {
        print("n.getClass() != n1.getClass() " + n.getClass() + " != " + n1.getClass());
        return false;
      }
      //            if(n.beginColumn != n1.beginColumn){
      //                print("n = "+n+" n1 = "+n1);
      //                print("n = "+NodeUtils.getFullRepresentationString(n)+" n1 =
      // "+NodeUtils.getFullRepresentationString(n1));
      //                print("n.beginColumn != n1.beginColumn "+ n.beginColumn +" != "+
      // n1.beginColumn);
      //                return false;
      //            }
      //            if(n.beginLine != n1.beginLine){
      //                print("n.beginLine != n1.beginLine "+ n.beginLine +" != "+ n1.beginLine);
      //                return false;
      //            }

      String s1 = NodeUtils.getFullRepresentationString(n);
      String s2 = NodeUtils.getFullRepresentationString(n1);
      if ((s1 == null && s2 != null) || (s1 != null && s2 == null)) {
        print("(s1 == null && s2 != null) || (s1 != null && s2 == null)");
        return false;
      }

      if (s1.equals(s2.replaceAll("\r", "")) == false) {
        print("s1 != s2 \n-->" + s1 + "<--\n!=\n-->" + s2 + "<--");
        return false;
      }
    }

    return true;
  }