/*
 * 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.generation;

import io.michaelrocks.lightsaber.processor.ProcessingException;
import io.michaelrocks.lightsaber.processor.ProcessorContext;
import io.michaelrocks.lightsaber.processor.io.ClassFileVisitor;

import java.io.IOException;

public class ProcessorClassProducer implements ClassProducer {
    private final ClassFileVisitor classFileVisitor;
    private final ProcessorContext processorContext;

    public ProcessorClassProducer(final ClassFileVisitor classFileVisitor, final ProcessorContext processorContext) {
        this.classFileVisitor = classFileVisitor;
        this.processorContext = processorContext;
    }

    @Override
    public void produceClass(final String internalName, final byte[] classData) {
        final String classFileName = internalName + ".class";
        try {
            classFileVisitor.visitClassFile(classFileName, classData);
        } catch (final IOException exception) {
            final String message = String.format("Failed to produce class with %d bytes", classData.length);
            processorContext.reportError(new ProcessingException(message, exception, classFileName));
        }
    }
}

/*
 * 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.generation;

import io.michaelrocks.lightsaber.processor.ProcessingException;
import io.michaelrocks.lightsaber.processor.ProcessorContext;
import io.michaelrocks.lightsaber.processor.io.ClassFileVisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class ProcessorClassProducer implements ClassProducer {
    private static final Logger logger = LoggerFactory.getLogger(ProcessorClassProducer.class);

    private final ClassFileVisitor classFileVisitor;
    private final ProcessorContext processorContext;

    public ProcessorClassProducer(final ClassFileVisitor classFileVisitor, final ProcessorContext processorContext) {
        this.classFileVisitor = classFileVisitor;
        this.processorContext = processorContext;
    }

    @Override
    public void produceClass(final String internalName, final byte[] classData) {
        logger.debug("Producing class {}", internalName);
        final String classFileName = internalName + ".class";
        try {
            classFileVisitor.visitClassFile(classFileName, classData);
        } catch (final IOException exception) {
            final String message = String.format("Failed to produce class with %d bytes", classData.length);
            processorContext.reportError(new ProcessingException(message, exception, classFileName));
        }
    }
}

Add debug logging to ProcessorClassProducer