Skip to content

Commit 34d6f97

Browse files
fix: export to Language (Java) has incorrect class name COMPASS-6159 (#3914)
* fix: export to Language (Java) has incorrect class name COMPASS-6159 * refactor: remove bootstrap * fix: use imports depending on mode * docs: update readme * refactor: reformat * refactor: make code more readable * refactor: remove extra check * refactor: eventually for of * test: move position of the imported class
1 parent 78df036 commit 34d6f97

29 files changed

+75
-60
lines changed

packages/bson-transpilers/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ Output a compiled string given input and output languages.
4141
- __codeString:__ The code string you would like to be compiled to your
4242
selected output language.
4343

44-
### importsString = transpiler\[inputLang\]\[outputLang\].getImports()
44+
### importsString = transpiler\[inputLang\]\[outputLang\].getImports(mode, driverSyntax)
4545
Output a string containing the set of import statements for the generated code
4646
to compile. These are all the packages that the compiled code could use so that
4747
the transpiler output will be runnable.
48+
- __inputLang:__ Input language of the code string. `shell` and `javascript`
49+
are currently supported.
50+
- __outputLang:__ The language you would like the output to be. `java`,
51+
`python`, `shell`, `javascript`, and `csharp` are currently supported.
52+
- __mode:__ Either 'Query' for the `.find()` method or 'Pipeline' for `.aggregate()`.
53+
- __driverSyntax:__ Whether or not you want to include Driver Syntax into your output string.
4854

4955
### catch (error)
5056
Any transpiler errors that occur will be thrown. To catch them, wrap the

packages/bson-transpilers/codegeneration/CodeGenerationVisitor.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ module.exports = (ANTLRVisitor) => class CodeGenerationVisitor extends ANTLRVisi
8787
* PUBLIC: As code is generated, any classes that require imports are tracked
8888
* in this.Imports. Each class has a "code" defined in the symbol table.
8989
* The imports are then generated based on the output language templates.
90-
*
90+
* @param {String} mode
9191
* @param {Boolean} driverSyntax (optional)
92-
* @return {String} - The list of imports in the target language.
92+
* @return {String} - The list of imports in the target language.
9393
*/
94-
getImports(driverSyntax) {
94+
getImports(mode, driverSyntax) {
9595
const importTemplate = this.Imports.import.template ?
9696
this.Imports.import.template :
9797
(s) => (
@@ -107,18 +107,16 @@ module.exports = (ANTLRVisitor) => class CodeGenerationVisitor extends ANTLRVisi
107107
}
108108
});
109109
this.requiredImports.driver = !!driverSyntax;
110-
const imports = Object.keys(this.requiredImports)
111-
.filter((code) => {
112-
return (
113-
this.requiredImports[code] &&
114-
this.Imports[code] &&
115-
this.Imports[code].template
116-
);
117-
})
118-
.reduce((obj, c) => {
119-
obj[c] = this.Imports[c].template(this.requiredImports[c]);
120-
return obj;
121-
}, {});
110+
const imports = {};
111+
for (const code of Object.keys(this.requiredImports)) {
112+
if (
113+
this.requiredImports[code] &&
114+
this.Imports[code] &&
115+
this.Imports[code].template
116+
) {
117+
imports[code] = this.Imports[code].template(this.requiredImports[code], mode);
118+
}
119+
}
122120
return importTemplate(imports);
123121
}
124122

packages/bson-transpilers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ const getTranspiler = (loadTree, visitor, generator, symbols) => {
184184
return transpiler.Syntax.driver.bind(transpiler.getState())(result);
185185
},
186186
compile: compile,
187-
getImports: (driverSyntax) => {
188-
return transpiler.getImports(driverSyntax);
187+
getImports: (mode, driverSyntax) => {
188+
return transpiler.getImports(mode, driverSyntax);
189189
}
190190
};
191191
};

packages/bson-transpilers/lib/symbol-table/javascripttogo.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bson-transpilers/lib/symbol-table/javascripttojava.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bson-transpilers/lib/symbol-table/pythontogo.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bson-transpilers/lib/symbol-table/pythontojava.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bson-transpilers/lib/symbol-table/shelltogo.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bson-transpilers/lib/symbol-table/shelltojava.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bson-transpilers/symbols/go/templates.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ Templates:
932932
.join('\n');
933933
}
934934
DriverImportTemplate: &DriverImportTemplate !!js/function >
935-
(args) => {
935+
() => {
936936
return [
937937
"go.mongodb.org/mongo-driver/mongo",
938938
"go.mongodb.org/mongo-driver/mongo/options",

0 commit comments

Comments
 (0)