-
Notifications
You must be signed in to change notification settings - Fork 80
- B PackageSettings only needs to support private ctor if the members are all static #748
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
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideRefines PackageLevelSettings instantiation so that package-level settings classes with only static fields do not require an accessible constructor, and adds tests to cover both instance and static-only PackageSettings scenarios including private constructors. Sequence diagram for retrieving package settings with static-only PackageSettingssequenceDiagram
actor Test
participant PackageLevelSettings
participant Reflection as Class_And_Field_Reflection
Test->>PackageLevelSettings: getSettingsFor(packageName, visitedPackages)
PackageLevelSettings->>Reflection: loadClass(packageName.PackageSettings)
Reflection-->>PackageLevelSettings: Class clazz
PackageLevelSettings->>Reflection: clazz.getDeclaredFields()
Reflection-->>PackageLevelSettings: Field[] fields
loop for each field
PackageLevelSettings->>PackageLevelSettings: check Modifier.isStatic(field.modifiers)
alt static field
PackageLevelSettings->>PackageLevelSettings: getFieldValue(field, null)
else instance field
opt first instance field
PackageLevelSettings->>PackageLevelSettings: createInstance(clazz)
end
PackageLevelSettings->>PackageLevelSettings: getFieldValue(field, instance)
end
end
PackageLevelSettings-->>Test: Map settings
Class diagram for PackageLevelSettings and PackageSettings test fixturesclassDiagram
class PackageLevelSettings {
-PackageLevelSettings()
static Map~String, Settings~ getSettingsFor(String packageName, HashSet~String~ visitedPackages)
static Object createInstance(Class clazz)
static Object getFieldValue(Field field, Object instance)
}
class PackageSettings_instance {
-PackageSettings_instance()
Object instanceField
static Object staticField
}
class PackageSettings_static {
-PackageSettings_static()
static Object staticField
}
PackageLevelSettings ..> PackageSettings_instance : uses via reflection
PackageLevelSettings ..> PackageSettings_static : uses via reflection
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to override accessibility of the ctor.
Fixes #370
Summary by Sourcery
Support package-level settings classes that only expose static members and may have private constructors, by lazily instantiating settings classes only when non-static fields are accessed.
New Features:
Bug Fixes:
Tests: