Added caseSensitive property to ImportOrder check (bug 842604).
This commit is contained in:
parent
4d8c68ec20
commit
c6bbd67749
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* <module name="ImportOrder">
|
||||
* <property name="groups" value="java,javax"/>
|
||||
* <property name="ordered" value="true"/>
|
||||
* <property name="caseSensitive" value="false"/>
|
||||
* </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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
public class InputImportOrderCaseInsensitive {
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue