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

kte: Fix parameter declaration for generated templates #319

Merged
merged 2 commits into from
Jan 19, 2024

Conversation

marcospereira
Copy link
Contributor

What?

Given the following template:

@param name: String
@param age: Int? = null

The generated code for Kotlin's renderMap would have:

@JvmStatic fun renderMap(jteOutput:gg.jte.html.HtmlTemplateOutput, jteHtmlInterceptor:gg.jte.html.HtmlInterceptor?, params:Map<String, Any?>) {
	val name = params["name"] as String
	val age = params["age"] as Int?? ?: null
	render(jteOutput, jteHtmlInterceptor, name, age);
}

There are two issues here:

  1. The double ? in Int?? generates a warning (Redundant '?')
  2. The section ?: null also generates a warning (Right operand of elvis operator (?:) is useless if it is null).

This PR fixes both warnings.

@@ -764,6 +768,41 @@ void paramWithDefaultValue() {
assertThat(output.toString()).isEqualTo("Your age is 10");
}

@Test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casid @edward3h, I'm unsure if this is the best way/place to test it, but let me know what you think.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I'd say!

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7ad2e12) 91.20% compared to head (dc8ef75) 91.23%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #319      +/-   ##
============================================
+ Coverage     91.20%   91.23%   +0.02%     
- Complexity     1211     1216       +5     
============================================
  Files            76       76              
  Lines          3151     3159       +8     
  Branches        492      492              
============================================
+ Hits           2874     2882       +8     
  Misses          164      164              
  Partials        113      113              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@casid casid merged commit d4f82bf into casid:main Jan 19, 2024
8 checks passed
@casid
Copy link
Owner

casid commented Jan 19, 2024

Thank you @marcospereira!

@marcospereira marcospereira deleted the kotlin/fix-nullable-types branch January 20, 2024 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants