From e4064fa5e07c0649fc5041290d37860c88110cd2 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Thu, 28 Jan 2021 07:07:55 +0100 Subject: [PATCH] Implement method injection priority (higher earlier) --- src/dev/w1zzrd/asm/GraftSource.java | 8 ++++++-- src/dev/w1zzrd/asm/Inject.java | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dev/w1zzrd/asm/GraftSource.java b/src/dev/w1zzrd/asm/GraftSource.java index ab7ce12..018b25d 100644 --- a/src/dev/w1zzrd/asm/GraftSource.java +++ b/src/dev/w1zzrd/asm/GraftSource.java @@ -128,8 +128,12 @@ public final class GraftSource { return fieldAnnotations.get(node); } - public Set getInjectMethods() { - return methodAnnotations.keySet(); + public List getInjectMethods() { + return methodAnnotations + .keySet() + .stream() + .sorted(Comparator.comparingInt(a -> getInjectAnnotation(a).getEntry("priority"))) + .collect(Collectors.toList()); } public Set getInjectFields() { diff --git a/src/dev/w1zzrd/asm/Inject.java b/src/dev/w1zzrd/asm/Inject.java index c18925a..4f02f39 100644 --- a/src/dev/w1zzrd/asm/Inject.java +++ b/src/dev/w1zzrd/asm/Inject.java @@ -30,4 +30,6 @@ public @interface Inject { * @return True if the injection method should receive the return value */ boolean acceptOriginalReturn() default false; + + int priority() default Integer.MIN_VALUE; }