Search in sources :

Example 21 with Annotation

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);
            }
        }
    }
}
Also used : GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.Field) PutField(net.runelite.asm.attributes.code.instructions.PutField) ClassFile(net.runelite.asm.ClassFile) IOException(java.io.IOException) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Aggregations

Annotation (net.runelite.asm.attributes.annotation.Annotation)21 ClassFile (net.runelite.asm.ClassFile)10 Method (net.runelite.asm.Method)8 Annotations (net.runelite.asm.attributes.Annotations)8 Field (net.runelite.asm.Field)7 Element (net.runelite.asm.attributes.annotation.Element)6 Signature (net.runelite.asm.signature.Signature)6 DeobAnnotations (net.runelite.deob.DeobAnnotations)6 IOException (java.io.IOException)5 Type (net.runelite.asm.Type)5 List (java.util.List)4 GetField (net.runelite.asm.attributes.code.instructions.GetField)4 PutField (net.runelite.asm.attributes.code.instructions.PutField)4 ArrayList (java.util.ArrayList)3 ClassGroup (net.runelite.asm.ClassGroup)3 Instruction (net.runelite.asm.attributes.code.Instruction)3 Class (net.runelite.asm.pool.Class)3 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2