Class AbstractingFormulaExtractor

java.lang.Object
org.variantsync.diffdetective.feature.AbstractingFormulaExtractor
All Implemented Interfaces:
DiffLineFormulaExtractor
Direct Known Subclasses:
CPPDiffLineFormulaExtractor, JPPDiffLineFormulaExtractor

public abstract class AbstractingFormulaExtractor extends Object implements DiffLineFormulaExtractor
AbstractingFormulaExtractor is an abstract class that extracts a formula from text containing a conditional annotation, and then abstracts the formula using the custom abstractFormula(String) implementation of its subclass. The extraction of a formula is controlled by a Pattern with which an AbstractingFormulaExtractor is initialized. The given text might also be a line in a diff (i.e., preceeded by a '-' or '+').

For example, given the annotation "#if defined(A) || B()", the extractor should extract the formula "defined(A) || B". It would then hand this formula to the abstractFormula(String) method for abstraction (e.g., to substitute the 'defined(A)' macro call with 'DEFINED_A').

Author:
Paul Bittner, Sören Viegener, Benjamin Moosherr, Alexander Schultheiß
  • Field Details

    • annotationPattern

      private final Pattern annotationPattern
  • Constructor Details

    • AbstractingFormulaExtractor

      public AbstractingFormulaExtractor(Pattern annotationPattern)
      Initialize a new AbstractingFormulaExtractor object that uses the given Pattern to identify formulas in annotations. See CPPDiffLineFormulaExtractor for an example of how such a pattern could look like.
      Parameters:
      annotationPattern - The pattern used for formula extraction
  • Method Details

    • extractFormula

      public String extractFormula(String text) throws UnparseableFormulaException
      Extracts the feature formula as a string from a piece of text (possibly within a diff) and abstracts it.
      Specified by:
      extractFormula in interface DiffLineFormulaExtractor
      Parameters:
      text - The text of which to extract the formula
      Returns:
      The extracted and abstracted formula
      Throws:
      UnparseableFormulaException
    • abstractFormula

      protected abstract String abstractFormula(String formula)
      Abstract the given formula (e.g., by substituting parts of the formula with predefined String literals). See CPPDiffLineFormulaExtractor for an example of how this could be done.
      Parameters:
      formula - that is to be abstracted
      Returns:
      the abstracted formula