Class JavaCheckVerifier

java.lang.Object
org.sonar.java.checks.verifier.internal.JavaCheckVerifier
All Implemented Interfaces:
CheckVerifier

public class JavaCheckVerifier extends Object implements CheckVerifier
  • Method Details

    • newInstance

      public static JavaCheckVerifier newInstance()
    • withCheck

      public CheckVerifier withCheck(JavaFileScanner check)
      Description copied from interface: CheckVerifier
      Defines the check to be verified against at least one test file.
      Specified by:
      withCheck in interface CheckVerifier
      Parameters:
      check - the rule to be verified
      Returns:
      the verifier configured to use the check provided as an argument
    • withChecks

      public CheckVerifier withChecks(JavaFileScanner... checks)
      Description copied from interface: CheckVerifier
      Defines the check(s) to be verified against at least one test file.
      Specified by:
      withChecks in interface CheckVerifier
      Parameters:
      checks - the rules to be verified
      Returns:
      the verifier configured to use the checks provided as argument
    • withClassPath

      public CheckVerifier withClassPath(Collection<File> classpath)
      Description copied from interface: CheckVerifier
      Defines the classpath to be used for the verification. Usually used when the code of the test files require the knowledge of a particular set of libraries or java compiled classes.
      Specified by:
      withClassPath in interface CheckVerifier
      Parameters:
      classpath - a collection of files which defines the classes/jars/zips which contains the bytecode to be used as a classpath when executing the rule
      Returns:
      the verifier configured to use the files provided as argument as classpath
    • withJavaVersion

      public CheckVerifier withJavaVersion(int javaVersionAsInt)
      Description copied from interface: CheckVerifier
      Defines the java version syntax to be used for the verification. Usually used when the code of the test files explicitly target a given version (e.g. java 7) where a particular syntax/API has been introduced. Preview features for the specified java version will be disabled by default; use CheckVerifier.withJavaVersion(int, boolean) to enable or disable preview features associated with the specified java version.
      Specified by:
      withJavaVersion in interface CheckVerifier
      Parameters:
      javaVersionAsInt - defines the java language syntax version to be considered during verification, provided as an integer. For instance, for Java 1.7, use '7'. For Java 12, simply '12'.
      Returns:
      the verifier configured to consider the provided test file(s) as following the syntax of the given java version
    • withJavaVersion

      public CheckVerifier withJavaVersion(int javaVersionAsInt, boolean enablePreviewFeatures)
      Description copied from interface: CheckVerifier
      Defines the java version syntax to be used for the verification. Usually used when the code of the test files explicitly target a given version (e.g. java 7) where a particular syntax/API has been introduced.
      Specified by:
      withJavaVersion in interface CheckVerifier
      Parameters:
      javaVersionAsInt - defines the java language syntax version to be considered during verification, provided as an integer. For instance, for Java 1.7, use '7'. For Java 12, simply '12'.
      enablePreviewFeatures - defines if preview features from the specified java version should be enabled or not
      Returns:
      the verifier configured to consider the provided test file(s) as following the syntax of the given java version
    • withinAndroidContext

      public CheckVerifier withinAndroidContext(boolean inAndroidContext)
      Description copied from interface: CheckVerifier
      Defines whether the current file is an analyzer in an Android context.
      Specified by:
      withinAndroidContext in interface CheckVerifier
      Returns:
      the verifier currently configured
    • onFile

      public CheckVerifier onFile(String filename)
      Description copied from interface: CheckVerifier
      Defines the filename to be verified with the given rule(s). This file should contain all the "Noncompliant" comments defining the expected issues.
      Specified by:
      onFile in interface CheckVerifier
      Parameters:
      filename - the file to be analyzed
      Returns:
      the verifier configured to consider the provided test file as the source for the rule(s)
    • onFiles

      public CheckVerifier onFiles(String... filenames)
      Description copied from interface: CheckVerifier
      Defines the filenames to be verified with the given rule(s). These files should all contain "Noncompliant" comments defining the expected issues.
      Specified by:
      onFiles in interface CheckVerifier
      Parameters:
      filenames - the files to be analyzed
      Returns:
      the verifier configured to consider the provided test file(s) as source for the rule(s)
    • onFiles

      public CheckVerifier onFiles(Collection<String> filenames)
      Description copied from interface: CheckVerifier
      Defines a collection of filenames to be verified with the given rule(s). These files should all contain "Noncompliant" comments defining the expected issues.
      Specified by:
      onFiles in interface CheckVerifier
      Parameters:
      filenames - a collection of files to be analyzed
      Returns:
      the verifier configured to consider the provided test file(s) as source for the rule(s)
    • addFiles

      public CheckVerifier addFiles(org.sonar.api.batch.fs.InputFile.Status status, String... filenames)
      Description copied from interface: CheckVerifier
      Adds a collection of files with an expected status to be verified by the given rule(s). An exception is thrown if a file by the same filename is already listed to be analyzed.
      Specified by:
      addFiles in interface CheckVerifier
      Parameters:
      status - The status of the files to be analyzed
      filenames - a collection of files to be analyzed
      Returns:
      the verifier configured
    • addFiles

      public CheckVerifier addFiles(org.sonar.api.batch.fs.InputFile.Status status, Collection<String> filenames)
      Description copied from interface: CheckVerifier
      Adds a collection of files with an expected status. An exception is thrown if a file with the same filename is already listed to be analyzed.
      Specified by:
      addFiles in interface CheckVerifier
      Parameters:
      status - The status of the files to be analyzed
      filenames - a collection of files to be analyzed
      Returns:
      the verifier configured
    • withoutSemantic

      public CheckVerifier withoutSemantic()
      Description copied from interface: CheckVerifier
      Tells the verifier that no bytecode will be provided. This method is usually used in combination with CheckVerifier.verifyNoIssues(), to assert the fact that if no bytecode is provided, the rule will not raise any issues.
      Specified by:
      withoutSemantic in interface CheckVerifier
      Returns:
      the verifier configured to consider that no bytecode will be provided for analysis
    • withCache

      public CheckVerifier withCache(@Nullable org.sonar.api.batch.sensor.cache.ReadCache readCache, @Nullable org.sonar.api.batch.sensor.cache.WriteCache writeCache)
      Description copied from interface: CheckVerifier
      Tells the verifier to feed the check with cached information in its preScan phase.
      Specified by:
      withCache in interface CheckVerifier
      Parameters:
      readCache - A source of information from previous analyses
      writeCache - A place to dump information at the end of the analysis
      Returns:
      the verifier configured with the caches to use.
    • verifyIssues

      public void verifyIssues()
      Description copied from interface: CheckVerifier
      Verifies that all the expected issues are correctly raised by the rule(s), at their expected positions and attributes.
      Specified by:
      verifyIssues in interface CheckVerifier
    • verifyIssueOnFile

      public void verifyIssueOnFile(String expectedIssueMessage)
      Description copied from interface: CheckVerifier
      Verifies that an issue (only one) is raised directly on the file and not within the content of the file.
      Specified by:
      verifyIssueOnFile in interface CheckVerifier
      Parameters:
      expectedIssueMessage - the message to be expected with the issue.
    • verifyIssueOnProject

      public void verifyIssueOnProject(String expectedIssueMessage)
      Description copied from interface: CheckVerifier
      Verifies that an issue (only one) is raised directly on the project, which would include this file, and not within the content of the file.
      Specified by:
      verifyIssueOnProject in interface CheckVerifier
      Parameters:
      expectedIssueMessage -
    • verifyNoIssues

      public void verifyNoIssues()
      Description copied from interface: CheckVerifier
      Verifies that no issues are raised by the rule(s) on the given file(s).
      Specified by:
      verifyNoIssues in interface CheckVerifier