refactor: directly expose static final String fields / remove getters#706
Merged
johnrengelman merged 1 commit intoGradleUp:masterfrom Oct 4, 2021
Merged
Conversation
Omitting the visibility modifier creates a Groovy _property_ [1], which
is composed by:
* a _private_ backing field
* a public getter
* (+ setter if the property is not `final`)
It is unlikely to be an intended design as it makes access to those
fields awkward from statically typed languages
`ShadowBasePlugin.getCONFIGURATION_NAME()`.
This commit replaces such _properties_ with _public fields_ only.
This is a backward incompatible change as this removes public getters.
Here is what the generated class looked liked before this
commit (7.0.0):
```
$ javap -p -c -constants ShadowBasePlugin.class
Compiled from "ShadowBasePlugin.groovy"
public class com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin implements org.gradle.api.Plugin<org.gradle.api.Project>, groovy.lang.GroovyObject {
private static final java.lang.String EXTENSION_NAME = "shadow";
private static final java.lang.String CONFIGURATION_NAME = "shadow";
[...]
public static java.lang.String getEXTENSION_NAME();
Code:
0: getstatic GradleUp#86 // Field EXTENSION_NAME:Ljava/lang/String;
3: areturn
public static java.lang.String getCONFIGURATION_NAME();
Code:
0: getstatic GradleUp#111 // Field CONFIGURATION_NAME:Ljava/lang/String;
3: areturn
```
[1] https://groovy-lang.org/objectorientation.html#properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Omitting the visibility modifier creates a Groovy property [1], which
is composed by:
final)It is unlikely to be an intended design as it makes access to those
fields awkward from statically typed languages
ShadowBasePlugin.getCONFIGURATION_NAME().This commit replaces such properties with public fields only.
This is a backward incompatible change as this removes public getters.
Here is what the generated class looked liked before this
commit (7.0.0):
[1] https://groovy-lang.org/objectorientation.html#properties