Commit d28d5dde9ba936d287308d59c4505219dae270a8
1 parent
9959697d
move generateDescriptor methods to ByteCodeUtilities
Showing
3 changed files
with
73 additions
and
75 deletions
java/common/com/mumfrey/liteloader/transformers/ByteCodeUtilities.java
| ... | ... | @@ -677,4 +677,74 @@ public abstract class ByteCodeUtilities |
| 677 | 677 | } |
| 678 | 678 | return null; |
| 679 | 679 | } |
| 680 | + | |
| 681 | + /** | |
| 682 | + * @param returnType | |
| 683 | + * @param args | |
| 684 | + */ | |
| 685 | + public static String generateDescriptor(Type returnType, Object... args) | |
| 686 | + { | |
| 687 | + return ByteCodeUtilities.generateDescriptor(Obf.MCP, returnType, args); | |
| 688 | + } | |
| 689 | + | |
| 690 | + /** | |
| 691 | + * @param returnType | |
| 692 | + * @param args | |
| 693 | + */ | |
| 694 | + public static String generateDescriptor(Obf returnType, Object... args) | |
| 695 | + { | |
| 696 | + return ByteCodeUtilities.generateDescriptor(Obf.MCP, returnType, args); | |
| 697 | + } | |
| 698 | + | |
| 699 | + /** | |
| 700 | + * @param returnType | |
| 701 | + * @param args | |
| 702 | + */ | |
| 703 | + public static String generateDescriptor(String returnType, Object... args) | |
| 704 | + { | |
| 705 | + return ByteCodeUtilities.generateDescriptor(Obf.MCP, returnType, args); | |
| 706 | + } | |
| 707 | + | |
| 708 | + /** | |
| 709 | + * @param obfType | |
| 710 | + * @param returnType | |
| 711 | + * @param args | |
| 712 | + */ | |
| 713 | + public static String generateDescriptor(int obfType, Object returnType, Object... args) | |
| 714 | + { | |
| 715 | + StringBuilder sb = new StringBuilder().append('(');; | |
| 716 | + | |
| 717 | + for (Object arg : args) | |
| 718 | + { | |
| 719 | + sb.append(ByteCodeUtilities.toDescriptor(obfType, arg)); | |
| 720 | + } | |
| 721 | + | |
| 722 | + return sb.append(')').append(returnType != null ? ByteCodeUtilities.toDescriptor(obfType, returnType) : "V").toString(); | |
| 723 | + } | |
| 724 | + | |
| 725 | + /** | |
| 726 | + * @param obfType | |
| 727 | + * @param arg | |
| 728 | + */ | |
| 729 | + private static String toDescriptor(int obfType, Object arg) | |
| 730 | + { | |
| 731 | + if (arg instanceof Obf) | |
| 732 | + { | |
| 733 | + return ((Obf)arg).getDescriptor(obfType); | |
| 734 | + } | |
| 735 | + else if (arg instanceof String) | |
| 736 | + { | |
| 737 | + return (String)arg; | |
| 738 | + } | |
| 739 | + else if (arg instanceof Type) | |
| 740 | + { | |
| 741 | + return arg.toString(); | |
| 742 | + } | |
| 743 | + else if (arg instanceof Class) | |
| 744 | + { | |
| 745 | + return Type.getDescriptor((Class<?>)arg).toString(); | |
| 746 | + } | |
| 747 | + | |
| 748 | + return arg == null ? "" : arg.toString(); | |
| 749 | + } | |
| 680 | 750 | } | ... | ... |
java/common/com/mumfrey/liteloader/transformers/Callback.java
| ... | ... | @@ -3,8 +3,6 @@ package com.mumfrey.liteloader.transformers; |
| 3 | 3 | import java.util.ArrayList; |
| 4 | 4 | import java.util.List; |
| 5 | 5 | |
| 6 | -import org.objectweb.asm.Type; | |
| 7 | - | |
| 8 | 6 | import com.mumfrey.liteloader.core.runtime.Obf; |
| 9 | 7 | |
| 10 | 8 | /** |
| ... | ... | @@ -273,74 +271,4 @@ public class Callback |
| 273 | 271 | { |
| 274 | 272 | return super.hashCode(); |
| 275 | 273 | } |
| 276 | - | |
| 277 | - /** | |
| 278 | - * @param returnType | |
| 279 | - * @param args | |
| 280 | - */ | |
| 281 | - public static String generateDescriptor(Type returnType, Object... args) | |
| 282 | - { | |
| 283 | - return Callback.generateDescriptor(Obf.MCP, returnType, args); | |
| 284 | - } | |
| 285 | - | |
| 286 | - /** | |
| 287 | - * @param returnType | |
| 288 | - * @param args | |
| 289 | - */ | |
| 290 | - public static String generateDescriptor(Obf returnType, Object... args) | |
| 291 | - { | |
| 292 | - return Callback.generateDescriptor(Obf.MCP, returnType, args); | |
| 293 | - } | |
| 294 | - | |
| 295 | - /** | |
| 296 | - * @param returnType | |
| 297 | - * @param args | |
| 298 | - */ | |
| 299 | - public static String generateDescriptor(String returnType, Object... args) | |
| 300 | - { | |
| 301 | - return Callback.generateDescriptor(Obf.MCP, returnType, args); | |
| 302 | - } | |
| 303 | - | |
| 304 | - /** | |
| 305 | - * @param obfType | |
| 306 | - * @param returnType | |
| 307 | - * @param args | |
| 308 | - */ | |
| 309 | - public static String generateDescriptor(int obfType, Object returnType, Object... args) | |
| 310 | - { | |
| 311 | - StringBuilder sb = new StringBuilder().append('(');; | |
| 312 | - | |
| 313 | - for (Object arg : args) | |
| 314 | - { | |
| 315 | - sb.append(Callback.toDescriptor(obfType, arg)); | |
| 316 | - } | |
| 317 | - | |
| 318 | - return sb.append(')').append(returnType != null ? Callback.toDescriptor(obfType, returnType) : "V").toString(); | |
| 319 | - } | |
| 320 | - | |
| 321 | - /** | |
| 322 | - * @param obfType | |
| 323 | - * @param arg | |
| 324 | - */ | |
| 325 | - private static String toDescriptor(int obfType, Object arg) | |
| 326 | - { | |
| 327 | - if (arg instanceof Obf) | |
| 328 | - { | |
| 329 | - return ((Obf)arg).getDescriptor(obfType); | |
| 330 | - } | |
| 331 | - else if (arg instanceof String) | |
| 332 | - { | |
| 333 | - return (String)arg; | |
| 334 | - } | |
| 335 | - else if (arg instanceof Type) | |
| 336 | - { | |
| 337 | - return arg.toString(); | |
| 338 | - } | |
| 339 | - else if (arg instanceof Class) | |
| 340 | - { | |
| 341 | - return Type.getDescriptor((Class<?>)arg).toString(); | |
| 342 | - } | |
| 343 | - | |
| 344 | - return arg == null ? "" : arg.toString(); | |
| 345 | - } | |
| 346 | 274 | } |
| 347 | 275 | \ No newline at end of file | ... | ... |
java/common/com/mumfrey/liteloader/transformers/event/MethodInfo.java
| ... | ... | @@ -3,7 +3,7 @@ package com.mumfrey.liteloader.transformers.event; |
| 3 | 3 | import joptsimple.internal.Strings; |
| 4 | 4 | |
| 5 | 5 | import com.mumfrey.liteloader.core.runtime.Obf; |
| 6 | -import com.mumfrey.liteloader.transformers.Callback; | |
| 6 | +import com.mumfrey.liteloader.transformers.ByteCodeUtilities; | |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Encapsulates a method descriptor with varying degrees of accuracy from a simpler owner/method mapping up to |
| ... | ... | @@ -139,7 +139,7 @@ public class MethodInfo |
| 139 | 139 | */ |
| 140 | 140 | public MethodInfo(Obf owner, String method, Object returnType, Object... args) |
| 141 | 141 | { |
| 142 | - this(owner.name, owner.obf, method, method, method, Callback.generateDescriptor(Obf.MCP, returnType, args), Callback.generateDescriptor(Obf.OBF, returnType, args)); | |
| 142 | + this(owner.name, owner.obf, method, method, method, ByteCodeUtilities.generateDescriptor(Obf.MCP, returnType, args), ByteCodeUtilities.generateDescriptor(Obf.OBF, returnType, args)); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| ... | ... | @@ -158,7 +158,7 @@ public class MethodInfo |
| 158 | 158 | */ |
| 159 | 159 | public MethodInfo(Obf owner, Obf method, Object returnType, Object... args) |
| 160 | 160 | { |
| 161 | - this(owner.name, owner.obf, method.name, method.srg, method.obf, Callback.generateDescriptor(Obf.MCP, returnType, args), Callback.generateDescriptor(Obf.OBF, returnType, args)); | |
| 161 | + this(owner.name, owner.obf, method.name, method.srg, method.obf, ByteCodeUtilities.generateDescriptor(Obf.MCP, returnType, args), ByteCodeUtilities.generateDescriptor(Obf.OBF, returnType, args)); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** | ... | ... |