java-ast
v0.4.1
Published
Java Parser for JavaScript/TypeScript, based on antlr4ts
Downloads
5,313
Maintainers
Readme
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)
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.