Class JavaCheckVerifier


  • @Beta
    public class JavaCheckVerifier
    extends CheckVerifier
    It is possible to specify the absolute line number on which the issue should appear by appending "@<line>" to "Noncompliant". But usually better to use line number relative to the current, this is possible to do by prefixing the number with either '+' or '-'. For example:
       // Noncompliant@+1 {{do not import "java.util.List"}}
       import java.util.List;
     
    Full syntax:
       // Noncompliant@+1 [[startColumn=1;endLine=+1;endColumn=2;effortToFix=4;secondary=3,4]] {{issue message}}
     
    Attributes between [[]] are optional:
    • startColumn: column where the highlight starts
    • endLine: relative endLine where the highlight ends (i.e. +1), same line if omitted
    • endColumn: column where the highlight ends
    • effortToFix: the cost to fix as integer
    • secondary: a comma separated list of integers identifying the lines of secondary locations if any
    • Method Detail

      • verify

        public static void verify​(String filename,
                                  JavaFileScanner check)
        Verifies that the provided file will raise all the expected issues when analyzed with the given check.

        By default, any jar or zip archive present in the folder defined by DEFAULT_TEST_JARS_DIRECTORY will be used to add extra classes to the classpath. If this folder is empty or does not exist, then the analysis will be based on the source of the provided file.
        Parameters:
        filename - The file to be analyzed
        check - The check to be used for the analysis
      • verify

        public static void verify​(String filename,
                                  JavaFileScanner check,
                                  int javaVersion)
        Verifies that the provided file will raise all the expected issues when analyzed with the given check and a given java version used for the sources.
        Parameters:
        filename - The file to be analyzed
        check - The check to be used for the analysis
        javaVersion - The version to consider for the analysis (6 for java 1.6, 7 for 1.7, etc.)
      • verify

        public static void verify​(String filename,
                                  JavaFileScanner check,
                                  Collection<File> classpath)
        Verifies that the provided file will raise all the expected issues when analyzed with the given check, but using having the classpath extended with a collection of files (classes/jar/zip).
        Parameters:
        filename - The file to be analyzed
        check - The check to be used for the analysis
        classpath - The files to be used as classpath
      • verify

        public static void verify​(String filename,
                                  JavaFileScanner check,
                                  String testJarsDirectory)
        Verifies that the provided file will raise all the expected issues when analyzed with the given check, using jars/zips files from the given directory to extends the classpath.
        Parameters:
        filename - The file to be analyzed
        check - The check to be used for the analysis
        testJarsDirectory - The directory containing jars and/or zip defining the classpath to be used
      • verifyNoIssue

        public static void verifyNoIssue​(String filename,
                                         JavaFileScanner check)
        Verifies that the provided file will not raise any issue when analyzed with the given check.
        Parameters:
        filename - The file to be analyzed
        check - The check to be used for the analysis
      • verifyNoIssueWithoutSemantic

        public static void verifyNoIssueWithoutSemantic​(String filename,
                                                        JavaFileScanner check,
                                                        int javaVersion)
      • verifyNoIssueWithoutSemantic

        public static void verifyNoIssueWithoutSemantic​(String filename,
                                                        JavaFileScanner check)
      • verifyNoIssue

        public static void verifyNoIssue​(String filename,
                                         JavaFileScanner check,
                                         int javaVersion)
        Verifies that the provided file will not raise any issue when analyzed with the given check.
        Parameters:
        filename - The file to be analyzed
        check - The check to be used for the analysis
        javaVersion - The version to consider for the analysis (6 for java 1.6, 7 for 1.7, etc.)
      • verifyIssueOnFile

        public static void verifyIssueOnFile​(String filename,
                                             String message,
                                             JavaFileScanner check)
        Verifies that the provided file will only raise an issue on the file, with the given message, when analyzed using the given check.
        Parameters:
        filename - The file to be analyzed
        message - The message expected to be raised on the file
        check - The check to be used for the analysis