Class LookaheadParser

java.lang.Object
edu.hm.hafner.analysis.IssueParser
edu.hm.hafner.analysis.LookaheadParser
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AbstractMavenLogParser, AcuCobolParser, AnsibleLintParser, Armcc5CompilerParser, ArmccCompilerParser, BluePearlParser, BuckminsterParser, CadenceIncisiveParser, CargoClippyParser, ClangParser, ClangTidyParser, CMakeParser, CodeAnalysisParser, CodeCheckerParser, CodeGeneratorParser, CoolfluxChessccParser, CppLintParser, CrossCoreEmbeddedStudioParser, DiabCParser, DrMemoryParser, EclipseMavenParser, EclipseParser, ErlcParser, ErrorProneParser, FlawfinderParser, FlexSdkParser, FoodcriticParser, Gcc4CompilerParser, Gcc4LinkerParser, GccParser, GhsMultiParser, GnatParser, GnuFortranParser, GoLintParser, GoVetParser, GradleErrorProneParser, IarCstatParser, IarParser, IntelParser, InvalidsParser, MentorParser, MetrowerksCwCompilerParser, MetrowerksCwLinkerParser, MsBuildParser, NagFortranParser, OELintAdvParser, P4Parser, Pep8Parser, PerlCriticParser, PhpParser, PreFastParser, ProtoLintParser, PuppetLintParser, PyLintParser, QacSourceCodeAnalyserParser, RobocopyParser, RuboCopParser, SbtScalacParser, ScalacParser, SphinxBuildLinkCheckParser, SphinxBuildParser, SunCParser, TaskingVxCompilerParser, TiCcsParser, TnsdlParser, XlcCompilerParser, XlcLinkerParser, YuiCompressorParser

public abstract class LookaheadParser extends IssueParser
Parses a report file line by line for issues using a pre-defined regular expression. If the regular expression matches then the abstract method createIssue(Matcher, LookaheadStream, IssueBuilder) will be called. Sub classes need to provide an implementation that transforms the Matcher instance into a new issue. If required, sub classes may consume additional lines from the report file before control is handed back to the template method of this parser.
Author:
Ullrich Hafner
See Also:
  • Field Details

    • ANT_TASK

      protected static final String ANT_TASK
      Pattern identifying an ant task debug output prefix.
      See Also:
  • Constructor Details

    • LookaheadParser

      protected LookaheadParser(String pattern)
      Creates a new instance of LookaheadParser.
      Parameters:
      pattern - pattern of compiler warnings.
  • Method Details

    • parse

      public Report parse(ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException
      Description copied from class: IssueParser
      Parses the specified file for issues.
      Specified by:
      parse in class IssueParser
      Parameters:
      readerFactory - provides a reader to the reports
      Returns:
      the issues
      Throws:
      ParsingException - Signals that during parsing a non-recoverable error has been occurred
      ParsingCanceledException - Signals that the parsing has been aborted by the user
    • preprocessLine

      protected void preprocessLine(String line)
      Preprocesses the specified line. This method is called before the line is checked for a match. Subclasses may override this empty default implementation.
      Parameters:
      line - the line to preprocess
    • createIssue

      protected abstract Optional<Issue> createIssue(Matcher matcher, edu.hm.hafner.util.LookaheadStream lookahead, IssueBuilder builder) throws ParsingException
      Creates a new issue for the specified pattern. This method is called for each matching line in the specified file. If a match is a false positive, then return Optional.empty() to ignore this warning.
      Parameters:
      matcher - the regular expression matcher
      lookahead - the lookahead stream to read additional lines
      builder - the issue builder to use
      Returns:
      a new annotation for the specified pattern
      Throws:
      ParsingException - Signals that during parsing a non recoverable error has been occurred
    • isLineInteresting

      protected boolean isLineInteresting(String line)
      Returns whether the specified line is interesting. Each interesting line will be matched by the defined regular expression. Here a parser can implement some fast checks (i.e. string or character comparisons) in order to see if a required condition is met. This default implementation does always return true.
      Parameters:
      line - the line to inspect
      Returns:
      true if the line should be handed over to the regular expression scanner, false if the line does not contain a warning.
    • postProcess

      protected Report postProcess(Report report)
      Post processes the issues. This default implementation does nothing.
      Parameters:
      report - the issues after the parsing process
      Returns:
      the post processed issues