mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-12-23 02:54:52 +01:00
fix: fixed MirroredTypeException
This commit is contained in:
parent
0cd50cc179
commit
19b739943f
2 changed files with 13 additions and 10 deletions
|
@ -29,6 +29,7 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import static ftbsc.lll.processor.tools.ASTUtils.*;
|
||||
import static ftbsc.lll.processor.tools.ASTUtils.getClassFullyQualifiedName;
|
||||
|
||||
/**
|
||||
* The actual annotation processor behind the magic.
|
||||
|
@ -175,8 +176,8 @@ public class LilleroProcessor extends AbstractProcessor {
|
|||
private static String findClassName(Patch patchAnn, FindMethod methodAnn, ObfuscationMapper mapper) {
|
||||
String fullyQualifiedName =
|
||||
methodAnn == null || methodAnn.parent() == Object.class
|
||||
? getClassFullyQualifiedName(patchAnn.value())
|
||||
: getClassFullyQualifiedName(methodAnn.parent());
|
||||
? getClassFullyQualifiedName(patchAnn, p -> patchAnn.value())
|
||||
: getClassFullyQualifiedName(methodAnn, m -> methodAnn.parent());
|
||||
return findClassName(fullyQualifiedName, mapper);
|
||||
}
|
||||
|
||||
|
@ -322,11 +323,11 @@ public class LilleroProcessor extends AbstractProcessor {
|
|||
private VariableElement findField(ExecutableElement stub, ObfuscationMapper mapper) {
|
||||
Patch patchAnn = stub.getEnclosingElement().getAnnotation(Patch.class);
|
||||
FindField fieldAnn = stub.getAnnotation(FindField.class);
|
||||
String parentName = findClassName(getClassFullyQualifiedName(
|
||||
fieldAnn.parent().equals(Object.class)
|
||||
? patchAnn.value()
|
||||
: fieldAnn.parent()
|
||||
), mapper);
|
||||
String parentName;
|
||||
if(fieldAnn.parent().equals(Object.class))
|
||||
parentName = getClassFullyQualifiedName(patchAnn, p -> patchAnn.value());
|
||||
else parentName = getClassFullyQualifiedName(fieldAnn, f -> fieldAnn.parent());
|
||||
parentName = findClassName(parentName, mapper);
|
||||
String name = fieldAnn.name().equals("")
|
||||
? stub.getSimpleName().toString()
|
||||
: fieldAnn.name();
|
||||
|
|
|
@ -13,6 +13,7 @@ import javax.lang.model.type.MirroredTypeException;
|
|||
import javax.lang.model.type.TypeMirror;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -137,13 +138,14 @@ public class ASTUtils {
|
|||
* Safely converts a {@link Class} to its fully qualified name. See
|
||||
* <a href="https://area-51.blog/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor">this blogpost</a>
|
||||
* for more information.
|
||||
* @param clazz the class to get the name for
|
||||
* @param ann the annotation containing the class
|
||||
* @param fun the annotation function returning the class
|
||||
* @return the fully qualified name of the given class
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public static String getClassFullyQualifiedName(Class<?> clazz) {
|
||||
public static <T extends Annotation> String getClassFullyQualifiedName(T ann, Function<Annotation, Class<?>> fun) {
|
||||
try {
|
||||
return clazz.getCanonicalName();
|
||||
return fun.apply(ann).getCanonicalName();
|
||||
} catch(MirroredTypeException e) {
|
||||
return e.getTypeMirror().toString();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue