<commit_before>package annotations.io;

import java.util.ArrayDeque;
import java.util.Deque;

import annotations.util.JVMNames;

import com.sun.source.tree.ClassTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;

/**
 * Structure bundling an {@link ASTPath} with information about its
 *  starting point. Necessary because the {@link ASTPath} structure
 *  does not include the declaration from which it originates.
 *
 * @author dbro
 */
public class ASTRecord implements Comparable<ASTRecord> {
  /**
   * Name of the enclosing class declaration.
   */
  public final String className;

  /**
   * Name of the enclosing method declaration, or null if there is none.
   */
  public final String methodName;

  /**
   * Name of the enclosing variable declaration, or null if there is none.
   */
  public final String varName;

  /**
   * Kind of immediately enclosing declaration: METHOD, VARIABLE, or a
   *  class type (CLASS, INTERFACE, ENUM, or ANNOTATION_TYPE).
   */
  public final ASTPath astPath;

  public ASTRecord(String className, String methodName, String varName,
      ASTPath astPath) {
    this.className = className;
    this.methodName = methodName;
    this.varName = varName;
    this.astPath = astPath;<commit_msg>Adds logic for canonicalizing the AST path.<commit_after>package annotations.io;

import java.util.ArrayDeque;
import java.util.Deque;

import annotations.util.JVMNames;

import com.sun.source.tree.ClassTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;

/**
 * Structure bundling an {@link ASTPath} with information about its
 *  starting point. Necessary because the {@link ASTPath} structure
 *  does not include the declaration from which it originates.
 *
 * @author dbro
 */
public class ASTRecord implements Comparable<ASTRecord> {
  /**
   * Name of the enclosing class declaration.
   */
  public final String className;

  /**
   * Name of the enclosing method declaration, or null if there is none.
   */
  public final String methodName;

  /**
   * Name of the enclosing variable declaration, or null if there is none.
   */
  public final String varName;

  /**
   * Path through AST, from specified declaration to descendant node.
   */
  public final ASTPath astPath;

  public ASTRecord(String className, String methodName, String varName,
      ASTPath astPath) {
    this.className = className;
    this.methodName = methodName;
    this.varName = varName;
    // FIXME: ensure path is canonical
    if (varName != null) {
      // TODO
    } else if (methodName != null) {
      int n = astPath.size();
      if (n > 0 && astPath.get(0).getTreeKind() != Tree.Kind.METHOD
          && astPath.get(0).getTreeKind() != Tree.Kind.VARIABLE) {
        ASTPath bodyPath = ASTPath.empty().add(
            new ASTPath.ASTEntry(Tree.Kind.METHOD, ASTPath.BODY));
        for (int i = 0; i < n; i++) { bodyPath = bodyPath.add(astPath.get(i)); }
        astPath = bodyPath;
      }
    }
    this.astPath = astPath;
{'fraction_non_alphanumeric': 0.10417910447761194, 'fraction_numerical': 0.0011940298507462687, 'mean_word_length': 3.36328125, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '5926215', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1000, 'n_words': 306}