Search in sources :

Example 1 with XpathQueryGenerator

use of com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator in project checkstyle by checkstyle.

the class AbstractXpathTestSupport method generateXpathQueries.

/**
 * Returns a list of XPath queries to locate the violation nodes in a Java file.
 *
 * @param fileToProcess the Java file to be processed. {@link File} type object.
 * @param position the position of violation in the file. {@link ViolationPosition} object.
 * @return a list of strings containing XPath queries for locating violation nodes.
 * @throws Exception can throw exceptions while accessing file contents.
 */
private static List<String> generateXpathQueries(File fileToProcess, ViolationPosition position) throws Exception {
    final FileText fileText = new FileText(fileToProcess, StandardCharsets.UTF_8.name());
    final DetailAST rootAst = JavaParser.parseFile(fileToProcess, JavaParser.Options.WITH_COMMENTS);
    final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(rootAst, position.violationLineNumber, position.violationColumnNumber, fileText, DEFAULT_TAB_WIDTH);
    return queryGenerator.generate();
}
Also used : XpathQueryGenerator(com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FileText(com.puppycrawl.tools.checkstyle.api.FileText)

Example 2 with XpathQueryGenerator

use of com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator in project checkstyle by checkstyle.

the class XpathFileGeneratorAstFilter method accept.

@Override
public boolean accept(TreeWalkerAuditEvent event) {
    if (event.getTokenType() != 0) {
        final XpathQueryGenerator xpathQueryGenerator = new XpathQueryGenerator(event, tabWidth);
        final List<String> xpathQueries = xpathQueryGenerator.generate();
        if (!xpathQueries.isEmpty()) {
            final String query = String.join(DELIMITER, xpathQueries);
            MESSAGE_QUERY_MAP.put(event.getViolation(), query);
        }
    }
    return true;
}
Also used : XpathQueryGenerator(com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator)

Example 3 with XpathQueryGenerator

use of com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator in project checkstyle by checkstyle.

the class SuppressionsStringPrinter method generate.

/**
 * Creates {@code XpathQueryGenerator} instance and generates suppressions.
 *
 * @param fileText {@code FileText} object.
 * @param detailAST {@code DetailAST} object.
 * @param lineNumber line number.
 * @param columnNumber column number.
 * @param tabWidth length of the tab character.
 * @return generated suppressions.
 */
private static String generate(FileText fileText, DetailAST detailAST, int lineNumber, int columnNumber, int tabWidth) {
    final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(detailAST, lineNumber, columnNumber, fileText, tabWidth);
    final List<String> suppressions = queryGenerator.generate();
    return suppressions.stream().collect(Collectors.joining(LINE_SEPARATOR, "", LINE_SEPARATOR));
}
Also used : XpathQueryGenerator(com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator)

Aggregations

XpathQueryGenerator (com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator)3 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)1 FileText (com.puppycrawl.tools.checkstyle.api.FileText)1