1 package com.puppycrawl.tools.checkstyle.checks; 20 21 import com.puppycrawl.tools.checkstyle.api.Check; 22 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 23 import com.puppycrawl.tools.checkstyle.api.DetailAST; 24 25 33 public class ArrayTypeStyleCheck extends Check 34 { 35 36 private boolean mJavaStyle = true; 37 38 39 public int[] getDefaultTokens() 40 { 41 return new int[] {TokenTypes.ARRAY_DECLARATOR}; 42 } 43 44 45 public void visitToken(DetailAST aAST) 46 { 47 final DetailAST typeAST = aAST.getParent(); 48 if (typeAST.getType() != TokenTypes.TYPE) { 49 return; 50 } 51 final DetailAST declAST = typeAST.getParent(); 52 if (declAST.getType() == TokenTypes.METHOD_DEF) { 53 return; 56 } 57 58 final DetailAST variableAST = (DetailAST) typeAST.getNextSibling(); 59 if (variableAST != null) { 60 final boolean isJavaStyle = 61 (variableAST.getLineNo() > aAST.getLineNo()) 62 || (variableAST.getColumnNo() > aAST.getColumnNo()); 63 64 if (isJavaStyle != mJavaStyle) { 65 log(aAST.getLineNo(), aAST.getColumnNo(), "array.type.style"); 66 } 67 } 68 } 69 70 74 public void setJavaStyle(boolean aJavaStyle) 75 { 76 mJavaStyle = aJavaStyle; 77 } 78 } 79 | Popular Tags |