<commit_before>package com.google.errorprone;

import com.sun.tools.javac.tree.JCTree;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Wraps a Map<JCTree, Integer> (used for javac endpositions) so that the JCTree keys can be
 * searched by value equality.  JCTree does not implement equals and hashCode, so reference
 * equality would be used otherwise.
 *
 * @author <NAME> (<EMAIL>)
 */
class WrappedTreeMap extends AbstractMap<JCTree, Integer> {

   /**
   * A map from wrapped tree nodes to tree end positions.
   */
  private final Map<WrappedTreeNode, Integer> wrappedMap;

  public WrappedTreeMap(Map<JCTree, Integer> map) {
    wrappedMap = new HashMap<WrappedTreeNode, Integer>();
    for (Map.Entry<JCTree, Integer> entry : map.entrySet()) {
      wrappedMap.put(new WrappedTreeNode(entry.getKey()), entry.getValue());
    }
  }

  @Override
  public Set<Map.Entry<JCTree, Integer>> entrySet() {
    throw new UnsupportedOperationException("entrySet() not implemented on WrappedTreeMap");
  }

  @Override
  public Integer get(Object key) {
    if (!(key instanceof JCTree)) {
      return null;
    }
    WrappedTreeNode wrappedNode = new WrappedTreeNode((JCTree) key);
    return wrappedMap.get(wrappedNode);
  }

  /**
   * Wraps a node of type JCTree so that we can do an equals/hashCode comparison.
   */
  public class WrappedTreeNode {

    private final JCTree node;

    public WrappedTreeNode(JCTree node) {
      this.node = node;
    }

    /**
     * equals compares start position, kind of node, and tag. This is an approximation and may not
     * actually distinguish between unequal tree nodes.
     *
     * Note: Do not include node.toString() as part of the hash or the equals.  We generate
     * the WrappedTreeMap after the parse phase, but we compare after the flow phase.  The
     * attribute phase may alter the structure of the AST nodes such that their string
     * representations no longer match.  For example, annotation nodes after the parse phase look
     * like:
     * @SuppressWarnings("foo")
     * But after the flow phase, they look like:
     * @SuppressWarnings(value = "foo")
     */
    @Override
    public boolean equals(Object o) {
      if (!(o instanceof WrappedTreeNode)) {
        return false;
      }
      WrappedTreeNode other = (WrappedTreeNode) o;

      return node.getStartPosition() == other.node.getStartPosition() &&
          node.getKind() == other.node.getKind() &&
          node.getTag() == other.node.getTag();
    }

    /**
     * Note: Do not include node.toString() as part of the hash or the equals.  We generate
     * the WrappedTreeMap after the parse phase, but we compare after the flow phase.  The
     * attribute phase may alter the structure of the AST nodes such that their string
     * representations no longer match.  For example, annotation nodes after the parse phase look
     * like:
     * @SuppressWarnings("foo")
     * But after the flow phase, they look like:
     * @SuppressWarnings(value = "foo")
     */
    @Override
    public int hashCode() {
      int result = 17;
      result = 31 * result + node.getStartPosition();
      result = 31 * result + node.getKind().ordinal();
      result = 31 * result + node.getTag();
      return result;
    }
  }

}<commit_msg>Fix bug in WrappedTreeMap<commit_after>package com.google.errorprone;

import com.sun.source.tree.Tree.Kind;
import com.sun.tools.javac.tree.JCTree;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Wraps a Map<JCTree, Integer> (used for javac endpositions) so that the JCTree keys can be
 * searched by value equality.  JCTree does not implement equals and hashCode, so reference
 * equality would be used otherwise.
 *
 * @author <NAME> (<EMAIL>)
 */
class WrappedTreeMap extends AbstractMap<JCTree, Integer> {

   /**
   * A map from wrapped tree nodes to tree end positions.
   */
  private final Map<WrappedTreeNode, Integer> wrappedMap;

  public WrappedTreeMap(Map<JCTree, Integer> map) {
    wrappedMap = new HashMap<WrappedTreeNode, Integer>();
    for (Map.Entry<JCTree, Integer> entry : map.entrySet()) {
      wrappedMap.put(new WrappedTreeNode(entry.getKey()), entry.getValue());
    }
  }

  @Override
  public Set<Map.Entry<JCTree, Integer>> entrySet() {
    throw new UnsupportedOperationException("entrySet() not implemented on WrappedTreeMap");
  }

  @Override
  public Integer get(Object key) {
    if (!(key instanceof JCTree)) {
      return null;
    }
    WrappedTreeNode wrappedNode = new WrappedTreeNode((JCTree) key);
    return wrappedMap.get(wrappedNode);
  }

  /**
   * Wraps a node of type JCTree so that we can do an equals/hashCode comparison.
   */
  public class WrappedTreeNode {

    private final JCTree node;

    public WrappedTreeNode(JCTree node) {
      this.node = node;
    }

    /**
     * equals compares start position, kind of node, and tag. This is an approximation and may not
     * actually distinguish between unequal tree nodes.
     *
     * Note: Do not include node.toString() as part of the hash or the equals.  We generate
     * the WrappedTreeMap after the parse phase, but we compare after the flow phase.  The
     * attribute phase may alter the structure of the AST nodes such that their string
     * representations no longer match.  For example, annotation nodes after the parse phase look
     * like:
     * @SuppressWarnings("foo")
     * But after the flow phase, they look like:
     * @SuppressWarnings(value = "foo")
     */
    @Override
    public boolean equals(Object o) {
      if (!(o instanceof WrappedTreeNode)) {
        return false;
      }
      WrappedTreeNode other = (WrappedTreeNode) o;

      // LetExpr and TypeBoundKind throw an AssertionError on getKind(). Ignore them for computing
      // equality.
      Kind thisKind;
      Kind otherKind;
      try {
        thisKind = node.getKind();
      } catch (AssertionError e) {
        thisKind = null;
      }
      try {
        otherKind = other.node.getKind();
      } catch (AssertionError e) {
        otherKind = null;
      }

      return node.getStartPosition() == other.node.getStartPosition() &&
          thisKind == otherKind &&
          node.getTag() == other.node.getTag();
    }

    /**
     * Note: Do not include node.toString() as part of the hash or the equals.  We generate
     * the WrappedTreeMap after the parse phase, but we compare after the flow phase.  The
     * attribute phase may alter the structure of the AST nodes such that their string
     * representations no longer match.  For example, annotation nodes after the parse phase look
     * like:
     * @SuppressWarnings("foo")
     * But after the flow phase, they look like:
     * @SuppressWarnings(value = "foo")
     */
    @Override
    public int hashCode() {
      int result = 17;
      result = 31 * result + node.getStartPosition();
      try {
        result = 31 * result + node.getKind().ordinal();
      } catch (AssertionError e) {
        // getKind() throws an AssertionError for LetExpr and TypeBoundKind. Ignore it for 
        // calculating the hash code.
      }
      result = 31 * result + node.getTag();
      return result;
    }
  }

}

{'fraction_non_alphanumeric': 0.09532940693055746, 'fraction_numerical': 0.002191480619093275, 'mean_word_length': 2.879914984059511, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6718551', 'n_tokens_mistral': 2116, 'n_tokens_neox': 2081, 'n_words': 739}