2017-07-31 57 views
0

我想寫一個自定義檢查Checkstyle 8.1。我成功安裝並配置Gradle Checkstyle並寫入我的支票草圖。但是,當我嘗試運行我的支票 - 我有錯誤Android checkstyle - 調試自定義檢查

Execution failed for task ':app:checkstyle'. 
> Unable to process files: FILE1, FILE2 ... 

這裏是我的校驗碼

package com.lsurvila.checkstyle; 
import com.puppycrawl.tools.checkstyle.api.*; 

import javax.xml.ws.LogicalMessage; 

public class LinesAfterClassJavadocCheck extends AbstractCheck 
{ 
    private static final int DEFAULT_MAX = 30; 
    private int max = DEFAULT_MAX; 

    /** 
    * Returns the default token a check is interested in. Only used if the 
    * configuration for a check does not define the tokens. 
    * 
    * @return the default tokens 
    * @see TokenTypes 
    */ 
    @Override 
    public int[] getDefaultTokens() { 
     return new int[]{TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF}; 
    } 

    /** 
    * The configurable token set. 
    * Used to protect Checks against malicious users who specify an 
    * unacceptable token set in the configuration file. 
    * The default implementation returns the check's default tokens. 
    * 
    * @return the token set this check is designed for. 
    * @see TokenTypes 
    */ 
    @Override 
    public int[] getAcceptableTokens() { 
     return new int[0]; 
    } 

    /** 
    * The tokens that this check must be registered for. 
    * 
    * @return the token set this must be registered for. 
    * @see TokenTypes 
    */ 
    @Override 
    public int[] getRequiredTokens() { 
     return new int[0]; 
    } 

    @Override 
    public void visitToken(DetailAST ast) 
    { 
     //throw new IllegalArgumentException("SUKA BLEAT"); 
     DetailAST objBlock1 = ast.findFirstToken(TokenTypes.LITERAL_CLASS); 
     if (objBlock1 == null) { 
      log(ast.getLineNo(), "PIDOR"); 
      //System.out.print("PIDOR"); 
     } 

     String a = getLine(objBlock1.getLineNo()-1); 
     log(1,a); 
     //System.out.print(a); 
     if (a.isEmpty()) { 
      log(ast.getLineNo(), "PIDOR1"); 
     } 

     /*DetailAST objBlock2 = ast.findFirstToken(TokenTypes.MODIFIERS).findFirstToken(TokenTypes.BLOCK_COMMENT_BEGIN); 
     if (objBlock2 == null) { 
      log(ast.getLineNo(), "PIDOR1"); 
      //System.out.print("PIDOR"); 
     }*/ 

     /*DetailAST objBlock2 = ast.findFirstToken(TokenTypes.LITERAL_CLASS); 

     DetailAST objBlock3 = objBlock1.findFirstToken(TokenTypes.MODIFIERS).findFirstToken(TokenTypes.BLOCK_COMMENT_BEGIN).findFirstToken(TokenTypes.BLOCK_COMMENT_END); 




     if (objBlock3.getLine()+2 != objBlock2.getLine()) { 
      log(ast.getLineNo(), "PIDOR"); 
     }*/ 
    } 
} 

我發現log()方法產生這種例外。我沒有找到另一種方法來查看我的代碼中發生了什麼 - 即使System.out.print()也不顯示任何內容。我怎樣才能運行調試器附加到我的自定義檢查?由於在編譯應用程序之前我的檢查已經開始,所以情況很複雜。

這裏是screenshoot如何檢查擺在我的應用程序的項目: enter image description here

請對不起我的英文不好

回答

0

我建議使用Command line interface看到的Checkstyle的原始輸出和錯誤。我沒有具體瞭解gradle如何處理這些情況,但System.out應該從CLI工作。如果你仍然沒有輸出,那可能是visitToken甚至沒有被調用。

我還建議使用-t選項來查看文件的AST樹,以驗證您是否爲您的支票獲取了權限令牌。

return new int[0]; 

這是不對的,你必須返回一個標記Acceptable否則你是說你的支票接受什麼。將其更改爲返回getDefaultTokens

我建議從their google group form獲得小組的幫助。