Skip to content

Commit

Permalink
Retrieve package name and class name prefix for the code generator in…
Browse files Browse the repository at this point in the history
… Kotlin from the target enum.
  • Loading branch information
hokeun committed Jul 26, 2021
1 parent bd6d6db commit 2c50c49
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions org.lflang/src/org/lflang/generator/LFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,12 @@ private GeneratorBase createKotlinGenerator(Target target, FileConfig fileConfig
// play a few tricks here so that Kotlin FileConfig and
// Kotlin Generator do not appear as an import. Instead we look the
// class up at runtime and instantiate it if found.
String packageName;
String classNamePrefix;
switch (target) {
case CPP: {
packageName = "cpp";
classNamePrefix = "Cpp";
break;
}
case TS: {
packageName = "ts";
classNamePrefix = "Ts";
break;
}
default: {
throw new RuntimeException("Unexpected target!");
}
if (target.name().length() < 2) {
throw new RuntimeException("Unexpected target!");
}
String packageName = target.name().toLowerCase();
String classNamePrefix = target.name().charAt(0)

This comment has been minimized.

Copy link
@lhstrh

lhstrh Jul 26, 2021

Member

I don't think this works for Cpp, right? Perhaps add a function called getPackagePrefix to Target?

This comment has been minimized.

Copy link
@hokeun

hokeun Jul 26, 2021

Author Member

I think this works for Cpp. target.name() is CPP; so it works since the package name is cpp and the class name prefix is Cpp.

This comment has been minimized.

Copy link
@lhstrh

lhstrh Jul 26, 2021

Member

OK, but for TypeScript I think the prefix should be TS or TypeScript, not Ts.

This comment has been minimized.

Copy link
@hokeun

hokeun Jul 26, 2021

Author Member

Got it, I changed the prefix to TS and created methods for returning the package names and class name prefixes.

+ target.name().substring(1).toLowerCase();
try {
return (GeneratorBase) Class
.forName("org.lflang.generator." + packageName + "." + classNamePrefix + "Generator")
Expand Down

0 comments on commit 2c50c49

Please sign in to comment.