Skip to content

Commit

Permalink
Fixed problem with prefix setting
Browse files Browse the repository at this point in the history
The prefix setting can be a string or a function, but was always treated as function.

Signed-off-by: Mike Lischke <mike@lischke-online.de>
  • Loading branch information
mike-lischke committed Dec 2, 2023
1 parent d97b1a3 commit 5ab5d8d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"type": "node",
"request": "launch",
"name": "Convert ANTLR4",
"name": "Convert ANTLR4 runtime tests",
"sourceMaps": true,
"stopOnEntry": false,
"smartStep": true,
Expand All @@ -34,7 +34,7 @@
"--loader",
"ts-node/esm",
"src/convert",
"config/antlr4.json",
"config/antlr4-runtime-tests.json",
],
"console": "integratedTerminal",
"trace": false
Expand Down
57 changes: 57 additions & 0 deletions config/antlr4-runtime-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"packageRoot": "../antlr4/runtime-testsuite/test",
"include": [],
"exclude": [],
"outputPath": "../ANTLRng/runtime-testsuite/test",
"options": {
"convertAnnotations": false,
"sourceMappings": [],
"preferArrowFunctions": false,
"autoAddBraces": true,
"addNullUnionType": false,
"suppressTypeWithInitializer": true,
"wrapStringLiterals": false,
"memberOrderOptions": {
"default": [
"signature",
"public-static-field",
"protected-static-field",
"private-static-field",
"public-decorated-field",
"protected-decorated-field",
"private-decorated-field",
"public-instance-field",
"protected-instance-field",
"private-instance-field",
"public-abstract-field",
"protected-abstract-field",
"public-field",
"protected-field",
"private-field",
"static-field",
"instance-field",
"abstract-field",
"decorated-field",
"field",
"public-constructor",
"protected-constructor",
"private-constructor",
"constructor",
"public-static-method",
"protected-static-method",
"private-static-method",
"public-decorated-method",
"protected-decorated-method",
"private-decorated-method",
"public-instance-method",
"protected-instance-method",
"private-instance-method",
"public-abstract-method",
"protected-abstract-method"
]
},
"addIndexFiles": false,
"useUnqualifiedTypes": true
},
"debug": {}
}
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"whitespaces"
],
"ignoreWords": [
"ANTL",
"COLONCOLON",
"FEFFFFFFFFFFFFF",
"Harwell",
Expand All @@ -52,6 +53,7 @@
"stringtemplate",
"testlibrary",
"testng",
"testsuite",
"typeof",
"unmappable",
"unmocked",
Expand Down
10 changes: 9 additions & 1 deletion src/conversion/FileProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,15 @@ export class FileProcessor {

const firstChild = context.getChild(0);
const header = new java.lang.StringBuilder();
const prefix = this.configuration.options?.prefix as ConverterOptionsPrefixFunc ?? (() => { return ""; });
let prefix;
if (typeof this.configuration.options?.prefix === "string") {
prefix = () => { return this.configuration.options?.prefix as string; };
} else if (typeof this.configuration.options?.prefix === "function") {
prefix = this.configuration.options?.prefix;
} else {
prefix = () => { return ""; };
}

if (firstChild instanceof ParserRuleContext) {
header.append(this.getLeadingWhiteSpaces(firstChild));
header.append(prefix(this.source.sourceFile, this.source.targetFile));
Expand Down
2 changes: 1 addition & 1 deletion src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (args.length < 1) {
process.exit(1);
}

console.log("\nConverting Java to TypeScript...");
console.log("\nConverting Java to TypeScript...\n");

// Load the given configuration file and create a converter configuration from it.
const configFile = args[0];
Expand Down

0 comments on commit 5ab5d8d

Please sign in to comment.