diff options
author | zaaarf <zaaarf@proton.me> | 2023-04-11 23:25:38 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-04-11 23:25:38 +0200 |
commit | a5576ac5e7e3144cebee41530a9020191d0c76f5 (patch) | |
tree | 3fada9892ab42c83b66eb263a52ac43f2800b47d /src/main/java/ftbsc/lll/processor/tools/ASTUtils.java | |
parent | 5579df7c39bc6d95d23bc357bdfa1d5b75cfbc24 (diff) |
feat: type erasure is now handled correctly
Diffstat (limited to 'src/main/java/ftbsc/lll/processor/tools/ASTUtils.java')
-rw-r--r-- | src/main/java/ftbsc/lll/processor/tools/ASTUtils.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java index 498a8f0..f8b05b5 100644 --- a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java +++ b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java @@ -12,10 +12,8 @@ import ftbsc.lll.proxies.ProxyType; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.*; import javax.lang.model.type.*; -import javax.tools.Diagnostic; import java.lang.annotation.Annotation; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -303,6 +301,36 @@ public class ASTUtils { } /** + * Tries to find the method being overloaded by the given {@link ExecutableElement}. + * In case of multiple layers of overloading, it finds the original one. In case of + * no overloading, it returns the given method. + * @param context the {@link TypeElement} representing the parent class + * @param method an {@link ExecutableElement} representing the overloading method + * @param env the {@link ProcessingEnvironment} to perform the operation in + * @return the original overloaded method, or the given method if it was not found + * @since 0.5.2 + */ + public static ExecutableElement findOverloadedMethod( + TypeElement context, ExecutableElement method, ProcessingEnvironment env) { + if (context.getSuperclass().getKind() == TypeKind.NONE) + return method; + + for (Element elem : context.getEnclosedElements()) { + if (elem.getKind() != ElementKind.METHOD) + continue; + if (env.getElementUtils().overrides(method, (ExecutableElement) elem, context)) { + method = (ExecutableElement) elem; + break; //found + } + } + + return findOverloadedMethod( + (TypeElement) env.getTypeUtils().asElement(context.getSuperclass()), + method, env + ); + } + + /** * Utility method for finding out what type of proxy a field is. * It will fail if the return type is not a known type of proxy. * @param v the annotated {@link VariableElement} |