Skip to content

Commit

Permalink
Allow unsetting the java lib configuration
Browse files Browse the repository at this point in the history
Setting `javaLib` to an empty string prevents including any library that provides Java APIs, and also prevents adding `extends JavaObject` to classes that have no base class. Useful if you plan to completely rewrite the code without any Java reminiscence.

Signed-off-by: Mike Lischke <mike@lischke-online.de>
  • Loading branch information
mike-lischke committed Mar 9, 2024
1 parent 6143c5f commit b487704
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/conversion/FileProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class FileProcessor {
header.append("\n");

let aliases = "";
if (this.configuration.options?.useUnqualifiedTypes) {
if (this.configuration.options?.useUnqualifiedTypes && this.configuration.javaLib !== "") {
// Create const reassignments and type aliases depending on the type of the imported symbol.
this.packageImports.forEach((symbol, key) => {
// Cannot create a type alias for an enum type (it would be infinite recursion).
Expand Down Expand Up @@ -722,7 +722,7 @@ export class FileProcessor {
if (context.EXTENDS()) {
this.getContent(localBuilder, context.EXTENDS());
this.processTypeType(localBuilder, context.typeType());
} else {
} else if (this.configuration.javaLib !== "") {
// Add the default extends clause.
localBuilder.append(" extends JavaObject");
this.registerJavaImport("JavaObject");
Expand Down Expand Up @@ -1355,6 +1355,11 @@ export class FileProcessor {
}
}

if (!hasSuperCall && this.configuration.javaLib === "") {
// Don't add a super call if no base class is specified and no java lib is used.
hasSuperCall = true;
}

result.containsThisCall = hasThisCall;

// See if we should automatically add a call to super. Only if none exists yet and this class extends another.
Expand Down Expand Up @@ -2739,8 +2744,12 @@ export class FileProcessor {
builder.append("class extends ");
} else {
if (info.symbol instanceof InterfaceSymbol) {
builder.append("class extends JavaObject implements ");
this.registerJavaImport("JavaObject");
if (this.configuration.javaLib === "") {
builder.append("class implements ");
} else {
builder.append("class extends JavaObject implements ");
this.registerJavaImport("JavaObject");
}
} else {
builder.append("class extends ");
}
Expand Down
2 changes: 1 addition & 1 deletion src/conversion/JavaToTypeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export interface IConverterConfiguration {
export class JavaToTypescriptConverter {
public constructor(private configuration: IConverterConfiguration) {
let javaLib;
if (!configuration.javaLib) {
if (configuration.javaLib === undefined) {
javaLib = "jree"; // Use the jree node module as default.
} else if (configuration.javaLib.indexOf("/") < 0) {
javaLib = configuration.javaLib; // Assume this is another node module.
Expand Down

0 comments on commit b487704

Please sign in to comment.