java.lang.Object
org.variantsync.diffdetective.experiments.views.ViewAnalysis
All Implemented Interfaces:
Analysis.Hooks

public class ViewAnalysis extends Object implements Analysis.Hooks
Implementation of the feasibility study from Section 6 of our paper Views on Edits to Variational Software at SPLC'23. This Analysis is run on a batch of commits of a single repository. For the whole feasibility study, multiple analysis are run in parallel, each processing a part of a repositories history.
  • Field Details

    • VIEW_CSV_EXTENSION

      public static final String VIEW_CSV_EXTENSION
      File extension for csv files created by this analysis.
      See Also:
    • csv

      private StringBuilder csv
      StringBuilder that is used to iteratively create a csv file with this analysis' results.
    • random

      private Random random
      Random instance to generate random numbers. Used to generate random relevance predicates.
  • Constructor Details

    • ViewAnalysis

      public ViewAnalysis()
  • Method Details

    • initializeResults

      public void initializeResults(Analysis analysis)
      Description copied from interface: Analysis.Hooks
      Initialization hook for Analysis.getResult(). All result types should be appended with a neutral value using Analysis.append(org.variantsync.diffdetective.analysis.AnalysisResult.ResultKey<T>, T). No other side effects should be performed during this methods as it might be called an arbitrary amount of times.
      Specified by:
      initializeResults in interface Analysis.Hooks
    • runRelevanceExperiment

      private void runRelevanceExperiment(Analysis analysis, VariationDiff<DiffLinesLabel> d, Relevance rho)
      Benchmark for view generation on the given variation diff with the given relevance. This method generates a view once with each algorithm: - once with the naive algorithm view_naive (Equation 8 from our paper), - and once with the optimized algorithm view_smart (Equation 10 in our paper). This method measures both algorithms runtimes and stores the runtimes and metadata in terms of a ViewEvaluation in this objects csv field.
      Parameters:
      analysis - The current instance of the analysis that is run. Used to access metadata of the current commit that is processed.
      d - The variation diff to benchmark view generation on.
      rho - A relevance predicate that determines which nodes should be contained in the view.
    • analyzeVariationDiff

      public boolean analyzeVariationDiff(Analysis analysis) throws Exception
      Runs the feasibility study on the current variation diff. Creates random relevance predicates as explained in Section 6 of our paper. Then runs runRelevanceExperiment(Analysis, VariationDiff, Relevance) for each relevance on the current variation diff.
      Specified by:
      analyzeVariationDiff in interface Analysis.Hooks
      Parameters:
      analysis - The current instance of the analysis that is run. Used to access metadata of the current commit that is processed.
      Returns:
      Analysis.Hooks.analyzeVariationDiff(Analysis)
      Throws:
      Exception
    • generateRandomRelevances

      private List<Relevance> generateRandomRelevances(VariationDiff<DiffLinesLabel> d)
      Generates random relevance predicates for creating random views on the given variation diff d, as explained in Section 6.1 in our paper. If possible, this method will generate one relevance of each type of Configure, Trace, and Search.
      Parameters:
      d - The variation diff to generate relevance predicates for.
      Returns:
      A list of three random relevance predicates.
    • addRandomRelevance

      private static <RelevanceParams, RelevanceCandidates extends Collection<RelevanceParams>> void addRandomRelevance(RelevanceCandidates source, Function<RelevanceCandidates,Relevance> pick, Collection<Relevance> target)
      This is a convenience method for creating a random relevance predicate from a collection of potential parameterisations.

      If the given collection source of parameters for relevance predicates is not empty, this method picks a random parameterization and creates a relevance predicate from it. The created predicate is added to the given target collection.

      Type Parameters:
      RelevanceParams - The type of the parameters for the relevance predicates.
      RelevanceCandidates - The type of collection of the parameters.
      Parameters:
      source - A potentially empty collection of arguments for relevance predicates.
      pick - A function that picks a parameterisation at random and creates a relevance predicate from it.
      target - A collection to which the randomly created relevance predicate will be added to.
    • addAll

      private static <RelevanceParams, RelevanceCandidates extends Collection<? extends RelevanceParams>> void addAll(RelevanceCandidates source, Function<? super RelevanceCandidates,? extends Collection<? extends Relevance>> prepare, Collection<Relevance> target)
      This is a convenience method for creating relevance predicates from their parameters.

      If the given collection of parameters for relevance predicates is not empty, this method generates corresponding relevance predicates for all those predicates and adds them to the given target collection.

      Type Parameters:
      RelevanceParams - The type of the parameters for the relevance predicates.
      RelevanceCandidates - The type of collection of the parameters.
      Parameters:
      source - A potentially empty collection of arguments for relevance predicates.
      prepare - A function that creates a relevance predicate from suitable arguments.
      target - A collection to which all relevance predicates will be added to.
    • allConfigureRelevances

      private List<Configure> allConfigureRelevances(List<org.prop4j.Node> deselectedPCs)
      Generates all Configure relevance predicates that can be generated from the given list of deselected presence conditions. The returned list of predicates is complete: For every (partial) variant of the variation tree or diff the deselected presence conditions come from, a corresponding relevance predicate is within the returned list.
      Parameters:
      deselectedPCs - A list of negations of all presence conditions that occur in a variation tree or diff.
      Returns:
      A complete list of Configure predicates.
    • randomConfigure

      private Configure randomConfigure(List<org.prop4j.Node> deselectedPCs)
      Creates a random Configure relevance predicate from the given list of deselected presence conditions. This method picks a random satisfiable formula from the given list and returns it as a relevance predicate for configuration.
      Returns:
      A random, satisfiable Configure predicate, created from the given presence conditions. Null if the given list is empty or if it does not contain a satisfiable formula.
    • allTraceRelevances

      private List<Trace> allTraceRelevances(Set<String> features)
      Generates a Trace relevance predicate for each feature in the given set of feature names.
      Parameters:
      features - A set of feature names to trace.
      Returns:
      A Trace predicate for each feature name in the given set.
    • randomTrace

      private Trace randomTrace(Set<String> features)
      Creates a random Trace relevance predicate from the given set of feature names.
      Parameters:
      features - A set of feature names.
      Returns:
      A Trace predicate for a feature name randomly picked from the given set.
    • allSearchRelevances

      private List<Search> allSearchRelevances(Set<String> artifacts)
      Generates a Search relevance predicate for each artifact in the given set.
      Parameters:
      artifacts - A list of text-based artifacts.
      Returns:
      A Search predicate for each artifact.
    • randomSearch

      private Search randomSearch(Set<String> artifacts)
      Creates a random Search relevance predicate from the given set of artifacts.
      Parameters:
      artifacts - A set of text-based artifacts (e.g., lines of code).
      Returns:
      A Search predicate for an artifact randomly picked from the given set.
    • endBatch

      public void endBatch(Analysis analysis) throws IOException
      Writes the results of this analysis to disk as CSV file.
      Specified by:
      endBatch in interface Analysis.Hooks
      Parameters:
      analysis - The current state of the analysis.
      Throws:
      IOException - When the file cannot be created or written.