Skip to content

Commit 481504c

Browse files
committed
fix tests by accounting for NONE access change
1 parent 8f952a4 commit 481504c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/java/io/papermc/restamp/at/ModifierTransformationProgress.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void recordFoundVisibilitySpot() {
182182
*/
183183
@NotNull
184184
public Result finaliseProgress(
185-
@NotNull final Supplier<J.Modifier> visibilityModifierCreator,
185+
@Nullable final Supplier<J.Modifier> visibilityModifierCreator,
186186
@NotNull Space parentSpace
187187
) {
188188
// If we neither found the visibility nor found ones to remove, pretend we found a valid spot at index 0.
@@ -206,7 +206,7 @@ public Result finaliseProgress(
206206
}
207207

208208
// Insert if the spot is still useful, the visibility was not found.
209-
if (this.validVisibilitySpot.useful) {
209+
if (this.validVisibilitySpot.useful && visibilityModifierCreator != null) {
210210
this.modifiers.add(this.validVisibilitySpot.index, visibilityModifierCreator.get());
211211
this.mutatedFromOriginal = true;
212212
}

src/main/java/io/papermc/restamp/at/ModifierTransformer.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public ModifierTransformationResult transformModifiers(@NotNull final AccessTran
7878
continue;
7979
}
8080

81+
// Do not touch access modifiers if no change was requested.
82+
if (accessTransform.getAccess() == AccessChange.NONE) continue;
83+
8184
// Drop unwanted visibility modifiers and record potential position for new modifier.
8285
if (modifier.getType() != accessTypeToKeep) {
8386
transformationProgress.dropModifier(modifier);
@@ -90,8 +93,9 @@ public ModifierTransformationResult transformModifiers(@NotNull final AccessTran
9093
}
9194

9295
// Finalise the progress tracker
96+
// Only pass a modifier creator if we are requesting access change in the first place
9397
final ModifierTransformationProgress.Result result = transformationProgress.finaliseProgress(
94-
() -> new J.Modifier(
98+
accessTransform.getAccess() == AccessChange.NONE ? null : () -> new J.Modifier(
9599
Tree.randomId(), Space.EMPTY, Markers.EMPTY, null,
96100
Objects.requireNonNull(accessTypeToKeep, "package private caused insertion"), Collections.emptyList()
97101
),

0 commit comments

Comments
 (0)