/*
 * 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 io.michaelrocks.lightsaber.processor.injection;

import io.michaelrocks.lightsaber.processor.ProcessorContext;
import io.michaelrocks.lightsaber.processor.descriptors.InjectionTargetDescriptor;
import io.michaelrocks.lightsaber.processor.descriptors.MethodDescriptor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;

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

public class ProvidableTargetPatcher extends BaseInjectionClassVisitor {
    private final InjectionTargetDescriptor providableTarget;

    public ProvidableTargetPatcher(final ProcessorContext processorContext, final ClassVisitor classVisitor,
            final InjectionTargetDescriptor providableTarget) {
        super(processorContext, classVisitor);
        this.providableTarget = providableTarget;
    }

    @Override
    public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
            final String[] exceptions) {
        final MethodDescriptor methodDescriptor = new MethodDescriptor(name, desc);
        if (providableTarget.isInjectableConstructor(methodDescriptor)) {
            final int newAccess = access & ~ACC_PRIVATE;
            if (newAccess != access) {
                setDirty(true);
            }
            return super.visitMethod(newAccess, name, desc, signature, exceptions);
        } else {
            return super.visitMethod(access, name, desc, signature, exceptions);
        }
    }
}

@@ -994,27 +994,17 @@
 Opcodes.
-ACC_PRIVATE
+*
 ;%0A%0Apubli
@@ -1354,16 +1354,16 @@
 sitor);%0A
-
         
@@ -1411,16 +1411,441 @@
 %0A    %7D%0A%0A
+    @Override%0A    public void visit(final int version, final int access, final String name, final String signature,%0A            final String superName, final String%5B%5D interfaces) %7B%0A        final int newAccess = (access & ~(ACC_PRIVATE %7C ACC_PROTECTED)) %7C ACC_PUBLIC;%0A        super.visit(version, access, name, signature, superName, interfaces);%0A        if (newAccess != access) %7B%0A            setDirty(true);%0A        %7D%0A    %7D%0A%0A
     @Ove

Patch providable targets to make them public