Class PreprocessorAnnotationParser

java.lang.Object
org.variantsync.diffdetective.feature.PreprocessorAnnotationParser
All Implemented Interfaces:
AnnotationParser
Direct Known Subclasses:
CPPAnnotationParser, JPPAnnotationParser

public abstract class PreprocessorAnnotationParser extends Object implements AnnotationParser
A parser of preprocessor-like annotations.
Author:
Paul Bittner, Alexander Schultheiß
See Also:
  • Field Details

  • Constructor Details

    • PreprocessorAnnotationParser

      public PreprocessorAnnotationParser(Pattern annotationPattern)
      Creates a new preprocessor annotation parser.
      Parameters:
      annotationPattern - pattern that identifies the AnnotationType and the associated formula of an annotation
      See Also:
  • Method Details

    • parseAnnotation

      public Annotation parseAnnotation(String line) throws UnparseableFormulaException
      Description copied from interface: AnnotationParser
      Parse the given line as an annotation. Note that line might also be a line in a diff (i.e., preceded by - or +).
      Specified by:
      parseAnnotation in interface AnnotationParser
      Parameters:
      line - that might contain an annotation
      Returns:
      the annotation type and the associated formula. If line doesn't contain an annotation, returns Annotation(AnnotationType.NONE).
      Throws:
      UnparseableFormulaException - if an annotation is detected but it is malformed
    • parseAnnotationType

      protected AnnotationType parseAnnotationType(String directive)
      Converts the string captured by the named capture group directive of annotationPattern into an AnnotationType.
    • parseFormula

      protected abstract org.prop4j.Node parseFormula(String directive, String formula) throws UnparseableFormulaException
      Parses the feature formula of a preprocessor annotation line. It should abstract complex formulas (e.g., if they contain arithmetics or macro calls) as desired. For example, for the line "#if A && B == C", this method is should be called like parseFormula("if", "A && B == C") (the exact arguments are determined by annotationPattern and it should return something like and(var("A"), var("B==C")).

      This method is only called if directive actually requires a formula as determined by parseAnnotationType(java.lang.String).

      Parameters:
      directive - as matched by the named capture group directive of annotationPattern
      formula - as matched by the named capture group formula of annotationPattern
      Returns:
      the feature mapping
      Throws:
      UnparseableFormulaException - if formula is ill-formed.