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 Pattern
Pattern that is used to extract theAnnotationType
and 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 AnnotationType
parseAnnotationType
(String directive) Converts the string captured by the named capture groupdirective
ofannotationPattern
into anAnnotationType
.protected abstract org.prop4j.Node
parseFormula
(String directive, String formula) Parses the feature formula of a preprocessor annotation line.
-
Field Details
-
annotationPattern
Pattern that is used to extract theAnnotationType
and the associatedformula
.The pattern needs to contain at least the two named capture groups
directive
andformula
. Thedirective
group must match a string that can be processed byparseAnnotationType(java.lang.String)
and whenever the resulting annotation typerequires a formula
, the capture groupformula
needs 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 theAnnotationType
and the associatedformula
of an annotation- See Also:
-
-
Method Details
-
parseAnnotation
Description copied from interface:AnnotationParser
Parse the given line as an annotation. Note thatline
might also be a line in a diff (i.e., preceded by-
or+
).- Specified by:
parseAnnotation
in interfaceAnnotationParser
- Parameters:
line
- that might contain an annotation- Returns:
- the annotation type and the associated formula.
If
line
doesn'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 groupdirective
ofannotationPattern
into 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 byannotationPattern
and it should return something likeand(var("A"), var("B==C"))
.This method is only called if
directive
actually requires a formula as determined byparseAnnotationType(java.lang.String)
.- Parameters:
directive
- as matched by the named capture groupdirective
ofannotationPattern
formula
- as matched by the named capture groupformula
ofannotationPattern
- Returns:
- the feature mapping
- Throws:
UnparseableFormulaException
- ifformula
is ill-formed.
-