Skip to content

Create a renderer to make final fields#140

Merged
eed3si9n merged 3 commits intosbt:masterfrom
magneticflux-:feature/fix#127-add-final-modifier
Oct 1, 2018
Merged

Create a renderer to make final fields#140
eed3si9n merged 3 commits intosbt:masterfrom
magneticflux-:feature/fix#127-add-final-modifier

Conversation

@magneticflux-
Copy link
Copy Markdown
Contributor

Copied ScalaCaseObjectRenderer.scala to ScalaFinalCaseObjectRenderer.scala and made each line have the "final" modifier so they can be used in annotations.

Closes #127

…scala and made each line have the "final" modifier so they can be used in annotations
@@ -0,0 +1,88 @@
package sbtbuildinfo

private[sbtbuildinfo] case class ScalaFinalCaseObjectRenderer(options: Seq[BuildInfoOption], pkg: String, obj: String) extends ScalaRenderer {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add scripted test to see if this can be used? I don't know if you can with package private.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Whoops, you're right!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this look good?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome. Thanks!

@eed3si9n eed3si9n merged commit 1acf504 into sbt:master Oct 1, 2018
@magneticflux- magneticflux- changed the title Created a renderer that make final fields Create a renderer to make final fields Jan 15, 2019
@magneticflux- magneticflux- deleted the feature/fix#127-add-final-modifier branch January 15, 2019 22:40
eed3si9n added a commit that referenced this pull request Aug 8, 2020
This is a rework of #140

Looking closely it doesn't look like `ScalaFinalCaseObjectRenderer` added in #140 is actually going to be useful since it just added `final` in front of all vals.

This provides fix for #127 by generating [constant value definition](https://www.scala-lang.org/files/archive/spec/2.12/04-basic-declarations-and-definitions.html#value-declarations-and-definitions) for `Int`, `Long`, `Double`, `Boolean`, `Symbol`, and `String`.

This allows the values to be used in annotation as the scripted test show. Note due to constant folding using this is not recommended for libraries.
eed3si9n added a commit that referenced this pull request Aug 9, 2020
This is a rework of #140

Looking closely it doesn't look like `ScalaFinalCaseObjectRenderer` added in #140 is actually going to be useful since it just added `final` in front of all vals.

This provides fix for #127 by generating [constant value definition](https://www.scala-lang.org/files/archive/spec/2.12/04-basic-declarations-and-definitions.html#value-declarations-and-definitions) for `Int`, `Long`, `Double`, `Boolean`, `Symbol`, and `String`.

This allows the values to be used in annotation as the scripted test show. Note due to constant folding using this is not recommended for libraries.
@eed3si9n
Copy link
Copy Markdown
Member

eed3si9n commented Aug 9, 2020

FYI upon closer inspection of this PR, I don't think simply adding final in front of the val is not going to work. I've gutted out the imple but provided a replacement in #164

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.

Compile properties as constants

2 participants