java-ast
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

java-ast

npm version code style: prettier

Java Parser for JavaScript/TypeScript, based on antlr4ts, grammar taken from antlr4's java grammar too (so please report bugs and open pull requests related to grammars upstream)

Usage Example

import { parse, createVisitor } from 'java-ast';

const countMethods = (source: string) => {
  let ast = parse(source);

  return createVisitor({
    visitMethodDeclaration: () => 1,
    defaultResult: () => 0,
    aggregateResult: (a, b) => a + b,
  }).visit(ast);
};

console.log(
  countMethods(`
    class A {
      int a;
      void b() {}
      void c() {}
    }
    class B {
      void z() {}
    }
  `),
); // logs 3

History

This project was originally created by Uri Shaked.

See also

  • java-model - Provides high-level access to the Java type model.

License

MIT

Package Sidebar

Install

npm i java-ast

Weekly Downloads

325

Version

0.4.1

License

MIT

Unpacked Size

905 kB

Total Files

21

Last publish

Collaborators

  • pascalgn