Class PreprocessorAnnotationParser
java.lang.Object
org.variantsync.diffdetective.feature.PreprocessorAnnotationParser
- All Implemented Interfaces:
AnnotationParser
A parser of preprocessor-like annotations.
- Author:
- Paul Bittner, Alexander Schultheiß
-
Field Summary
Modifier and TypeFieldDescriptionprivate final Pattern
protected static final Pattern
Matches the beginning or end of CPP conditional macros.static final PreprocessorAnnotationParser
Default parser for C preprocessor annotations.private final DiffLineFormulaExtractor
private final PropositionalFormulaParser
protected static final Pattern
Matches the beginning or end of JPP conditional macros.static final PreprocessorAnnotationParser
Default parser for JavaPP (Java PreProcessor) annotations. -
Constructor Summary
ConstructorDescriptionPreprocessorAnnotationParser
(Pattern annotationPattern, DiffLineFormulaExtractor formulaExtractor) PreprocessorAnnotationParser
(Pattern annotationPattern, PropositionalFormulaParser formulaParser, DiffLineFormulaExtractor formulaExtractor) Creates a new preprocessor annotation parser. -
Method Summary
Modifier and TypeMethodDescriptionstatic PreprocessorAnnotationParser
CreateCppAnnotationParser
(PropositionalFormulaParser formulaParser, DiffLineFormulaExtractor formulaExtractor) Creates a new preprocessor annotation parser for C preprocessor annotations.static PreprocessorAnnotationParser
CreateJppAnnotationParser
(PropositionalFormulaParser formulaParser, DiffLineFormulaExtractor formulaExtractor) Creates a new preprocessor annotation parser for JavaPP (Java PreProcessor) annotations.Determine the annotation type for the given piece of text (typically a line of source code).org.prop4j.Node
parseAnnotation
(String line) Parses the condition of the given line of source code that contains a preprocessor macro (i.e., IF, IFDEF, ELIF).
-
Field Details
-
CPP_PATTERN
Matches the beginning or end of CPP conditional macros. It doesn't match the whole macro name, for example for#ifdef
only"#if"
is matched and only"if"
is captured.Note that this pattern doesn't handle comments between
#
and the macro name. -
JPP_PATTERN
Matches the beginning or end of JPP conditional macros. It doesn't match the whole macro name, for example for//#if defined(x)
only"//#if"
is matched and only"if"
is captured. -
CPPAnnotationParser
Default parser for C preprocessor annotations. Created by invokingPreprocessorAnnotationParser(Pattern, PropositionalFormulaParser, DiffLineFormulaExtractor)
. -
JPPAnnotationParser
Default parser for JavaPP (Java PreProcessor) annotations. Created by invokingPreprocessorAnnotationParser(Pattern, PropositionalFormulaParser, DiffLineFormulaExtractor)
. -
annotationPattern
-
formulaParser
-
extractor
-
-
Constructor Details
-
PreprocessorAnnotationParser
public PreprocessorAnnotationParser(Pattern annotationPattern, DiffLineFormulaExtractor formulaExtractor) InvokesPreprocessorAnnotationParser(Pattern, PropositionalFormulaParser, DiffLineFormulaExtractor)
with thedefault formula parser
and a newDiffLineFormulaExtractor
.- Parameters:
annotationPattern
- Pattern that is used to identify the AnnotationType of a given annotation;CPP_PATTERN
provides an example
-
PreprocessorAnnotationParser
public PreprocessorAnnotationParser(Pattern annotationPattern, PropositionalFormulaParser formulaParser, DiffLineFormulaExtractor formulaExtractor) Creates a new preprocessor annotation parser.- Parameters:
annotationPattern
- Pattern that is used to identify the AnnotationType of a given annotation;CPP_PATTERN
provides an exampleformulaParser
- Parser that is used to parse propositional formulas in conditional annotations (e.g., the formulaf
in#if f
).formulaExtractor
- An extractor that extracts the formula part of a preprocessor annotation that is then given to the formulaParser.
-
-
Method Details
-
CreateCppAnnotationParser
public static PreprocessorAnnotationParser CreateCppAnnotationParser(PropositionalFormulaParser formulaParser, DiffLineFormulaExtractor formulaExtractor) Creates a new preprocessor annotation parser for C preprocessor annotations.- Parameters:
formulaParser
- Parser that is used to parse propositional formulas in conditional annotations (e.g., the formulaf
in#if f
).formulaExtractor
- An extractor that extracts the formula part of a preprocessor annotation that is then given to the formulaParser.
-
CreateJppAnnotationParser
public static PreprocessorAnnotationParser CreateJppAnnotationParser(PropositionalFormulaParser formulaParser, DiffLineFormulaExtractor formulaExtractor) Creates a new preprocessor annotation parser for JavaPP (Java PreProcessor) annotations.- Parameters:
formulaParser
- Parser that is used to parse propositional formulas in conditional annotations (e.g., the formulaf
in#if f
).formulaExtractor
- An extractor that extracts the formula part of a preprocessor annotation that is then given to the formulaParser.
-
parseAnnotation
Parses the condition of the given line of source code that contains a preprocessor macro (i.e., IF, IFDEF, ELIF).- Specified by:
parseAnnotation
in interfaceAnnotationParser
- Parameters:
line
- The line of code of a preprocessor annotation.- Returns:
- The formula of the macro in the given line. If no such formula could be parsed, returns a Literal with the line's condition as name.
- Throws:
UnparseableFormulaException
- whenDiffLineFormulaExtractor.extractFormula(String)
throws.
-
determineAnnotationType
Description copied from interface:AnnotationParser
Determine the annotation type for the given piece of text (typically a line of source code).- Specified by:
determineAnnotationType
in interfaceAnnotationParser
- Parameters:
text
- The text of which the type is determined.- Returns:
- The annotation type of the piece of text.
-