Class PreprocessorAnnotationParser
java.lang.Object
org.variantsync.diffdetective.feature.PreprocessorAnnotationParser
- All Implemented Interfaces:
AnnotationParser
- Direct Known Subclasses:
CPPAnnotationParser,JPPAnnotationParser
A parser of preprocessor-like annotations.
- Author:
- Paul Bittner, Alexander Schultheiß
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final PatternPattern that is used to extract theAnnotationTypeand the associatedformula. -
Constructor Summary
ConstructorsConstructorDescriptionPreprocessorAnnotationParser(Pattern annotationPattern) Creates a new preprocessor annotation parser. -
Method Summary
Modifier and TypeMethodDescriptionparseAnnotation(String line) Parse the given line as an annotation.protected AnnotationTypeparseAnnotationType(String directive) Converts the string captured by the named capture groupdirectiveofannotationPatterninto anAnnotationType.protected abstract org.prop4j.NodeparseFormula(String directive, String formula) Parses the feature formula of a preprocessor annotation line.
-
Field Details
-
annotationPattern
Pattern that is used to extract theAnnotationTypeand the associatedformula.The pattern needs to contain at least the two named capture groups
directiveandformula. Thedirectivegroup must match a string that can be processed byparseAnnotationType(java.lang.String)and whenever the resulting annotation typerequires a formula, the capture groupformulaneeds to match the formula that should be processed byparseFormula(java.lang.String,java.lang.String).
-
-
Constructor Details
-
PreprocessorAnnotationParser
Creates a new preprocessor annotation parser.- Parameters:
annotationPattern- pattern that identifies theAnnotationTypeand the associatedformulaof an annotation- See Also:
-
-
Method Details
-
parseAnnotation
Description copied from interface:AnnotationParserParse the given line as an annotation. Note thatlinemight also be a line in a diff (i.e., preceded by-or+).- Specified by:
parseAnnotationin interfaceAnnotationParser- Parameters:
line- that might contain an annotation- Returns:
- the annotation type and the associated formula.
If
linedoesn't contain an annotation, returnsAnnotation(AnnotationType.NONE). - Throws:
UnparseableFormulaException- if an annotation is detected but it is malformed
-
parseAnnotationType
Converts the string captured by the named capture groupdirectiveofannotationPatterninto anAnnotationType. -
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 likeparseFormula("if", "A && B == C")(the exact arguments are determined byannotationPatternand it should return something likeand(var("A"), var("B==C")).This method is only called if
directiveactually requires a formula as determined byparseAnnotationType(java.lang.String).- Parameters:
directive- as matched by the named capture groupdirectiveofannotationPatternformula- as matched by the named capture groupformulaofannotationPattern- Returns:
- the feature mapping
- Throws:
UnparseableFormulaException- ifformulais ill-formed.
-