Skip to content

Commit

Permalink
Use full annotation class names when resolving injectors, fixes Spong…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Dec 23, 2020
1 parent e8dd923 commit 3ccc611
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ static class InjectorEntry {

final Class<? extends Annotation> annotationType;

final Class<? extends InjectionInfo> type;
final Class<? extends InjectionInfo> injectorType;

final Constructor<? extends InjectionInfo> ctor;

final String simpleName;
final String annotationDesc;

final String prefix;

InjectorEntry(Class<? extends Annotation> annotationType, Class<? extends InjectionInfo> type) throws NoSuchMethodException {
this.annotationType = annotationType;
this.type = type;
this.injectorType = type;
this.ctor = type.getDeclaredConstructor(MixinTargetContext.class, MethodNode.class, AnnotationNode.class);
this.simpleName = annotationType.getSimpleName() + ";";
this.annotationDesc = Type.getDescriptor(annotationType);

HandlerPrefix handlerPrefix = type.<HandlerPrefix>getAnnotation(HandlerPrefix.class);
this.prefix = handlerPrefix != null ? handlerPrefix.value() : InjectionInfo.DEFAULT_PREFIX;
Expand All @@ -144,9 +144,9 @@ InjectionInfo create(MixinTargetContext mixin, MethodNode method, AnnotationNode
throw (MixinException)cause;
}
Throwable ex = cause != null ? cause : itex;
throw new MixinError("Error initialising injector metaclass [" + this.type + "] for annotation " + annotation.desc, ex);
throw new MixinError("Error initialising injector metaclass [" + this.injectorType + "] for annotation " + annotation.desc, ex);
} catch (ReflectiveOperationException ex) {
throw new MixinError("Failed to instantiate injector metaclass [" + this.type + "] for annotation " + annotation.desc, ex);
throw new MixinError("Failed to instantiate injector metaclass [" + this.injectorType + "] for annotation " + annotation.desc, ex);
}
}
}
Expand Down Expand Up @@ -620,7 +620,7 @@ public static InjectionInfo parse(MixinTargetContext mixin, MethodNode method) {
}

for (InjectorEntry injector : InjectionInfo.registry.values()) {
if (annotation.desc.endsWith(injector.simpleName)) {
if (annotation.desc.equals(injector.annotationDesc)) {
return injector.create(mixin, method, annotation);
}
}
Expand Down Expand Up @@ -660,7 +660,7 @@ public static String getInjectorPrefix(AnnotationNode annotation) {
}

for (InjectorEntry injector : InjectionInfo.registry.values()) {
if (annotation.desc.endsWith(injector.simpleName)) {
if (annotation.desc.endsWith(injector.annotationDesc)) {
return injector.prefix;
}
}
Expand Down Expand Up @@ -713,16 +713,16 @@ public static void register(Class<? extends InjectionInfo> type) {
} catch (NoSuchMethodException ex) {
throw new MixinError("InjectionInfo class " + type.getName() + " is missing a valid constructor");
}
InjectorEntry existing = InjectionInfo.registry.get(entry.simpleName);
InjectorEntry existing = InjectionInfo.registry.get(entry.annotationDesc);
if (existing != null) { // && !existing.type.equals(type)) {
MessageRouter.getMessager().printMessage(Kind.WARNING, String.format("Overriding InjectionInfo for @%s with %s (previously %s)",
annotationType.value().getSimpleName(), type.getName(), existing.type.getName()));
annotationType.value().getSimpleName(), type.getName(), existing.injectorType.getName()));
} else {
MessageRouter.getMessager().printMessage(Kind.OTHER, String.format("Registering new injector for @%s with %s",
annotationType.value().getSimpleName(), type.getName()));
}

InjectionInfo.registry.put(entry.simpleName, entry);
InjectionInfo.registry.put(entry.annotationDesc, entry);

ArrayList<Class<? extends Annotation>> annotations = new ArrayList<Class<? extends Annotation>>();
for (InjectorEntry injector : InjectionInfo.registry.values()) {
Expand Down

0 comments on commit 3ccc611

Please sign in to comment.