diff options
Diffstat (limited to 'src/main/java/ftbsc/lll/processor/containers')
-rw-r--r-- | src/main/java/ftbsc/lll/processor/containers/ClassContainer.java | 8 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/processor/containers/MethodContainer.java | 23 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/main/java/ftbsc/lll/processor/containers/ClassContainer.java b/src/main/java/ftbsc/lll/processor/containers/ClassContainer.java index f19c0c4..047bc47 100644 --- a/src/main/java/ftbsc/lll/processor/containers/ClassContainer.java +++ b/src/main/java/ftbsc/lll/processor/containers/ClassContainer.java @@ -6,7 +6,6 @@ import ftbsc.lll.processor.annotations.Find; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.ProcessorOptions; -import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; import java.lang.annotation.Annotation; @@ -26,11 +25,11 @@ public class ClassContainer { public final ClassData data; /** - * The {@link Element} corresponding to the class. + * The {@link TypeElement} corresponding to the class. * May only be null intentionally i.e. when the associated element is * an anonymous class or a child of an anonymous class. */ - public final Element elem; + public final TypeElement elem; /** * Private constructor, called from {@link #from(Annotation, Function, String, ProcessorOptions)}. @@ -40,7 +39,7 @@ public class ClassContainer { */ private ClassContainer(String fqn, String[] innerNames, ProcessorOptions options) { //find and validate - Element elem = options.env.getElementUtils().getTypeElement(fqn); + TypeElement elem = options.env.getElementUtils().getTypeElement(fqn); if(elem == null) throw new TargetNotFoundException("class", fqn); @@ -71,6 +70,7 @@ public class ClassContainer { .getEnclosedElements() .stream() .filter(e -> e instanceof TypeElement) + .map(e -> (TypeElement) e) .filter(e -> e.getSimpleName().contentEquals(inner)) .findFirst() .orElse(null); diff --git a/src/main/java/ftbsc/lll/processor/containers/MethodContainer.java b/src/main/java/ftbsc/lll/processor/containers/MethodContainer.java index 78c5a5a..e8b0892 100644 --- a/src/main/java/ftbsc/lll/processor/containers/MethodContainer.java +++ b/src/main/java/ftbsc/lll/processor/containers/MethodContainer.java @@ -2,6 +2,7 @@ package ftbsc.lll.processor.containers; import ftbsc.lll.exceptions.AmbiguousDefinitionException; import ftbsc.lll.exceptions.TargetNotFoundException; +import ftbsc.lll.mapper.data.ClassData; import ftbsc.lll.mapper.utils.MappingUtils; import ftbsc.lll.mapper.data.MethodData; import ftbsc.lll.processor.annotations.Find; @@ -56,7 +57,7 @@ public class MethodContainer { */ private MethodContainer(ClassContainer parent, String name, String descriptor, boolean strict, boolean bridge, ProcessorOptions options) { this.parent = parent; - if(parent.elem == null) { //unverified + if(parent.elem == null) { // unverified if(descriptor == null) throw new AmbiguousDefinitionException("Cannot use name-based lookups for methods of unverifiable classes!"); this.elem = null; @@ -68,7 +69,25 @@ public class MethodContainer { name = this.elem.getSimpleName().toString(); descriptor = descriptorFromExecutableElement(this.elem, options.env); } - this.data = getMethodData(parent.data.name, name, descriptor, options.mapper); + + // some mapping formats omit methods if they are overriding a parent's method + // since there is no drawback but efficiency, let's use the top parent's name for that (when possible) + String mappedName = null; + if(this.parent.elem != null) { + ExecutableElement top = findOverloadedMethod(this.parent.elem, this.elem, options.env); + ClassData topParentData = getClassData( + internalNameFromType(top.getEnclosingElement().asType(), options.env), + options.mapper + ); + MethodData topData = getMethodData(topParentData.name, name, descriptor, options.mapper); + this.data = new MethodData( + parent.data, + topData.signature.name, + topData.signature.descriptor, + topData.nameMapped + ); + } else this.data = getMethodData(parent.data.name, name, descriptor, options.mapper); + this.descriptorObf = options.mapper == null ? this.data.signature.descriptor : MappingUtils.mapMethodDescriptor(this.data.signature.descriptor, options.mapper, false); } |