/*
 * Copyright 2015 Michael Rozumyanskiy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.michaelrocks.lightsaber.processor.injection;

import com.michaelrocks.lightsaber.Module;
import com.michaelrocks.lightsaber.processor.ProcessorContext;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Type;

import java.util.Arrays;

import static org.objectweb.asm.Opcodes.ASM5;

public class RootVisitor extends ClassVisitor {
    private final ProcessorContext processorContext;

    public RootVisitor(final ClassVisitor classVisitor, final ProcessorContext processorContext) {
        super(ASM5, classVisitor);
        this.processorContext = processorContext;
    }

    @Override
    public void visit(final int version, final int access, final String name, final String signature,
            final String superName, final String[] interfaces) {
        if (interfaces != null && Arrays.asList(interfaces).indexOf(Type.getInternalName(Module.class)) >= 0) {
            // FIXME: This code must be removed when the injection package gets refactored.
            if (!processorContext.getGlobalModule().getModuleType().getInternalName().equals(name)) {
                cv = new ModuleVisitor(cv);
            }
        } else {
            // FIXME: This code must be removed when the injection package gets refactored.
            if (!processorContext.getInjectorFactoryType().getInternalName().equals(name)) {
                cv = new InjectionVisitor(cv);
            }
        }

        super.visit(version, access, name, signature, superName, interfaces);
    }
}

@@ -699,16 +699,84 @@
 Module;%0A
+import com.michaelrocks.lightsaber.processor.ProcessorClassVisitor;%0A
 import c
@@ -830,16 +830,16 @@
 ontext;%0A
-
 import o
@@ -931,156 +931,64 @@
 s;%0A%0A
-import static org.objectweb.asm.Opcodes.ASM5;%0A%0Apublic class RootVisitor extends ClassVisitor %7B%0A    private final ProcessorContext processorContext;%0A
+public class RootVisitor extends ProcessorClassVisitor %7B
 %0A   
@@ -1101,61 +1101,8 @@
 per(
-ASM5, classVisitor);%0A        this.processorContext = 
 proc
@@ -1113,16 +1113,31 @@
 rContext
+, classVisitor)
 ;%0A    %7D%0A
@@ -1531,33 +1531,36 @@
            if (!
-p
+getP
 rocessorContext.
@@ -1554,24 +1554,26 @@
 essorContext
+()
 .getGlobalMo
@@ -1813,17 +1813,20 @@
    if (!
-p
+getP
 rocessor
@@ -1832,16 +1832,18 @@
 rContext
+()
 .getInje

Make RootVisitor a subclass of ProcessorClassVisitor