Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to make Java models extend a class and implement interfaces. #205

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/Core/FileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public enum GenerationParameterType {
case indent
case packageName
case javaNullabilityAnnotationType
case javaExtends
case javaImplements
}

// Most of these are derived from https://www.binpress.com/tutorial/objective-c-reserved-keywords/43
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/JavaModelRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ public struct JavaModelRenderer: JavaFileRenderer {
aClass: JavaIR.Class(
annotations: [],
modifiers: [.public],
extends: nil,
implements: nil,
extends: params[.javaExtends],
implements: params[.javaImplements]?.components(separatedBy: ","),
name: className,
methods: [
self.renderModelConstructor(),
Expand Down
10 changes: 10 additions & 0 deletions Sources/plank/Cli.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ enum FlagOptions: String {
case objectiveCClassPrefix = "objc_class_prefix"
case javaPackageName = "java_package_name"
case javaNullabilityAnnotationType = "java_nullability_annotation_type"
case javaExtends = "java_extends"
case javaImplements = "java_implements"
case printDeps = "print_deps"
case noRecursive = "no_recursive"
case noRuntime = "no_runtime"
Expand All @@ -41,6 +43,8 @@ enum FlagOptions: String {
case .version: return false
case .javaPackageName: return true
case .javaNullabilityAnnotationType: return true
case .javaExtends: return true
case .javaImplements: return true
}
}
}
Expand All @@ -64,6 +68,8 @@ extension FlagOptions: HelpCommandOutput {
" Java:",
" --\(FlagOptions.javaPackageName.rawValue) - The package name to associate with generated Java sources",
" --\(FlagOptions.javaNullabilityAnnotationType.rawValue) - The type of nullability annotations to use. Can be either \"android-support\" (default) or \"androidx\".",
" --\(FlagOptions.javaExtends.rawValue) - The class that the model extends",
" --\(FlagOptions.javaImplements.rawValue) - The interface(s) that the model implements. If there are multiple interfaces, separate with commas.",
].joined(separator: "\n")
}
}
Expand Down Expand Up @@ -148,6 +154,8 @@ func handleGenerateCommand(withArguments arguments: [String]) {
let indent: String? = flags[.indent]
let packageName: String? = flags[.javaPackageName]
let javaNullabilityAnnotationType: String? = flags[.javaNullabilityAnnotationType]
let javaExtends: String? = flags[.javaExtends]
let javaImplements: String? = flags[.javaImplements]

let generationParameters: GenerationParameters = [
(.recursive, recursive),
Expand All @@ -156,6 +164,8 @@ func handleGenerateCommand(withArguments arguments: [String]) {
(.indent, indent),
(.packageName, packageName),
(.javaNullabilityAnnotationType, javaNullabilityAnnotationType),
(.javaExtends, javaExtends),
(.javaImplements, javaImplements),
].reduce([:]) { (dict: GenerationParameters, tuple: (GenerationParameterType, String?)) in
var mutableDict = dict
if let val = tuple.1 {
Expand Down