1 20 package com.puppycrawl.tools.checkstyle.checks.header; 21 22 import java.util.Arrays ; 23 24 import com.puppycrawl.tools.checkstyle.api.DetailAST; 25 import com.puppycrawl.tools.checkstyle.checks.AbstractHeaderCheck; 26 27 32 public class HeaderCheck extends AbstractHeaderCheck 33 { 34 35 private static final int[] EMPTY_INT_ARRAY = new int[0]; 36 37 38 private int[] mIgnoreLines = EMPTY_INT_ARRAY; 39 40 44 private boolean isIgnoreLine(int aLineNo) 45 { 46 return (Arrays.binarySearch(mIgnoreLines, aLineNo) >= 0); 47 } 48 49 54 protected boolean isMatch(int aLineNumber) 55 { 56 final String line = getLines()[aLineNumber]; 57 return isIgnoreLine(aLineNumber + 1) 59 || getHeaderLines()[aLineNumber].equals(line); 60 } 61 62 66 public void setIgnoreLines(int[] aList) 67 { 68 if ((aList == null) || (aList.length == 0)) { 69 mIgnoreLines = EMPTY_INT_ARRAY; 70 return; 71 } 72 73 mIgnoreLines = new int[aList.length]; 74 System.arraycopy(aList, 0, mIgnoreLines, 0, aList.length); 75 Arrays.sort(mIgnoreLines); 76 } 77 78 79 public void beginTree(DetailAST aRootAST) 80 { 81 if (getHeaderLines().length > getLines().length) { 82 log(1, "header.missing"); 83 } 84 else { 85 for (int i = 0; i < getHeaderLines().length; i++) { 86 if (!isMatch(i)) { 87 log(i + 1, "header.mismatch", getHeaderLines()[i]); 88 break; } 90 } 91 } 92 } 93 } 94 | Popular Tags |