package com.kiselev.reflection.ui.bytecode.agent;

import com.kiselev.reflection.ui.bytecode.holder.ByteCodeHolder;

import java.lang.instrument.Instrumentation;
import java.util.List;

/**
 * Created by Vadim Kiselev on 6/12/2017.
 */
public class Agent {

    public static void agentmain(String args, Instrumentation instrumentation) {
        try {
            instrumentation.addTransformer(new Transformer(), true);
            Class[] allLoadedClasses = instrumentation.getAllLoadedClasses();
            List<String> neededClasses = ByteCodeHolder.getClassesNamesForByteCode();

            for (Class loadedClass : allLoadedClasses) {
                if (neededClasses.contains(loadedClass.getName())) {
                    instrumentation.retransformClasses(loadedClass);
                }
            }

        } catch (Exception exception) {
            // sin
        }
    }
}

@@ -48,74 +48,8 @@
 t;%0A%0A
-import com.kiselev.reflection.ui.bytecode.holder.ByteCodeHolder;%0A%0A
 impo
@@ -92,31 +92,8 @@
 ion;
-%0Aimport java.util.List;
 %0A%0A/*
@@ -407,94 +407,8 @@
 s();
-%0A            List%3CString%3E neededClasses = ByteCodeHolder.getClassesNamesForByteCode();
 %0A%0A  
@@ -486,31 +486,9 @@
 if (
-neededClasses.contains(
+!
 load
@@ -499,17 +499,16 @@
 ass.
-getName()
+isArray(
 )) %7B
@@ -609,17 +609,16 @@
       %7D%0A
-%0A
         

Revert performance's improvement