Search in sources :

Example 16 with FileContents

use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.

the class MainFrameModel method parseFileWithComments.

/**
     * Parse a file and return the parse tree with comment nodes.
     * @param file the file to parse.
     * @return the root node of the parse tree.
     * @throws IOException if the file could not be read.
     * @throws ANTLRException if the file is not a Java source.
     */
public DetailAST parseFileWithComments(File file) throws IOException, ANTLRException {
    final FileText fileText = getFileText(file);
    final FileContents contents = new FileContents(fileText);
    return TreeWalker.parseWithComments(contents);
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) FileText(com.puppycrawl.tools.checkstyle.api.FileText)

Example 17 with FileContents

use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.

the class MainFrameModel method parseFile.

/**
     * Parse a file and return the parse tree.
     * @param file the file to parse.
     * @return the root node of the parse tree.
     * @throws IOException if the file could not be read.
     * @throws ANTLRException if the file is not a Java source.
     */
public DetailAST parseFile(File file) throws IOException, ANTLRException {
    final FileText fileText = getFileText(file);
    final FileContents contents = new FileContents(fileText);
    return TreeWalker.parse(contents);
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) FileText(com.puppycrawl.tools.checkstyle.api.FileText)

Example 18 with FileContents

use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.

the class JavadocMethodCheck method processAST.

@Override
protected final void processAST(DetailAST ast) {
    final Scope theScope = calculateScope(ast);
    if (shouldCheck(ast, theScope)) {
        final FileContents contents = getFileContents();
        final TextBlock textBlock = contents.getJavadocBefore(ast.getLineNo());
        if (textBlock == null) {
            if (!isMissingJavadocAllowed(ast)) {
                log(ast, MSG_JAVADOC_MISSING);
            }
        } else {
            checkComment(ast, textBlock);
        }
    }
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) Scope(com.puppycrawl.tools.checkstyle.api.Scope) TextBlock(com.puppycrawl.tools.checkstyle.api.TextBlock)

Example 19 with FileContents

use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.

the class SuppressWithNearbyCommentFilter method accept.

@Override
public boolean accept(AuditEvent event) {
    boolean accepted = true;
    if (event.getLocalizedMessage() != null) {
        // Lazy update. If the first event for the current file, update file
        // contents and tag suppressions
        final FileContents currentContents = FileContentsHolder.getCurrentFileContents();
        if (getFileContents() != currentContents) {
            setFileContents(currentContents);
            tagSuppressions();
        }
        if (matchesTag(event)) {
            accepted = false;
        }
    }
    return accepted;
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents)

Aggregations

FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)19 TextBlock (com.puppycrawl.tools.checkstyle.api.TextBlock)6 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)5 FileText (com.puppycrawl.tools.checkstyle.api.FileText)4 ArrayList (java.util.ArrayList)3 RecognitionException (antlr.RecognitionException)2 TokenStreamException (antlr.TokenStreamException)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2 List (java.util.List)2 TokenStreamRecognitionException (antlr.TokenStreamRecognitionException)1 LineColumn (com.puppycrawl.tools.checkstyle.api.LineColumn)1 LocalizedMessages (com.puppycrawl.tools.checkstyle.api.LocalizedMessages)1 Scope (com.puppycrawl.tools.checkstyle.api.Scope)1 File (java.io.File)1 Test (org.junit.Test)1