apex-reflection

所属分类:Node.js
开发工具:Dart
文件大小:0KB
下载次数:0
上传日期:2023-10-05 13:44:56
上 传 者sh-1993
说明:  Apex编程语言的基本反射。,
(Basic reflection for the Apex programming language.,)

文件列表:
.husky/ (0, 2023-10-24)
.husky/pre-commit (51, 2023-10-24)
.idea/ (0, 2023-10-24)
.idea/apexdocs-dart.iml (893, 2023-10-24)
.idea/git_toolbox_prj.xml (480, 2023-10-24)
.idea/libraries/ (0, 2023-10-24)
.idea/libraries/Dart_Packages.xml (23550, 2023-10-24)
.idea/libraries/Dart_SDK.xml (1987, 2023-10-24)
.idea/misc.xml (133, 2023-10-24)
.idea/modules.xml (278, 2023-10-24)
.idea/runConfigurations/ (0, 2023-10-24)
.idea/runConfigurations/_template__of_Dart_Test.xml (258, 2023-10-24)
.idea/runConfigurations/_template__of_Dart_Test2.xml (258, 2023-10-24)
.idea/runConfigurations/_template__of_Dart_Test3.xml (258, 2023-10-24)
.idea/runConfigurations/_template__of_Dart_Test4.xml (195, 2023-10-24)
.idea/vcs.xml (167, 2023-10-24)
TODO.md (116, 2023-10-24)
analysis_options.yaml (1037, 2023-10-24)
example/ (0, 2023-10-24)
example/node_example/ (0, 2023-10-24)
example/node_example/index.js (232, 2023-10-24)
example/node_example/package.json (226, 2023-10-24)
example/node_example_ts/ (0, 2023-10-24)
example/node_example_ts/package-lock.json (2521, 2023-10-24)
example/node_example_ts/package.json (354, 2023-10-24)
example/node_example_ts/src/ (0, 2023-10-24)
example/node_example_ts/src/index.js (347, 2023-10-24)
example/node_example_ts/src/index.ts (239, 2023-10-24)
example/node_example_ts/tsconfig.json (6046, 2023-10-24)
example/sample.txt (14, 2023-10-24)
js/ (0, 2023-10-24)
js/apex-reflection-node/ (0, 2023-10-24)
js/apex-reflection-node/__tests__/ (0, 2023-10-24)
js/apex-reflection-node/__tests__/end-to-end.test.ts (11558, 2023-10-24)
js/apex-reflection-node/index.d.ts (4109, 2023-10-24)
js/apex-reflection-node/index.js (213, 2023-10-24)
... ...

# Apex Reflection Provides basic reflection for the Apex programming language. ## Installation ``` npm i @cparra/apex-reflection ``` ## Usage This library exposes a single function that handles parsing the body of an Apex top level type (class, interface, or enum) and returns the result. ```typescript import {reflect} from '@cparra/apex-reflection'; const classBody = 'public with sharing class ExampleClass {}'; const response = reflect(classBody); ``` If you wish to parse an Apex type that comes from a file, you can read the file contents and use that as the source to reflect ```typescript import * as fs from 'fs'; import {reflect} from '@cparra/apex-reflection'; const path = './MyClass.cls'; const rawFile = fs.readFileSync(path); const response = reflect(rawFile.toString()); ``` The `reflect` function returns a `ReflectionResult` which contains either the results of the parsed `Type` (which will either be a `ClassMirror`, an `InterfaceMirror` or an `EnumMirror`) or a `ParsingError` if the passed in body was not parsed successfully, with a message indicating where the error occurred. ## Contributing Even though this library is exposed as a Node.js library, the project's source code is written in Dart. The source can be found in the `lib/src` directory. The Dart source code is transpiled to JS by `dart2js` through the default [grinder](https://pub.dev/packages/grinder) workflow within `tool/grind.dart`. To generate the JS files first set up `grinder` locally by following that package's instructions through its pub.dev listing, and then you can simply run `grind`. That build takes care of combining the output with `preamble/preamble.js` to achieve compatibility with Node.js. The resulting file is `js/apex-reflection-node/out.js`. ### Tests Both the Dart source code and the JS output must be tested. The Dart tests live in the `test` directory. The Dart source code must have unit tests testing each individual Dart file as well as end-to-end tests that verify the overall parsing functionality. The JS tests live in `js/apex-reflection-node/__tests__`. These are end-to-end tests that ensure that the transpiled JS code is working as intended. ### JSON serialization The reflection operation outputs a JSON representation of the Apex type, which is then deserialized on the JS side to return typed objects. Serialization is handled through the [json_serializable](https://pub.dev/packages/json_serializable) package, which helps automatically create the round-trip code for serialization and de-serialization. When changing any of the model classes with serialization support, to re-build the serialization code run ```shell dart run build_runner build ``` To keep the runner live by watching any modifications to files, run ```shell dart run build_runner watch ``` ### Parsing This needs to be run with ANTLR 4.9.3 The parsing algorithm relies on using ANTLR4 and its Dart target. To generate the Antlr4 **Apex** output run: ```shell java org.antlr.v4.Tool -Dlanguage=Dart lib/src/antlr/grammars/apex/ApexLexer.g4 lib/src/antlr/grammars/apex/ApexParser.g4 -o lib/src/antlr/lib/apex/ ``` To generate the Antlr4 **Apexdoc** output run: ```shell java org.antlr.v4.Tool -Dlanguage=Dart lib/src/antlr/grammars/apexdoc/ApexdocLexer.g4 lib/src/antlr/grammars/apexdoc/ApexdocParser.g4 -o lib/src/antlr/lib/apexdoc/ ``` ## Typescript This library provides its own TS type definition.

近期下载者

相关文件


收藏者