001/*
002 * Hypo, an extensible and pluggable Java bytecode analytical model.
003 *
004 * Copyright (C) 2021  Kyle Wood (DemonWav)
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the Lesser GNU General Public License as published by
008 * the Free Software Foundation, version 3 of the License only.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package com.demonwav.hypo.core;
020
021import com.demonwav.hypo.model.ClassDataDecorator;
022import com.demonwav.hypo.model.ClassDataProvider;
023import com.demonwav.hypo.model.data.ClassData;
024import org.jetbrains.annotations.NotNull;
025
026/**
027 * The default implementation of {@link ClassDataDecorator}. The only thing this does is set the provider for the
028 * {@link ClassData} object based on the {@link ClassDataProvider provider} passed to this class in the constructor.
029 */
030public class DefaultClassDataDecorator implements ClassDataDecorator {
031
032    private final @NotNull ClassDataProvider provider;
033
034    /**
035     * Create a new instance of this class which will pass the given provider on to each {@link ClassData} object's
036     * {@link ClassData#setProvider(ClassDataProvider)} method.
037     *
038     * @param provider The provider to pass on to each {@link ClassData} object.
039     */
040    public DefaultClassDataDecorator(final @NotNull ClassDataProvider provider) {
041        this.provider = provider;
042    }
043
044    @Override
045    public void decorate(final @NotNull ClassData classData) {
046        classData.setProvider(this.provider);
047    }
048}