cbarlin / cbarlin/advanced-record-utils

Clean up modifier generation in createMethod()

Open
#35 0 comments 0 reactions 0 assignees View on GitHub
refactor
Dominant language
Java
Stars
3
Forks
0
Avg merge
1m
Merged PRs (30d)
5

Description

## Background

The `createMethod()` methods in `ToBeBuilt` add `Modifier.PUBLIC` by default, as seen in the implementation that uses `MethodSpec.methodBuilder(...).addModifiers(Modifier.PUBLIC)`.

This causes several issues:
1. Many client classes need to immediately clear the modifiers and add their own, as seen in code like:
```java
final MethodSpec.Builder methodBuilder = xmlStaticClass.createMethod(...);
methodBuilder.modifiers.clear();
```

2. Other places redundantly add `Modifier.PUBLIC` even though it's already included by default.

3. In `IfaceAddBuilderEmpty` and similar classes, the modifiers are added explicitly with:
```java
.addModifiers(Modifier.STATIC, Modifier.FINAL)
```

but this doesn't clear the default `PUBLIC` modifier, making it redundantly both PUBLIC and FINAL.

## Proposed Solution

Refactor `createMethod()` to either:
1. Not add any modifiers by default, or
2. Add a parameter to control whether PUBLIC should be added or not
3. Add overload methods for common modifier patterns

This would simplify client code and avoid the need for explicit modifier clearing.

## Related Code
Found in PR #34 comment: https://github.com/cbarlin/advanced-record-utils/pull/34#discussion_r2075136441

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.