Start of a re-factor on the way options are set. Started on the easy

booleans. The downside of this approach is that is not 100% full-proof for the
plug-in developers. I think it is an acceptable compromise.
This commit is contained in:
Oliver Burn 2002-06-06 13:52:36 +00:00
parent 9ad235214f
commit 8af07e5dfd
3 changed files with 11 additions and 82 deletions

View File

@ -144,13 +144,7 @@ public class CheckStyleTask
/** @param aAllowed whether tabs are allowed **/
public void setAllowTabs(final boolean aAllowed)
{
mOptionMemory.add(new Runnable()
{
public void run()
{
mConfig.setAllowTabs(aAllowed);
}
});
setBooleanFlag(Defn.ALLOW_TABS_PROP, aAllowed);
}
/** @param aTabWidth number of spaces that are represented by one tab **/
@ -254,13 +248,7 @@ public class CheckStyleTask
*/
public void setIgnoreImportLen(final boolean aIgnore)
{
mOptionMemory.add(new Runnable()
{
public void run()
{
mConfig.setIgnoreImportLength(aIgnore);
}
});
setBooleanFlag(Defn.IGNORE_IMPORT_LENGTH_PROP, aIgnore);
}
/** @param aPat pattern for member variables **/
@ -447,13 +435,7 @@ public class CheckStyleTask
/** @param aIsRegexp whether to interpret header lines as regexp */
public void setHeaderLinesRegexp(final boolean aIsRegexp)
{
mOptionMemory.add(new Runnable()
{
public void run()
{
mConfig.setHeaderLinesRegexp(aIsRegexp);
}
});
setBooleanFlag(Defn.HEADER_LINES_REGEXP_PROP, aIsRegexp);
}
/** @param aList Comma separated list of line numbers **/

View File

@ -138,8 +138,6 @@ public class Configuration
private int mMaxConstructorLength = MAX_CONSTRUCTOR_LENGTH;
/** the maximum file length **/
private int mMaxFileLength = MAX_FILE_LENGTH;
/** whether to allow tabs **/
private boolean mAllowTabs = false;
/** the distance between tab stops **/
private int mTabWidth = TAB_WIDTH;
/** visibility scope where Javadoc is checked **/
@ -150,8 +148,6 @@ public class Configuration
private final HashSet mIllegalInstantiations = new HashSet();
/** name of the cache file **/
private String mCacheFile = null;
/** whether to ignore max line length of import statements **/
private boolean mIgnoreImportLength = false;
/** pattern to exclude from line lengh checking **/
private String mIgnoreLineLengthPat;
/** regexp to exclude from line length checking **/
@ -159,8 +155,6 @@ public class Configuration
/** the header lines to check for **/
private String[] mHeaderLines = {};
/** interpret the header lines as RE */
private boolean mHeaderLinesRegexp = false;
/** line numbers to ignore in header **/
private TreeSet mHeaderIgnoreLineNo = new TreeSet();
@ -225,7 +219,7 @@ public class Configuration
setMaxFileLength(getIntProperty(
aProps, aLog, MAX_FILE_LENGTH_PROP, MAX_FILE_LENGTH));
setAllowTabs(getBooleanProperty(aProps, ALLOW_TABS_PROP, mAllowTabs));
setBooleanFlag(aProps, ALLOW_TABS_PROP);
setTabWidth(getIntProperty(aProps, aLog, TAB_WIDTH_PROP, TAB_WIDTH));
setBooleanFlag(aProps, ALLOW_PROTECTED_PROP);
setBooleanFlag(aProps, ALLOW_PACKAGE_PROP);
@ -246,11 +240,9 @@ public class Configuration
setBooleanFlag(aProps, IGNORE_LONG_ELL_PROP);
setBooleanFlag(aProps, IGNORE_PUBLIC_IN_INTERFACE_PROP);
setCacheFile(aProps.getProperty(CACHE_FILE_PROP));
setIgnoreImportLength(getBooleanProperty(
aProps, IGNORE_IMPORT_LENGTH_PROP, mIgnoreImportLength));
setBooleanFlag(aProps, IGNORE_IMPORT_LENGTH_PROP);
setHeaderIgnoreLines(aProps.getProperty(HEADER_IGNORE_LINE_PROP));
setHeaderLinesRegexp(getBooleanProperty(
aProps, HEADER_LINES_REGEXP_PROP, mHeaderLinesRegexp));
setBooleanFlag(aProps, HEADER_LINES_REGEXP_PROP);
final String fname = aProps.getProperty(HEADER_FILE_PROP);
if (fname != null) {
@ -486,7 +478,7 @@ public class Configuration
/** @return whether to allow tabs **/
public boolean isAllowTabs()
{
return mAllowTabs;
return isFlagSet(ALLOW_TABS_PROP);
}
/** @return distance between tab stops */
@ -594,7 +586,7 @@ public class Configuration
/** @return whether to ignore max line length for import statements **/
public boolean isIgnoreImportLength()
{
return mIgnoreImportLength;
return isFlagSet(IGNORE_IMPORT_LENGTH_PROP);
}
/** @return the header lines to check for **/
@ -607,7 +599,7 @@ public class Configuration
/** @return if lines in header file are regular expressions */
public boolean getHeaderLinesRegexp()
{
return mHeaderLinesRegexp;
return isFlagSet(HEADER_LINES_REGEXP_PROP);
}
/**
@ -771,14 +763,6 @@ public class Configuration
mMaxFileLength = aMaxFileLength;
}
/**
* @param aIgnoreImportLength whether to allow tabs
*/
public void setIgnoreImportLength(boolean aIgnoreImportLength)
{
mIgnoreImportLength = aIgnoreImportLength;
}
/**
* @param aPkgPrefixList comma separated list of package prefixes
*/
@ -803,14 +787,6 @@ public class Configuration
}
}
/**
* @param aAllowTabs whether to allow tabs
*/
public void setAllowTabs(boolean aAllowTabs)
{
mAllowTabs = aAllowTabs;
}
/** @param aTabWidth distance between tab stops */
public void setTabWidth(int aTabWidth)
{
@ -861,14 +837,6 @@ public class Configuration
mHeaderLines = (String[]) lines.toArray(new String[0]);
}
/**
* @param aHeaderLinesRegexp lines in header file are regular expressions
*/
public void setHeaderLinesRegexp(boolean aHeaderLinesRegexp)
{
mHeaderLinesRegexp = aHeaderLinesRegexp;
}
/**
* @param aList comma separated list of line numbers to ignore in header.
*/
@ -1022,27 +990,6 @@ public class Configuration
return retVal;
}
/**
* @param aProps the properties set to use
* @param aName the name of the property to parse
* @param aDefault the default value to use.
* @return the value of an boolean property. If the property is not defined
* or cannot be parsed, then a default value is returned.
*/
private static boolean getBooleanProperty(Properties aProps,
String aName,
boolean aDefault)
{
boolean retVal = aDefault;
String strRep = aProps.getProperty(aName);
if (strRep != null) {
strRep = strRep.toLowerCase().trim();
retVal = strRep.equals("true") || strRep.equals("yes")
|| strRep.equals("on");
}
return retVal;
}
/**
* @param aProps the properties set to use
* @param aLog where to log errors to

View File

@ -632,7 +632,7 @@ public class CheckerTest
throws Exception
{
final Checker c = createChecker();
mConfig.setHeaderLinesRegexp(true);
mConfig.setBooleanFlag(Defn.HEADER_LINES_REGEXP_PROP, true);
mConfig.setHeaderFile(getPath("regexp.header"));
mConfig.setHeaderIgnoreLines("4,5");
final String filepath = getPath("InputScopeAnonInner.java");
@ -654,7 +654,7 @@ public class CheckerTest
public void testImport()
throws Exception
{
mConfig.setIgnoreImportLength(true);
mConfig.setBooleanFlag(Defn.IGNORE_IMPORT_LENGTH_PROP, true);
final Checker c = createChecker();
final String filepath = getPath("InputImport.java");
assertNotNull(c);