* Defaults to {@link OutputFormat#PLAIN}.
*
* @param format the output format
* @return the checkstyle operation
*/
public CheckstyleOperation format(OutputFormat format) {
options_.put("-f", format.label.toLowerCase());
return this;
}
/**
* Generates to output a suppression xml to use to suppress all violations from user's config. Instead of printing
* every violation, all violations will be caught and single suppressions xml file will be printed out.
* Used only with the {@link #configurationFile(String) configurationFile} option. Output location can be specified
* with the {@link #outputPath(String) output} option.
*
* @param xPathSuppression {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression) {
if (xPathSuppression) {
options_.put("-g", "");
} else {
options_.remove("-g");
}
return this;
}
/*
* Determines if a string is not blank.
*/
private boolean isNotBlank(String s) {
return s != null && !s.isBlank();
}
/**
* This option is used to print the Parse Tree of the Javadoc comment. The file has to contain only Javadoc comment
* content excluding '/**' and '*/' at the beginning and at the end respectively. It can only be used on a
* single file and cannot be combined with other options.
*
* @param isTree {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation javadocTree(boolean isTree) {
if (isTree) {
options_.put("-j", "");
} else {
options_.remove("-j");
}
return this;
}
/**
* Returns the command line options.
*
* @return the command line options
*/
public Map
* Defaults to stdout.
*
* @param file the output file
* @return the checkstyle operation
*/
public CheckstyleOperation outputPath(String file) {
if (isNotBlank(file)) {
options_.put("-o", file);
}
return this;
}
/**
* Sets the output file.
*
* Defaults to stdout.
*
* @param file the output file
* @return the checkstyle operation
*/
public CheckstyleOperation outputPath(File file) {
return outputPath(file.getAbsolutePath());
}
/**
* Sets the property files to load.
*
* @param file the file
* @return the checkstyle operation
*/
public CheckstyleOperation propertiesFile(String file) {
if (isNotBlank(file)) {
options_.put("-p", file);
}
return this;
}
/**
* Sets the property files to load.
*
* @param file the file
* @return the checkstyle operation
*/
public CheckstyleOperation propertiesFile(File file) {
return propertiesFile(file.getAbsolutePath());
}
/**
* Specified the file(s) or folder(s) containing the source files to check.
*
* @param dir one or more directories
* @return the checkstyle operation
* @see #sourceDir(Collection)
*/
public CheckstyleOperation sourceDir(String... dir) {
sourceDir_.addAll(Arrays.stream(dir).map(File::new).toList());
return this;
}
/**
* Specified the file(s) or folder(s) containing the source files to check.
*
* @param dir one or more directories
* @return the checkstyle operation
* @see #sourceDir(Collection)
*/
public CheckstyleOperation sourceDir(File... dir) {
sourceDir_.addAll(List.of(dir));
return this;
}
/**
* Specified the file(s) or folder(s) containing the source files to check.
*
* @param dirs the directories
* @return the checkstyle operation
* @see #sourceDir(String...)
*/
public CheckstyleOperation sourceDir(Collection
* Note that the generated result will have few queries, joined by pipe({@code |}). Together they will match all
* AST nodes on specified line and column. You need to choose only one and recheck that it works. Usage of all of
* them is also ok, but might result in undesirable matching and suppress other issues.
*
* @param lineColumnNumber the line column number
* @return the checkstyle operation
*/
public CheckstyleOperation suppressionLineColumnNumber(String lineColumnNumber) {
if (isNotBlank(lineColumnNumber)) {
options_.put("-s", lineColumnNumber);
}
return this;
}
/**
* Sets the length of the tab character. Used only with the
* {@link #suppressionLineColumnNumber(String) suppressionLineColumnNumber} option.
*
* Default value is {@code 8}.
*
* @param length the length
* @return the checkstyle operation
*/
public CheckstyleOperation tabWith(int length) {
options_.put("-w", String.valueOf(length));
return this;
}
/**
* This option is used to display the Abstract Syntax Tree (AST) without any comments of the specified file. It can
* only be used on a single file and cannot be combined with other options.
*
* @param isTree {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation tree(boolean isTree) {
if (isTree) {
options_.put("-t", "");
} else {
options_.remove("-t");
}
return this;
}
/**
* This option is used to display the Abstract Syntax Tree (AST) with comment nodes excluding Javadoc of the
* specified file. It can only be used on a single file and cannot be combined with other options.
*
* @param isTree {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation treeWithComments(boolean isTree) {
if (isTree) {
options_.put("-T", "");
} else {
options_.remove("-T");
}
return this;
}
/**
* This option is used to display the Abstract Syntax Tree (AST) with Javadoc nodes of the specified file. It can
* only be used on a single file and cannot be combined with other options.
*
* @param isTree {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation treeWithJavadoc(boolean isTree) {
if (isTree) {
options_.put("-J", "");
} else {
options_.remove("-J");
}
return this;
}
}