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

0.3.0 • Public • Published

java-ast

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)

npm version Build Status code style: prettier

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

Package Sidebar

Install

npm i java-ast

Weekly Downloads

66

Version

0.3.0

License

MIT

Unpacked Size

730 kB

Total Files

21

Last publish

Collaborators

  • urish
  • pascalgn