Skip to content

Commit

Permalink
Rename severity to level
Browse files Browse the repository at this point in the history
  • Loading branch information
takahi-i committed Aug 23, 2017
1 parent d7ea419 commit 40b5719
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void extractValidatorConfigurations(ConfigurationBuilder configBuilder,
validatorConfigurations.put(currentValidatorName, currentConfiguration);
NodeList propertyElementList = nNode.getChildNodes();
extractProperties(currentConfiguration, propertyElementList);
extractSeverity(currentConfiguration, element);
extractLevel(currentConfiguration, element);
} else {
LOG.warn("Invalid block: \"" + element.getNodeName() + "\"");
LOG.warn("Skip this block ...");
Expand All @@ -242,10 +242,10 @@ private void extractValidatorConfigurations(ConfigurationBuilder configBuilder,
validatorConfigurations.values().forEach(configBuilder::addValidatorConfig);
}

private void extractSeverity(ValidatorConfiguration currentConfiguration, Element element) {
private void extractLevel(ValidatorConfiguration currentConfiguration, Element element) {
String level = element.getAttribute("level");
if (level == null || level.length() == 0) return;
currentConfiguration.setSeverity(level);
currentConfiguration.setLevel(level);
}

private void extractProperties(ValidatorConfiguration currentConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ValidatorConfiguration implements Serializable, Cloneable {
/**
* Define how severe the validation errors are.
*/
public enum SEVERITY {
public enum LEVEL {
INFO, WARN, ERROR;

Map<String, String> mapping = new HashMap<String, String>() {
Expand All @@ -48,7 +48,7 @@ public String toString() {

private final String configurationName;
private Map<String, String> properties;
private SEVERITY severity = SEVERITY.ERROR;
private LEVEL level = LEVEL.ERROR;

/**
* @param name name configuration settings
Expand All @@ -61,17 +61,17 @@ public ValidatorConfiguration(String name) {
* @param name name configuration settings
* @param properties validator properties
*/
public ValidatorConfiguration(String name, Map<String, String> properties) { this(name, properties, SEVERITY.ERROR); }
public ValidatorConfiguration(String name, Map<String, String> properties) { this(name, properties, LEVEL.ERROR); }

/**
* @param name name configuration settings
* @param properties validator properties
* @param severity error level
* @param level error level
*/
public ValidatorConfiguration(String name, Map<String, String> properties, SEVERITY severity) {
public ValidatorConfiguration(String name, Map<String, String> properties, LEVEL level) {
this.configurationName = name;
this.properties = properties;
this.severity = severity;
this.level = level;
}

/**
Expand Down Expand Up @@ -106,25 +106,25 @@ public String getConfigurationName() {
* Get error level.
* @return error level
*/
public SEVERITY getSeverity() {
return severity;
public LEVEL getLevel() {
return level;
}

/**
* Set error level.
* @param severity error level
* @param level error level
*/
public ValidatorConfiguration setSeverity(String severity) {
public ValidatorConfiguration setLevel(String level) {
try {
setSeverity(SEVERITY.valueOf(severity.toUpperCase()));
setLevel(LEVEL.valueOf(level.toUpperCase()));
} catch (IllegalArgumentException e) {
throw new RuntimeException("No such a error level as " + severity, e);
throw new RuntimeException("No such a error level as " + level, e);
}
return this;
}

public ValidatorConfiguration setSeverity(SEVERITY severity) {
this.severity = severity;
public ValidatorConfiguration setLevel(LEVEL level) {
this.level = level;
return this;
}

Expand Down Expand Up @@ -160,7 +160,7 @@ public ValidatorConfiguration addAttribute(String name, Object value) {
ValidatorConfiguration that = (ValidatorConfiguration)o;
return Objects.equals(configurationName, that.configurationName) &&
Objects.equals(properties, that.properties) &&
Objects.equals(severity, that.severity);
Objects.equals(level, that.level);
}

@Override public int hashCode() {
Expand All @@ -178,7 +178,7 @@ public ValidatorConfiguration addAttribute(String name, Object value) {
try {
ValidatorConfiguration clone = (ValidatorConfiguration)super.clone();
clone.properties = new HashMap<>(properties);
clone.severity = severity;
clone.level = level;
return clone;
}
catch (CloneNotSupportedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ValidationError implements Serializable {
private final Sentence sentence;
private final LineOffset startPosition;
private final LineOffset endPosition;
private final ValidatorConfiguration.SEVERITY level;
private final ValidatorConfiguration.LEVEL level;

/**
* Constructor.
Expand All @@ -47,7 +47,7 @@ public class ValidationError implements Serializable {
public ValidationError(String validatorName,
String errorMessage,
Sentence sentenceWithError) {
this(validatorName, errorMessage, sentenceWithError, ValidatorConfiguration.SEVERITY.ERROR);
this(validatorName, errorMessage, sentenceWithError, ValidatorConfiguration.LEVEL.ERROR);
}

/**
Expand All @@ -60,7 +60,7 @@ public ValidationError(String validatorName,
public ValidationError(String validatorName,
String errorMessage,
Sentence sentenceWithError,
ValidatorConfiguration.SEVERITY level) {
ValidatorConfiguration.LEVEL level) {
this.message = errorMessage;
this.validatorName = validatorName;;
this.sentence = sentenceWithError;
Expand All @@ -80,7 +80,7 @@ public ValidationError(String validatorName,
*/
ValidationError(String validatorName, String errorMessage, Sentence sentenceWithError,
int startPosition, int endPosition) {
this(validatorName, errorMessage, sentenceWithError, startPosition, endPosition, ValidatorConfiguration.SEVERITY.ERROR);
this(validatorName, errorMessage, sentenceWithError, startPosition, endPosition, ValidatorConfiguration.LEVEL.ERROR);
}

/**
Expand All @@ -94,7 +94,7 @@ public ValidationError(String validatorName,
*/
ValidationError(String validatorName, String errorMessage, Sentence sentenceWithError,
int startPosition, int endPosition,
ValidatorConfiguration.SEVERITY level) {
ValidatorConfiguration.LEVEL level) {
this.message = errorMessage;
this.validatorName = validatorName;
this.sentence = sentenceWithError;
Expand All @@ -120,7 +120,7 @@ public ValidationError(String validatorName,
this.sentence = sentenceWithError;
this.startPosition = startPosition;
this.endPosition = endPosition;
this.level = ValidatorConfiguration.SEVERITY.ERROR;
this.level = ValidatorConfiguration.LEVEL.ERROR;
}

/**
Expand Down Expand Up @@ -195,7 +195,7 @@ public Optional<LineOffset> getEndPosition() {
* Get error level.
* @return error level
*/
public ValidatorConfiguration.SEVERITY getLevel() {
public ValidatorConfiguration.LEVEL getLevel() {
return level;
}

Expand Down
18 changes: 9 additions & 9 deletions redpen-core/src/main/java/cc/redpen/validator/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ protected File findFile(String relativePath) throws RedPenException {
return globalConfig.findFile(relativePath);
}

protected ValidatorConfiguration.SEVERITY getSeverity() {
protected ValidatorConfiguration.LEVEL getLevel() {
if( config == null) {
return ValidatorConfiguration.SEVERITY.ERROR;
return ValidatorConfiguration.LEVEL.ERROR;
}
return config.getSeverity();
return config.getLevel();
}

/**
Expand All @@ -352,7 +352,7 @@ protected ValidatorConfiguration.SEVERITY getSeverity() {
* @param sentenceWithError sentence
*/
protected void addError(String message, Sentence sentenceWithError) {
errors.add(new ValidationError(this.validatorName, message, sentenceWithError, getSeverity()));
errors.add(new ValidationError(this.validatorName, message, sentenceWithError, getLevel()));
}

/**
Expand All @@ -365,7 +365,7 @@ protected void addError(String message, Sentence sentenceWithError) {
*/
protected void addErrorWithPosition(String message, Sentence sentenceWithError,
int start, int end) {
errors.add(new ValidationError(this.validatorName, message, sentenceWithError, start, end, getSeverity()));
errors.add(new ValidationError(this.validatorName, message, sentenceWithError, start, end, getLevel()));
}

/**
Expand All @@ -375,7 +375,7 @@ protected void addErrorWithPosition(String message, Sentence sentenceWithError,
* @param args objects to format
*/
protected void addLocalizedError(Sentence sentenceWithError, Object... args) {
errors.add(new ValidationError(this.validatorName, getLocalizedErrorMessage(null, args), sentenceWithError, getSeverity()));
errors.add(new ValidationError(this.validatorName, getLocalizedErrorMessage(null, args), sentenceWithError, getLevel()));
}

/**
Expand All @@ -386,7 +386,7 @@ protected void addLocalizedError(Sentence sentenceWithError, Object... args) {
* @param args objects to format
*/
protected void addLocalizedError(String messageKey, Sentence sentenceWithError, Object... args) {
errors.add(new ValidationError(this.validatorName, getLocalizedErrorMessage(messageKey, args), sentenceWithError, getSeverity()));
errors.add(new ValidationError(this.validatorName, getLocalizedErrorMessage(messageKey, args), sentenceWithError, getLevel()));
}

/**
Expand All @@ -401,7 +401,7 @@ protected void addLocalizedErrorFromToken(Sentence sentenceWithError, TokenEleme
token.getOffset(),
token.getOffset() + token.getSurface().length(),
token.getSurface(),
getSeverity()
getLevel()
);
}

Expand Down Expand Up @@ -429,7 +429,7 @@ protected void addLocalizedErrorWithPosition(Sentence sentenceWithError,
*/
protected void addLocalizedErrorWithPosition(String messageKey, Sentence sentenceWithError,
int start, int end, Object... args) {
errors.add(new ValidationError(this.validatorName, getLocalizedErrorMessage(messageKey, args), sentenceWithError, start, end, getSeverity()));
errors.add(new ValidationError(this.validatorName, getLocalizedErrorMessage(messageKey, args), sentenceWithError, start, end, getLevel()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109626,8 +109626,8 @@ severeness's
severer
severest
severing
severity
severity's
level
level's
Severn
Severn's
severs
Expand Down Expand Up @@ -137162,4 +137162,4 @@ Zyuganov's
Zzz
AsciiDoc
Asciidoctor
Re:VIEW
Re:VIEW
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ public void testValidatorConfigurationWithErrorLevel() throws RedPenException {
assertEquals(1, configuration.getValidatorConfigs().size());
assertEquals("SentenceLength",
configuration.getValidatorConfigs().get(0).getConfigurationName());
assertEquals(ValidatorConfiguration.SEVERITY.INFO,
configuration.getValidatorConfigs().get(0).getSeverity());
assertEquals(ValidatorConfiguration.LEVEL.INFO,
configuration.getValidatorConfigs().get(0).getLevel());
}

@Test(expected = RuntimeException.class)
Expand Down Expand Up @@ -494,6 +494,6 @@ public void testSpecifiedErrorLevelComeInErrors() throws RedPenException {
RedPen redPen = new RedPen(config);
Map<Document, List<ValidationError>> errors = redPen.validate(documents);
assertEquals(1, errors.get(documents.get(0)).size());
assertEquals(ValidatorConfiguration.SEVERITY.INFO, errors.get(documents.get(0)).get(0).getLevel());
assertEquals(ValidatorConfiguration.LEVEL.INFO, errors.get(documents.get(0)).get(0).getLevel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public void canBeCloned() throws Exception {
assertEquals(conf.getProperties(), clone.getProperties());

assertNotSame(conf.getProperties(), clone.getProperties());
assertEquals(conf.getSeverity(), clone.getSeverity());
assertEquals(conf.getLevel(), clone.getLevel());
}

@Test
public void equals() throws Exception {
ValidatorConfiguration conf = new ValidatorConfiguration("test").addProperty("foo", "bar").setSeverity(ValidatorConfiguration.SEVERITY.ERROR);
ValidatorConfiguration conf2 = new ValidatorConfiguration("test").addProperty("foo", "bar").setSeverity(ValidatorConfiguration.SEVERITY.ERROR);
ValidatorConfiguration conf = new ValidatorConfiguration("test").addProperty("foo", "bar").setLevel(ValidatorConfiguration.LEVEL.ERROR);
ValidatorConfiguration conf2 = new ValidatorConfiguration("test").addProperty("foo", "bar").setLevel(ValidatorConfiguration.LEVEL.ERROR);
assertEquals(conf, conf2);
}

Expand All @@ -44,8 +44,8 @@ public void equals_names() throws Exception {

@Test
public void equals_levels() throws Exception {
ValidatorConfiguration conf = new ValidatorConfiguration("test").setSeverity(ValidatorConfiguration.SEVERITY.INFO);
ValidatorConfiguration conf2 = new ValidatorConfiguration("test2").setSeverity(ValidatorConfiguration.SEVERITY.INFO);;
ValidatorConfiguration conf = new ValidatorConfiguration("test").setLevel(ValidatorConfiguration.LEVEL.INFO);
ValidatorConfiguration conf2 = new ValidatorConfiguration("test2").setLevel(ValidatorConfiguration.LEVEL.INFO);;
assertFalse(conf.equals(conf2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testFormatDocumentsSettingErrorLevel() throws RedPenException, JSONE
String sampleText = "This is a good day。"; // invalid end of sentence symbol
Configuration conf = Configuration.builder().build();
Configuration configuration = Configuration.builder()
.addValidatorConfig(new ValidatorConfiguration("InvalidSymbol").setSeverity(ValidatorConfiguration.SEVERITY.INFO))
.addValidatorConfig(new ValidatorConfiguration("InvalidSymbol").setLevel(ValidatorConfiguration.LEVEL.INFO))
.build();

List<Document> documents = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void testFormatDocumentsSettingErrorLevel() throws RedPenException, JSONE
String sampleText = "This is a good day。"; // invalid end of sentence symbol
Configuration conf = Configuration.builder().build();
Configuration configuration = Configuration.builder()
.addValidatorConfig(new ValidatorConfiguration("InvalidSymbol").setSeverity(ValidatorConfiguration.SEVERITY.INFO))
.addValidatorConfig(new ValidatorConfiguration("InvalidSymbol").setLevel(ValidatorConfiguration.LEVEL.INFO))
.build();

List<Document> documents = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testConvertValidationErrorWithoutFileName() {
@Test
public void testConvertValidationErrorChangingErrorLevel() throws RedPenException {
Configuration config = Configuration.builder()
.addValidatorConfig(new ValidatorConfiguration("SentenceLength").setSeverity(ValidatorConfiguration.SEVERITY.INFO)).build();
.addValidatorConfig(new ValidatorConfiguration("SentenceLength").setLevel(ValidatorConfiguration.LEVEL.INFO)).build();
Validator validator = ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config);
Sentence sentence = new Sentence("This is a long long long long long long long long long long long long" +
" long long long long long long long long long long long long long long long long long long long long sentence", 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void testConvertedValidationErrorChangingLevel() throws RedPenException {
String sampleText = "This is a good day。\n"; // invalid end of sentence symbol
Configuration conf = Configuration.builder().build();
Configuration configuration = Configuration.builder()
.addValidatorConfig(new ValidatorConfiguration("InvalidSymbol").setSeverity(ValidatorConfiguration.SEVERITY.INFO))
.addValidatorConfig(new ValidatorConfiguration("InvalidSymbol").setLevel(ValidatorConfiguration.LEVEL.INFO))
.build();

List<cc.redpen.model.Document> documents = new ArrayList<>();
Expand Down

0 comments on commit 40b5719

Please sign in to comment.