-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dd1120
commit 159ba64
Showing
39 changed files
with
845 additions
and
197 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
44 changes: 44 additions & 0 deletions
44
src/main/java/io/papermc/asm/rules/rename/EnumRenameBuilder.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.papermc.asm.rules.rename; | ||
|
||
import java.lang.constant.ClassDesc; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
import static io.papermc.asm.util.DescriptorUtils.desc; | ||
|
||
public final class EnumRenameBuilder { | ||
|
||
private final ClassDesc enumTypeDesc; | ||
private @Nullable ClassDesc optionalEnumReplacementImpl; | ||
private final Map<String, String> enumFieldRenames = new HashMap<>(); | ||
|
||
EnumRenameBuilder(final ClassDesc enumTypeDesc) { | ||
this.enumTypeDesc = enumTypeDesc; | ||
} | ||
|
||
public EnumRenameBuilder enumReplacementImpl(final Class<?> type) { | ||
return this.enumReplacementImpl(desc(type)); | ||
} | ||
|
||
public EnumRenameBuilder enumReplacementImpl(final ClassDesc type) { | ||
if (this.enumTypeDesc.equals(type)) { | ||
throw new IllegalArgumentException("Cannot replace an enum with itself"); | ||
} | ||
this.optionalEnumReplacementImpl = type; | ||
return this; | ||
} | ||
|
||
public EnumRenameBuilder rename(final String legacyName, final String newName) { | ||
this.enumFieldRenames.put(legacyName, newName); | ||
return this; | ||
} | ||
|
||
void apply(final RenameRuleBuilder renameRuleBuilder) { | ||
this.enumFieldRenames.forEach((legacyName, newName) -> { | ||
renameRuleBuilder.fieldByDesc(this.enumTypeDesc, legacyName, newName); | ||
}); | ||
final Map<String, String> copy = Map.copyOf(this.enumFieldRenames); | ||
renameRuleBuilder.enumValueOfFieldRenames.put(this.enumTypeDesc, new EnumRenamer(this.enumTypeDesc, this.optionalEnumReplacementImpl, copy)); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.papermc.asm.rules.rename; | ||
|
||
import java.lang.constant.ClassDesc; | ||
import java.util.Map; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public record EnumRenamer(ClassDesc typeDesc, @Nullable ClassDesc optionalReplacementImpl, Map<String, String> fieldRenames) { | ||
} |
Oops, something went wrong.