mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-13 01:39:22 +01:00
feat: throw exception if bridge is not found correctly
This commit is contained in:
parent
524818a378
commit
abd9954ed3
2 changed files with 26 additions and 1 deletions
|
@ -330,6 +330,31 @@ public class ASTUtils {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find the "synthetic bridge" generated by the compiler for a certain overridden
|
||||
* method. A "bridge" only exists in cases where type erasure is involved (i.e. when the
|
||||
* method being overridden uses a generic parameter that is not preserved in the overriding
|
||||
* method).
|
||||
* @param context the {@link TypeElement} representing the parent class
|
||||
* @param method an {@link ExecutableElement} stub representing the overloading method
|
||||
* @param env the {@link ProcessingEnvironment} to perform the operation in
|
||||
* @return the "bridge"
|
||||
* @throws TargetNotFoundException if the method in question was not overriding anything, or
|
||||
* if the method it was overriding does not require a bridge
|
||||
* @since 0.5.2
|
||||
*/
|
||||
public static ExecutableElement findSyntheticBridge(
|
||||
TypeElement context, ExecutableElement method, ProcessingEnvironment env) throws TargetNotFoundException {
|
||||
ExecutableElement overridding = findOverloadedMethod(context, method, env);
|
||||
if(descriptorFromExecutableElement(overridding, env).equals(descriptorFromExecutableElement(method, env)))
|
||||
throw new TargetNotFoundException(
|
||||
"bridge method for",
|
||||
overridding.getSimpleName().toString(),
|
||||
context.getQualifiedName().toString()
|
||||
);
|
||||
else return overridding;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
@ -78,7 +78,7 @@ public class MethodContainer {
|
|||
ExecutableElement tmp = (ExecutableElement) findMember(
|
||||
parent, name, descriptor, descriptor != null && strict,false, env
|
||||
);
|
||||
this.elem = bridge ? findOverloadedMethod((TypeElement) this.parent.elem, tmp, env) : tmp;
|
||||
this.elem = bridge ? findSyntheticBridge((TypeElement) this.parent.elem, tmp, env) : tmp;
|
||||
this.name = this.elem.getSimpleName().toString();
|
||||
this.descriptor = descriptorFromExecutableElement(this.elem, env);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue