<commit_before># jvm-visitor

This module extends [`kylestev/jvm.js`](https://github.com/kylestev/jvm.js) by
exposing classes used for traversing the contents of a `ClassInfo` object from
jvm.js (a JavaScript representation of the JVM class file format) by utilizing
the [Visitor Pattern](https://en.wikipedia.org/wiki/Visitor_pattern).

## Examples

### Field Logging Visitor

```js
import { Jar } from 'jvm';
import { ClassVisitor } from 'jvm-visitor';

// instantiate a new ClassVisitor object
let visitor = new ClassVisitor;
// bind an event listener to the `visit-field` event whose callback is passed
// a `ClassInfo` object as well as a `FieldInfo` object.
visitor.on('visit-field', (cls, field) => {
  console.log('  %s %s.%s', field.desc, cls.name, field.name);
});

// parse the jar contents
Jar.unpack('/path/to/your.jar')
  // called when the Promise returned from `Jar#unpack(string)` succeeds
  .then((jar) => {
    // iterate all `ClassInfo` objects (`cls`) in the jar
    for (let [name, cls] of jar) {
      // pass the `ClassInfo` object to `ClassVisitor#accept(ClassInfo)`
      // in order to visit `cls` and its members<commit_msg>add link to unused field transform in readme<commit_after># jvm-visitor

This module extends [`kylestev/jvm.js`](https://github.com/kylestev/jvm.js) by
exposing classes used for traversing the contents of a `ClassInfo` object from
jvm.js (a JavaScript representation of the JVM class file format) by utilizing
the [Visitor Pattern](https://en.wikipedia.org/wiki/Visitor_pattern).

## Examples

* [Unused field remover](/examples/UnusedFieldTransform.js)

### Field Logging Visitor

```js
import { Jar } from 'jvm';
import { ClassVisitor } from 'jvm-visitor';

// instantiate a new ClassVisitor object
let visitor = new ClassVisitor;
// bind an event listener to the `visit-field` event whose callback is passed
// a `ClassInfo` object as well as a `FieldInfo` object.
visitor.on('visit-field', (cls, field) => {
  console.log('  %s %s.%s', field.desc, cls.name, field.name);
});

// parse the jar contents
Jar.unpack('/path/to/your.jar')
  // called when the Promise returned from `Jar#unpack(string)` succeeds
  .then((jar) => {
    // iterate all `ClassInfo` objects (`cls`) in the jar
    for (let [name, cls] of jar) {
      // pass the `ClassInfo` object to `ClassVisitor#accept(ClassInfo)`
      // in order to visit `cls` and its members
{'fraction_non_alphanumeric': 0.1327212020033389, 'fraction_numerical': 0.0, 'mean_word_length': 4.035714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '7111378', 'n_tokens_mistral': 760, 'n_tokens_neox': 750, 'n_words': 265}