Package org.sonar.java.checks.verifier
Class JavaCheckVerifier
- java.lang.Object
-
- org.sonar.java.checks.verifier.CheckVerifier
-
- org.sonar.java.checks.verifier.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.sonar.java.checks.verifier.CheckVerifier
CheckVerifier.IssueAttribute
-
-
Field Summary
-
Fields inherited from class org.sonar.java.checks.verifier.CheckVerifier
ATTRIBUTE_MAP, ISSUE_MARKER
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetExpectedIssueTrigger()static voidverify(String filename, JavaFileScanner check)Verifies that the provided file will raise all the expected issues when analyzed with the given check.static voidverify(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.static voidverify(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.static voidverify(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).static voidverifyIssueOnFile(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.static voidverifyIssueOnProject(String filename, String message, JavaFileScanner check)static voidverifyNoIssue(String filename, JavaFileScanner check)Verifies that the provided file will not raise any issue when analyzed with the given check.static voidverifyNoIssue(String filename, JavaFileScanner check, int javaVersion)Verifies that the provided file will not raise any issue when analyzed with the given check.static voidverifyNoIssueWithoutSemantic(String filename, JavaFileScanner check)static voidverifyNoIssueWithoutSemantic(String filename, JavaFileScanner check, int javaVersion)-
Methods inherited from class org.sonar.java.checks.verifier.CheckVerifier
checkIssues, collectExpectedIssues, expectNoIssues, getExpected, setExpectedFileIssue, setExpectedProjectIssue
-
-
-
-
Method Detail
-
getExpectedIssueTrigger
public String getExpectedIssueTrigger()
- Specified by:
getExpectedIssueTriggerin classCheckVerifier
-
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 byDEFAULT_TEST_JARS_DIRECTORYwill 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 analyzedcheck- 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 analyzedcheck- The check to be used for the analysisjavaVersion- 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 analyzedcheck- The check to be used for the analysisclasspath- 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 analyzedcheck- The check to be used for the analysistestJarsDirectory- 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 analyzedcheck- 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 analyzedcheck- The check to be used for the analysisjavaVersion- 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 analyzedmessage- The message expected to be raised on the filecheck- The check to be used for the analysis
-
verifyIssueOnProject
public static void verifyIssueOnProject(String filename, String message, JavaFileScanner check)
-
-