<commit_before>import logging

import lib.const as C
import lib.visit as v

from ..meta.program import Program
from ..meta.clazz import Clazz
from ..meta.method import Method
from ..meta.field import Field
from ..meta.statement import Statement
from ..meta.expression import Expression, to_expression

"""
class A {
    ... foo() {
        if (??) { doXoptional }
        if (??) { doYoptional }
    }
}

  =>

class A {
    static int e_h1 = ??;
    static int e_h2 = ??;
    ... foo() {
        if (A.e_h1) { doXoptional }
        if (A.e_h2) { doYoptional }
    }
}
"""
class EHole(object):

  # to avoid name conflict, use fresh counter as suffix
  __cnt = 0
  @classmethod
  def fresh_cnt(cls):
    cls.__cnt = cls.__cnt + 1
    return cls.__cnt

  def __init__(self):
    self._cur_mtd = None
    self._cur_s = None

  @v.on("node")
  def visit(self, node):
    """
    This is the generic method to initialize the dynamic dispatcher
    """

  @v.when(Program)
  def visit(self, node): pass

  @v.when(Clazz)
  def visit(self, node): pass

  @v.when(Field)
  def visit(self, node):
    # to avoid introducing another hole variable
    # reset the context statement
    self._cur_s = None

  @v.when(Method)
  def visit(self, node):
    self._cur_mtd = node

  @v.when(Statement)
  def visit(self, node):
    self._cur_s = node
    return [node]

  @v.when(Expression)
  def visit(self, node):
    # in case of visiting field initializing Expression
    if not self._cur_s: return node

    if node.kind == C.E.HOLE:
      cls = self._cur_mtd.clazz
      hname = u"e_h{}".format(EHole.fresh_cnt())
      hole = Field(clazz=cls, mods=[C.mod.ST], typ=C.J.i, name=hname, init=node)<commit_msg>using a flag to identify whether it's visiting field initializing exp or part of statements<commit_after>import logging

import lib.const as C
import lib.visit as v

from ..meta.program import Program
from ..meta.clazz import Clazz
from ..meta.method import Method
from ..meta.field import Field
from ..meta.statement import Statement
from ..meta.expression import Expression, to_expression

"""
class A {
    ... foo() {
        if (??) { doXoptional }
        if (??) { doYoptional }
    }
}

  =>

class A {
    static int e_h1 = ??;
    static int e_h2 = ??;
    ... foo() {
        if (A.e_h1) { doXoptional }
        if (A.e_h2) { doYoptional }
    }
}
"""
class EHole(object):

  # to avoid name conflict, use fresh counter as suffix
  __cnt = 0
  @classmethod
  def fresh_cnt(cls):
    cls.__cnt = cls.__cnt + 1
    return cls.__cnt

  def __init__(self):
    self._cur_mtd = None
    self._visiting_s = False

  @v.on("node")
  def visit(self, node):
    """
    This is the generic method to initialize the dynamic dispatcher
    """

  @v.when(Program)
  def visit(self, node): pass

  @v.when(Clazz)
  def visit(self, node): pass

  @v.when(Field)
  def visit(self, node):
    # to avoid introducing another hole variable
    # reset the context statement
    self._visiting_s = False

  @v.when(Method)
  def visit(self, node):
    self._cur_mtd = node
    if node.body:
      self._visiting_s = True

  @v.when(Statement)
  def visit(self, node): return [node]

  @v.when(Expression)
  def visit(self, node):
    # in case of visiting field initializing Expression
    if not self._visiting_s: return node

    if node.kind == C.E.HOLE:
      cls = self._cur_mtd.clazz
      hname = u"e_h{}".format(EHole.fresh_cnt())
      hole = Field(clazz=cls, mods=[C.mod.ST], typ=C.J.i, name=hname, init=node)
{'fraction_non_alphanumeric': 0.12457240592930445, 'fraction_numerical': 0.0034207525655644243, 'mean_word_length': 2.7409381663113006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2100542', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1200, 'n_words': 349}