Beispiel #1
0
  /**
   * Check if two terms are similar. Meaning they have the same constructor, and the children are
   * located in the same places.
   *
   * @param t1 - first term.
   * @param t2 - second term.
   * @param context - the context in which to compare them.
   * @return - true if the terms are similar, false otherwise.
   */
  private boolean isSimilar(IStrategoTerm t1, IStrategoTerm t2, Context context) {
    if (t1.getTermType() != t2.getTermType()) return false;

    if (t1.getTermType() == IStrategoTerm.APPL)
      if (!((IStrategoAppl) t1).getName().equals(((IStrategoAppl) t2).getName())) return false;
    if (t1.getTermType() == IStrategoTerm.STRING)
      if (!((IStrategoString) t1).stringValue().equals(((IStrategoString) t2).stringValue()))
        return false;
    if (t1.getTermType() == IStrategoTerm.INT)
      if (((IStrategoInt) t1).intValue() != ((IStrategoInt) t2).intValue()) return false;

    for (int i = 0; i < t1.getSubtermCount(); i++) {
      IStrategoTerm ch1 = t1.getSubterm(i);
      IStrategoTerm ch2 = t2.getSubterm(i);
      IStrategoTerm loc1 = ch1.getAnnotations();
      IStrategoTerm loc2 = ch2.getAnnotations();

      if (loc1 == null) context.getIOAgent().printError("Error1: " + ch1);
      if (loc2 == null) context.getIOAgent().printError("Error2: " + ch2);

      if (!loc1.toString().equals(loc2.toString())) return false;
    }
    return true;
  }