1 package com.puppycrawl.tools.checkstyle.checks; 20 21 import com.puppycrawl.tools.checkstyle.api.Check; 22 import com.puppycrawl.tools.checkstyle.api.Utils; 23 24 import java.util.regex.Pattern ; 25 import java.util.regex.PatternSyntaxException ; 26 27 import org.apache.commons.beanutils.ConversionException; 28 29 38 public abstract class AbstractFormatCheck 39 extends Check 40 { 41 42 private int mCompileFlags; 43 44 private Pattern mRegexp; 45 46 private String mFormat; 47 48 54 public AbstractFormatCheck(String aDefaultFormat) 55 throws ConversionException 56 { 57 this(aDefaultFormat, 0); 58 } 59 60 67 public AbstractFormatCheck(String aDefaultFormat, int aCompileFlags) 68 throws ConversionException 69 { 70 updateRegexp(aDefaultFormat, aCompileFlags); 71 } 72 73 78 public final void setFormat(String aFormat) 79 throws ConversionException 80 { 81 updateRegexp(aFormat, mCompileFlags); 82 } 83 84 88 public final void setCompileFlags(int aCompileFlags) 89 { 90 updateRegexp(mFormat, aCompileFlags); 91 } 92 93 94 public final Pattern getRegexp() 95 { 96 return mRegexp; 97 } 98 99 100 public final String getFormat() 101 { 102 return mFormat; 103 } 104 105 111 private void updateRegexp(String aFormat, int aCompileFlags) 112 { 113 try { 114 mRegexp = Utils.getPattern(aFormat, aCompileFlags); 115 mFormat = aFormat; 116 mCompileFlags |= aCompileFlags; 117 } 118 catch (final PatternSyntaxException e) { 119 throw new ConversionException("unable to parse " + aFormat, e); 120 } 121 } 122 } 123 | Popular Tags |