use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.
the class MixinInjector method injectFields.
/**
* Finds fields that are marked @Inject and inject them into the target
*
* @param mixinClasses
* @throws InjectionException
*/
private void injectFields(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
// Inject fields, and put them in injectedFields if they can be used by other mixins
for (Class<?> mixinClass : mixinClasses.keySet()) {
ClassFile mixinCf;
try {
mixinCf = loadClass(mixinClass);
} catch (IOException ex) {
throw new InjectionException(ex);
}
List<ClassFile> targetCfs = mixinClasses.get(mixinClass);
for (ClassFile cf : targetCfs) {
for (Field field : mixinCf.getFields()) {
// Always inject $assertionsEnabled if its missing.
if (ASSERTION_FIELD.equals(field.getName())) {
if (cf.findField(ASSERTION_FIELD, Type.BOOLEAN) != null) {
continue;
}
} else {
Annotation inject = field.getAnnotations().find(INJECT);
if (inject == null) {
continue;
}
}
Field copy = new Field(cf, field.getName(), field.getType());
copy.setAccessFlags(field.getAccessFlags());
copy.setPublic();
copy.setValue(field.getValue());
cf.addField(copy);
if (injectedFields.containsKey(field.getName())) {
throw new InjectionException("Injected field names must be globally unique");
}
injectedFields.put(field.getName(), copy);
}
}
}
}
Aggregations