issue969: Fix upper/lower case conversation, enhance tests
This commit is contained in:
parent
9ea33d0720
commit
335d28b494
|
|
@ -98,20 +98,6 @@
|
|||
<!-- till #925 -->
|
||||
<Package name="~com\.puppycrawl\.tools\.checkstyle\.gui.*" />
|
||||
</Match>
|
||||
<Match>
|
||||
<!-- till #896 -->
|
||||
<Or>
|
||||
<Class name="com.puppycrawl.tools.checkstyle.api.Scope" />
|
||||
<Class name="com.puppycrawl.tools.checkstyle.api.SeverityLevel" />
|
||||
<Class name="com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck" />
|
||||
<Class name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck" />
|
||||
<Class name="com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder" />
|
||||
<Class name="com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck" />
|
||||
<Class name="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck" />
|
||||
<Class name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck" />
|
||||
</Or>
|
||||
<Bug pattern="DM_CONVERT_CASE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<!-- have never been a case for years, Eclipse does not show any other classes inherited from CommonASTWithHiddenTokens -->
|
||||
<Class name="com.puppycrawl.tools.checkstyle.api.DetailAST" />
|
||||
|
|
|
|||
|
|
@ -18,11 +18,14 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.api;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Represents a Java visibility scope.
|
||||
*
|
||||
* @author Lars Kühne
|
||||
* @author Travis Schneeberger
|
||||
* @author Mehmet Can Cömert
|
||||
*/
|
||||
public enum Scope
|
||||
{
|
||||
|
|
@ -50,7 +53,7 @@ public enum Scope
|
|||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name().toLowerCase();
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,6 +76,6 @@ public enum Scope
|
|||
*/
|
||||
public static Scope getInstance(String scopeName)
|
||||
{
|
||||
return valueOf(Scope.class, scopeName.trim().toUpperCase());
|
||||
return valueOf(Scope.class, scopeName.trim().toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.api;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Severity level for a check violation.
|
||||
|
|
@ -29,6 +31,7 @@ package com.puppycrawl.tools.checkstyle.api;
|
|||
*
|
||||
* @author David Schneider
|
||||
* @author Travis Schneeberger
|
||||
* @author Mehmet Can Cömert
|
||||
*/
|
||||
public enum SeverityLevel
|
||||
{
|
||||
|
|
@ -52,7 +55,7 @@ public enum SeverityLevel
|
|||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name().toLowerCase();
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -65,6 +68,6 @@ public enum SeverityLevel
|
|||
public static SeverityLevel getInstance(String securityLevelName)
|
||||
{
|
||||
return valueOf(SeverityLevel.class, securityLevelName.trim()
|
||||
.toUpperCase());
|
||||
.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.checks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
|
|
@ -60,7 +62,7 @@ public abstract class AbstractOptionCheck<T extends Enum<T>>
|
|||
public void setOption(String optionStr) throws ConversionException
|
||||
{
|
||||
try {
|
||||
option = Enum.valueOf(optionClass, optionStr.trim().toUpperCase());
|
||||
option = Enum.valueOf(optionClass, optionStr.trim().toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
throw new ConversionException("unable to parse " + option, iae);
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ package com.puppycrawl.tools.checkstyle.checks;
|
|||
|
||||
import com.google.common.io.Closeables;
|
||||
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
/**
|
||||
|
|
@ -108,7 +111,7 @@ public class NewlineAtEndOfFileCheck
|
|||
try {
|
||||
lineSeparator =
|
||||
Enum.valueOf(LineSeparatorOption.class, lineSeparatorParam.trim()
|
||||
.toUpperCase());
|
||||
.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
throw new ConversionException("unable to parse " + lineSeparatorParam,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package com.puppycrawl.tools.checkstyle.checks;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
|
|
@ -30,6 +29,7 @@ import org.apache.commons.beanutils.ConversionException;
|
|||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -136,7 +136,7 @@ public class SuppressWarningsHolder
|
|||
if (sourceName.endsWith(CHECK_SUFFIX)) {
|
||||
endIndex -= CHECK_SUFFIX.length();
|
||||
}
|
||||
return sourceName.substring(startIndex, endIndex).toLowerCase();
|
||||
return sourceName.substring(startIndex, endIndex).toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.checks.annotation;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
|
|
@ -217,7 +219,7 @@ public final class AnnotationUseStyleCheck extends Check
|
|||
final String string)
|
||||
{
|
||||
try {
|
||||
return Enum.valueOf(enuclass, string.trim().toUpperCase());
|
||||
return Enum.valueOf(enuclass, string.trim().toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (final IllegalArgumentException iae) {
|
||||
throw new ConversionException("unable to parse " + string, iae);
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
|||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.Utils;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
/**
|
||||
|
|
@ -414,7 +416,7 @@ public class HiddenFieldCheck
|
|||
if (name != null && (name.length() == 1
|
||||
|| name.length() > 1 && !Character.isUpperCase(name.charAt(1))))
|
||||
{
|
||||
setterName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
setterName = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1);
|
||||
}
|
||||
return setterName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,11 @@ import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
|||
import com.puppycrawl.tools.checkstyle.api.TextBlock;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -467,7 +469,7 @@ public class JavadocStyleCheck
|
|||
// Can't simply not put them on the stack, since singletons
|
||||
// like <dt> and <dd> (unhappily) may either be terminated
|
||||
// or not terminated. Both options are legal.
|
||||
return SINGLE_TAGS.contains(tag.getId().toLowerCase());
|
||||
return SINGLE_TAGS.contains(tag.getId().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -478,7 +480,7 @@ public class JavadocStyleCheck
|
|||
*/
|
||||
private boolean isAllowedTag(HtmlTag tag)
|
||||
{
|
||||
return ALLOWED_TAGS.contains(tag.getId().toLowerCase());
|
||||
return ALLOWED_TAGS.contains(tag.getId().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,8 +21,15 @@ package com.puppycrawl.tools.checkstyle.api;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test cases for {@link Scope} enumeration.
|
||||
* @author Mehmet Can Cömert
|
||||
*/
|
||||
public class ScopeTest
|
||||
{
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
|
@ -47,6 +54,22 @@ public class ScopeTest
|
|||
Scope.getInstance("AnonInner");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedCaseSpacesWithDifferentLocales()
|
||||
{
|
||||
Locale[] differentLocales = new Locale[] {new Locale("TR", "tr") };
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
for (Locale differentLocale : differentLocales) {
|
||||
Locale.setDefault(differentLocale);
|
||||
testMixedCaseSpaces();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsInAnonInner()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,8 +20,15 @@ package com.puppycrawl.tools.checkstyle.api;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test cases for {@link SeverityLevel} enumeration.
|
||||
* @author Mehmet Can Cömert
|
||||
*/
|
||||
public class SeverityLevelTest
|
||||
{
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
|
@ -43,4 +50,20 @@ public class SeverityLevelTest
|
|||
SeverityLevel.getInstance(" WarniNg");
|
||||
SeverityLevel.getInstance(" ERROR ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedCaseSpacesWithDifferentLocales()
|
||||
{
|
||||
Locale[] differentLocales = new Locale[] {new Locale("TR", "tr") };
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
for (Locale differentLocale : differentLocales) {
|
||||
Locale.setDefault(differentLocale);
|
||||
testMixedCaseSpaces();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue