-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add support for APEX parsing and lexing using antlr4ng * feat: support test impacting in CLI
- Loading branch information
Showing
47 changed files
with
29,518 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
[![CircleCI](https://circleci.com/gh/Codeneos/vlocode/tree/main.svg?style=svg)](https://circleci.com/gh/Codeneos/vlocode/tree/main) | ||
[![GitHub top language](https://img.shields.io/github/languages/top/codeneos/vlocode.svg?logo=github)](https://github.com/Codeneos/vlocode) | ||
[![Bugs](https://img.shields.io/sonar/https/sonarcloud.io/curlybracket.vlocode/bugs.svg?color=lightgray&label=bugs&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAolBMVEUAAAD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZ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Njz0oQB3hnjNWOVoKpA8Amo4Dl4wwkBupFoR4AgGnIfq7M5ScYOq0JD9jO5wPmgwmDH%2B2Qpk0%2FKyjxa32lfsYjRZtcmo0kfJERE4vyoHnihgRT1TOK0J97ngLk92MOWk5XKKxZtiu0CvNTXNlReQmu2FzIbgLlKoJ8XuLtdQ0XUZxkAfzVyzSV8N02Vtvd6s2NN8%2FSMNzaEo%2B%2F525sPG5a%2BycM08xqLAtHfX8Kj26UlZmgRTzFYlTkbJK9RjrNHUSvYWmQFj2UKbQxQ6u1Fz8ay8ojuTMR24nTekAX0aQKd5am65KRHaZvo4vivDAkfaFZdnhOKOEt7ZR9XwYBJZeKLJf7LP4vYv0BK5jBy9A2z3IAAAAASUVORK5CYII%3D)](https://sonarcloud.io/dashboard?id=curlybracket.vlocode) | ||
[![Vulnerabilities](https://img.shields.io/sonar/https/sonarcloud.io/curlybracket.vlocode/vulnerabilities.svg?label=vulnerabilities&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAolBMVEUAAAD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgD%2FZgCXdjhZAAAANXRSTlMA%2Bg335ykFAwnr7hDZON7Ie1ZDMfTUmIUUSSLPoVAa4r6K8rtyXD62gG2xpsKSjnZpYx6qTp5XIo8AAAOWSURBVFjD7VbZtqIwEGSVRXYQAVFBFvf16v%2F%2F2tgJKs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B%2F525sPG5a%2BycM08xqLAtHfX8Kj26UlZmgRTzFYlTkbJK9RjrNHUSvYWmQFj2UKbQxQ6u1Fz8ay8ojuTMR24nTekAX0aQKd5am65KRHaZvo4vivDAkfaFZdnhOKOEt7ZR9XwYBJZeKLJf7LP4vYv0BK5jBy9A2z3IAAAAASUVORK5CYII%3D)](https://sonarcloud.io/dashboard?id=curlybracket.vlocode) | ||
![NPM Version](https://img.shields.io/npm/v/%40vlocode%5Capex) | ||
|
||
# **@vlocode/apex** Salesforce APEX Language Parser | ||
|
||
Antlr4 based [APEX Parser](./src/grammar/ApexParser.ts) and [Grammar](./grammar/ApexParser.g4). This library uses [antlr4ng](https://github.com/mike-lischke/antlr4ng) as runtime library which is a port of the original antlr4 runtime library to TypeScript. | ||
|
||
The library exposes the APEX Lexer and APEX parser generated from the `.g4` grammar files allowing parsing of APEX source code using Visitor or Listener patterns. | ||
|
||
## Features | ||
|
||
- Full APEX and SOQL grammar support | ||
- Extract code structure from APEX source code | ||
- Identify classes, fields, methods, properties and access modifiers | ||
- Identify which classes are tested by which test classes | ||
|
||
## Example: Identifying test classes for a given class | ||
|
||
Below code demonstrates how to identify which classes are tested by which test classes. And prints the test classes for a given class name. | ||
|
||
```ts | ||
import { TestIdentifier } from '@vlocode/apex'; | ||
|
||
const testIdentifier = container.create(TestIdentifier); | ||
await testIdentifier.loadApexClasses(['path/to/apex/classes']); | ||
const testClasses = testIdentifier.getTestClasses('MyClass'); | ||
console.log(testClasses); | ||
``` | ||
|
||
## Example: Extracting class information from APEX source code | ||
|
||
Below code demonstrates how to extract class information from an APEX source fragment and prints the class name, fields and methods as well as their access modifiers. | ||
|
||
```ts | ||
import { Parser } from '@vlocode/apex'; | ||
|
||
const sourceCode = `public class Person { | ||
private String name; | ||
private Integer age; | ||
public String nameProperty { | ||
get { return this.name; } | ||
} | ||
public Integer getAge(Integer arg) { | ||
return this.age; | ||
} | ||
public Date getBirthDate() { | ||
return Date.now(); | ||
} | ||
}`; | ||
|
||
const parser = new Parser(sourceCode); | ||
const struct = parser.getCodeStructure(); | ||
|
||
for (const classInfo of struct.classes) { | ||
console.log(`Class ${classInfo.name}`); | ||
|
||
console.log(` Fields: ${classInfo.fields.length}`); | ||
classInfo.fields.forEach((field, i) => | ||
console.log(` ${i + 1}) ${field.name} (${field.access})`) | ||
); | ||
|
||
console.log(` Methods: ${classInfo.methods.length}`); | ||
classInfo.methods.forEach((method, i) => | ||
console.log(` ${i + 1}) ${method.name} (${method.access})`) | ||
); | ||
} | ||
``` | ||
|
||
Outputs the following: | ||
|
||
```shell | ||
Class Person | ||
Fields: 2 | ||
1) name (private) | ||
2) age (private) | ||
Methods: 2 | ||
2) getAge (public) | ||
3) getBirthDate (public) | ||
``` | ||
|
||
## Credits | ||
|
||
The grammar files in this library are based on the grammar files from the `apex-parser` NPM library originally maintained by Andrey Gavrikov. The original library is no longer maintained and the grammar files have been updated to work with the latest version of Salesforce and the antlr4ng runtime library. |
Oops, something went wrong.