/*
 * Copyright 2017-2019 University of Hildesheim, Software Systems Engineering
 *
 * 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
 *
 *     https://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 net.ssehub.kernel_haven.fe_analysis;

import net.ssehub.kernel_haven.SetUpException;
import net.ssehub.kernel_haven.analysis.AnalysisComponent;
import net.ssehub.kernel_haven.analysis.JoinComponent;
import net.ssehub.kernel_haven.analysis.PipelineAnalysis;
import net.ssehub.kernel_haven.config.Configuration;
import net.ssehub.kernel_haven.fe_analysis.arch_components.ArchComponentWriter;
import net.ssehub.kernel_haven.fe_analysis.arch_components.DummyArchComponentStorageCreator;
import net.ssehub.kernel_haven.fe_analysis.fes.FeatureRelations;
import net.ssehub.kernel_haven.fe_analysis.fes.ThreadedFeatureEffectFinder;
import net.ssehub.kernel_haven.fe_analysis.fes.FeatureEffectFinder.VariableWithFeatureEffect;
import net.ssehub.kernel_haven.fe_analysis.pcs.PcFinder;
import net.ssehub.kernel_haven.util.null_checks.NonNull;

/**
 * A analysis for visualization using architecture components. This uses {@link DummyArchComponentStorageCreator} to
 * create the component mapping; this is useful for example for Linux.
 * 
 * @author Adam
 */
public class DummyComponentVisualization extends PipelineAnalysis {

    /**
     * Creates this pipeline.
     * 
     * @param config The pipeline configuration.
     */
    public DummyComponentVisualization(@NonNull Configuration config) {
        super(config);
    }

    @Override
    protected @NonNull AnalysisComponent<?> createPipeline() throws SetUpException {
        
        DummyArchComponentStorageCreator archComponents
                = new DummyArchComponentStorageCreator(config, getVmComponent());
        ArchComponentWriter archComponentOut = new ArchComponentWriter(config, archComponents);
        
        PcFinder pcs = new PcFinder(config, getCmComponent(), getBmComponent());
        AnalysisComponent<VariableWithFeatureEffect> fes = new ThreadedFeatureEffectFinder(config, pcs);
        FeatureRelations feRels = new FeatureRelations(config, fes);
        
        return new JoinComponent(config, archComponentOut, feRels);
    }

}

@@ -683,16 +683,93 @@
 lysis;%0A%0A
+import static net.ssehub.kernel_haven.util.null_checks.NullHelpers.notNull;%0A%0A
 import n
@@ -2652,32 +2652,913 @@
  fes);%0A        %0A
+        AnalysisComponent%3C?%3E pssm;%0A        // get ProblemSolutionSpaceMapper via reflection, so this plugin doesn't depend on it%0A        try %7B%0A            Class%3C?%3E pssmClass = ClassLoader.getSystemClassLoader().loadClass(%0A                    %22net.ssehub.kernel_haven.pss_mapper.ProblemSolutionSpaceMapper%22);%0A            %0A            pssm = (AnalysisComponent%3C?%3E) pssmClass.getConstructor(%0A                    Configuration.class, AnalysisComponent.class, AnalysisComponent.class, AnalysisComponent.class)%0A                    .newInstance(config, getCmComponent(), getBmComponent(), getVmComponent());%0A            pssm = notNull(pssm); // newInstance never returns null%0A            %0A        %7D catch (ReflectiveOperationException %7C ClassCastException %7C SecurityException e) %7B%0A            throw new SetUpException(%22Can't instantiate PSS-Mapper via reflection%22, e);%0A        %7D%0A        %0A
         return n
@@ -3606,16 +3606,22 @@
 , feRels
+, pssm
 );%0A    %7D

Add ProblemSolutionSpaceMapper to DummyComponentVisualization