1 package com.puppycrawl.tools.checkstyle.checks.imports; 20 21 import com.puppycrawl.tools.checkstyle.api.Check; 22 import com.puppycrawl.tools.checkstyle.api.DetailAST; 23 import com.puppycrawl.tools.checkstyle.api.FullIdent; 24 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 25 26 54 public class AvoidStarImportCheck 55 extends Check 56 { 57 58 private String [] mExcludes = new String [0]; 59 60 61 public int[] getDefaultTokens() 62 { 63 return new int[] {TokenTypes.IMPORT}; 64 } 65 66 70 public void setExcludes(String [] aExcludes) 71 { 72 mExcludes = new String [aExcludes.length]; 73 for (int i = 0; i < aExcludes.length; i++) { 74 mExcludes[i] = aExcludes[i]; 75 if (!mExcludes[i].endsWith(".*")) { 76 mExcludes[i] = mExcludes[i] + ".*"; 79 } 80 } 81 } 82 83 84 public void visitToken(DetailAST aAST) 85 { 86 final FullIdent name = FullIdent.createFullIdentBelow(aAST); 87 if ((name != null) && name.getText().endsWith(".*")) { 88 boolean exempt = false; 89 for (int i = 0; (i < mExcludes.length) && !exempt; i++) { 90 if (name.getText().equals(mExcludes[i])) { 91 exempt = true; 92 } 93 } 94 if (!exempt) { 95 log(aAST.getLineNo(), "import.avoidStar", name.getText()); 96 } 97 } 98 } 99 } 100 | Popular Tags |