void addTranslation(ASTNode node, String replacementText) {
    if (!enabled) {
      return;
    }

    if (node.getOrigin() != null) {
      // This node was parsed while loading the definition of another view
      // being referenced by the one being created, and we don't want
      // to track any expansions for the underlying view.
      return;
    }

    int tokenStartIndex = node.getTokenStartIndex();
    int tokenStopIndex = node.getTokenStopIndex();
    if (tokenStopIndex < 0) {
      // this is for artificially added tokens
      return;
    }
    Translation translation = new Translation();
    translation.tokenStopIndex = tokenStopIndex;
    translation.replacementText = replacementText;

    // Sanity check for overlap with regions already being expanded
    assert (tokenStopIndex >= tokenStartIndex);

    List<Integer> subsetEntries = new ArrayList<Integer>();
    // Is the existing entry and newer entry are subset of one another ?
    for (Map.Entry<Integer, Translation> existingEntry :
          translations.headMap(tokenStopIndex, true).entrySet()) {
      // check if the new entry contains the existing
      if (existingEntry.getValue().tokenStopIndex <= tokenStopIndex &&
            existingEntry.getKey() >= tokenStartIndex) {
        // Collect newer entry is if a super-set of existing entry,
        subsetEntries.add(existingEntry.getKey());
        // check if the existing entry contains the new
      } else if (existingEntry.getValue().tokenStopIndex >= tokenStopIndex &&
            existingEntry.getKey() <= tokenStartIndex) {
        assert (existingEntry.getValue().replacementText.contains(replacementText));
        // we don't need to add this new entry since there's already an overlapping one
        return;
      }
    }
    // remove any existing entries that are contained by the new one
    for (Integer index : subsetEntries) {
      translations.remove(index);
    }

    // It's all good: create a new entry in the map (or update existing one)
    translations.put(tokenStartIndex, translation);
  }
Register a translation to be performed as part of unparse. ANTLR imposes
strict conditions on the translations and errors out during
TokenRewriteStream.toString() if there is an overlap. It expects all
the translations to be disjoint (See HIVE-2439).
If the translation overlaps with any previously
registered translation, then it must be either
identical or a prefix (in which cases it is ignored),
or else it must extend the existing translation (i.e.
the existing translation must be a prefix/suffix of the new translation).
All other overlap cases result in assertion failures.

@param node
         target node whose subtree is to be replaced

@param replacementText
         text to use as replacement
ql/src/java/org/apache/hadoop/hive/ql/parse/UnparseTranslator.java