Added caseSensitive property to ImportOrder check (bug 842604).

This commit is contained in:
Oleg Sukhodolsky 2003-11-16 08:40:33 +00:00
parent 4d8c68ec20
commit c6bbd67749
6 changed files with 53 additions and 1 deletions

View File

@ -251,6 +251,12 @@
<td><a href="property_types.html#Boolean">Boolean</a></td>
<td>false</td>
</tr>
<tr>
<td>caseSensitive</td>
<td>whether strings comprision should be case sensitive or not</td>
<td><a href="property_types.html#Boolean">Boolean</a></td>
<td>true</td>
</tr>
</table>
<h4>Example</h4>

View File

@ -67,6 +67,10 @@
</p>
<ul>
<li class="body">Fixed grammar build process (request 827781).</li>
<li class="body">Added caseSensitive property to ImportOrder check
(bug 842604).</li>
</ul>
<p class="body">

View File

@ -36,6 +36,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* &lt;module name=&quot;ImportOrder&quot;>
* &lt;property name=&quot;groups&quot; value=&quot;java,javax&quot;/>
* &lt;property name=&quot;ordered&quot; value=&quot;true&quot;/>
* &lt;property name=&quot;caseSensitive&quot; value=&quot;false&quot;/>
* &lt;/module>
* </pre>
*
@ -64,6 +65,8 @@ public class ImportOrderCheck extends Check
/** Require imports in group be separated. */
private boolean mSeparated;
/** Should comprision be case sensitive. */
private boolean mCaseSensitive = true;
/** Last imported group. */
private int mLastGroup;
@ -125,6 +128,17 @@ public class ImportOrderCheck extends Check
mSeparated = aSeparated;
}
/**
* Sets whether strings comprision should be case sensitive
* or not.
* @param aCaseSensitive whether string comprition should be
* case sensitive.
*/
public void setCaseSensitive(boolean aCaseSensitive)
{
mCaseSensitive = aCaseSensitive;
}
/** {@inheritDoc} */
public int[] getDefaultTokens()
{
@ -186,7 +200,15 @@ public class ImportOrderCheck extends Check
}
else if (groupIdx == mLastGroup) {
if (mOrdered) {
if (mLastImport.compareTo(name) >= 0) {
boolean shouldFireError = false;
if (mCaseSensitive) {
shouldFireError = (mLastImport.compareTo(name) >= 0);
}
else {
shouldFireError =
(mLastImport.compareToIgnoreCase(name) >= 0);
}
if (shouldFireError) {
log(line, "import.ordering", name);
}
}

View File

@ -6,6 +6,9 @@ import java.awt.event.ActionEvent
import javax.swing.JComponent;
import javax.swing.JTable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
public class InputImportOrder {
}

View File

@ -0,0 +1,7 @@
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.Reader;
public class InputImportOrderCaseInsensitive {
}

View File

@ -43,4 +43,14 @@ public class ImportOrderCheckTest extends BaseCheckTestCase
verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder.java"), expected);
}
public void testCaseInsensitive() throws Exception
{
final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class);
checkConfig.addAttribute("caseSensitive", "false");
final String[] expected = {
};
verify(checkConfig, getPath("imports" + File.separator + "InputImportOrderCaseInsensitive.java"), expected);
}
}