Refactored UTs, modifier package, issue #537

This commit is contained in:
alexkravin 2015-02-20 17:00:32 +04:00
parent 8ad4aebb66
commit 0b98c0389e
4 changed files with 52 additions and 25 deletions

View File

@ -65,6 +65,19 @@ import java.util.List;
public class ModifierOrderCheck
extends Check
{
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_ANNOTATION_ORDER = "annotation.order";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_MODIFIER_ORDER = "mod.order";
/**
* The order of modifiers as suggested in sections 8.1.1,
* 8.3.1 and 8.4.3 of the JLS.
@ -102,14 +115,14 @@ public class ModifierOrderCheck
if (error != null) {
if (error.getType() == TokenTypes.ANNOTATION) {
log(error.getLineNo(), error.getColumnNo(),
"annotation.order",
MSG_ANNOTATION_ORDER,
error.getFirstChild().getText()
+ error.getFirstChild().getNextSibling()
.getText());
}
else {
log(error.getLineNo(), error.getColumnNo(),
"mod.order", error.getText());
MSG_MODIFIER_ORDER, error.getText());
}
}
}

View File

@ -34,6 +34,13 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class RedundantModifierCheck
extends Check
{
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_KEY = "redundantModifier";
@Override
public int[] getDefaultTokens()
{
@ -77,7 +84,7 @@ public class RedundantModifierCheck
modifiers.findFirstToken(tokenType);
if (null != modifier) {
log(modifier.getLineNo(), modifier.getColumnNo(),
"redundantModifier", modifier.getText());
MSG_KEY, modifier.getText());
}
}
}
@ -99,7 +106,7 @@ public class RedundantModifierCheck
|| (type == TokenTypes.FINAL))
{
log(modifier.getLineNo(), modifier.getColumnNo(),
"redundantModifier", modifier.getText());
MSG_KEY, modifier.getText());
break;
}
@ -130,7 +137,7 @@ public class RedundantModifierCheck
final int type = modifier.getType();
if (type == TokenTypes.FINAL) {
log(modifier.getLineNo(), modifier.getColumnNo(),
"redundantModifier", modifier.getText());
MSG_KEY, modifier.getText());
break;
}
modifier = modifier.getNextSibling();

View File

@ -25,6 +25,11 @@ import org.junit.Test;
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import static com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck
.MSG_ANNOTATION_ORDER;
import static com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck
.MSG_MODIFIER_ORDER;
public class ModifierOrderCheckTest
extends BaseCheckTestSupport
{
@ -34,12 +39,12 @@ public class ModifierOrderCheckTest
final DefaultConfiguration checkConfig =
createCheckConfig(ModifierOrderCheck.class);
final String[] expected = {
"14:10: 'final' modifier out of order with the JLS suggestions.",
"18:12: 'private' modifier out of order with the JLS suggestions.",
"24:14: 'private' modifier out of order with the JLS suggestions.",
"34:13: '@MyAnnotation2' annotation modifier does not preceed non-annotation modifiers.",
"39:13: '@MyAnnotation2' annotation modifier does not preceed non-annotation modifiers.",
"49:35: '@MyAnnotation4' annotation modifier does not preceed non-annotation modifiers.",
"14:10: " + getCheckMessage(MSG_MODIFIER_ORDER, "final"),
"18:12: " + getCheckMessage(MSG_MODIFIER_ORDER, "private"),
"24:14: " + getCheckMessage(MSG_MODIFIER_ORDER, "private"),
"34:13: " + getCheckMessage(MSG_ANNOTATION_ORDER, "@MyAnnotation2"),
"39:13: " + getCheckMessage(MSG_ANNOTATION_ORDER, "@MyAnnotation2"),
"49:35: " + getCheckMessage(MSG_ANNOTATION_ORDER, "@MyAnnotation4"),
};
verify(checkConfig, getPath("InputModifier.java"), expected);
}

View File

@ -25,6 +25,8 @@ import org.junit.Test;
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import static com.puppycrawl.tools.checkstyle.checks.modifier.RedundantModifierCheck.MSG_KEY;
public class RedundantModifierTest
extends BaseCheckTestSupport
{
@ -34,20 +36,20 @@ public class RedundantModifierTest
final DefaultConfiguration checkConfig =
createCheckConfig(RedundantModifierCheck.class);
final String[] expected = {
"54:12: Redundant 'static' modifier.",
"57:9: Redundant 'public' modifier.",
"63:9: Redundant 'abstract' modifier.",
"66:9: Redundant 'public' modifier.",
"54:12: " + getCheckMessage(MSG_KEY, "static"),
"57:9: " + getCheckMessage(MSG_KEY, "public"),
"63:9: " + getCheckMessage(MSG_KEY, "abstract"),
"66:9: " + getCheckMessage(MSG_KEY, "public"),
//"69:9: Redundant 'abstract' modifier.",
"72:9: Redundant 'final' modifier.",
"79:13: Redundant 'final' modifier.",
"88:12: Redundant 'final' modifier.",
"99:1: Redundant 'abstract' modifier.",
"116:5: Redundant 'public' modifier.",
"117:5: Redundant 'final' modifier.",
"118:5: Redundant 'static' modifier.",
"120:5: Redundant 'public' modifier.",
"121:5: Redundant 'abstract' modifier.",
"72:9: " + getCheckMessage(MSG_KEY, "final"),
"79:13: " + getCheckMessage(MSG_KEY, "final"),
"88:12: " + getCheckMessage(MSG_KEY, "final"),
"99:1: " + getCheckMessage(MSG_KEY, "abstract"),
"116:5: " + getCheckMessage(MSG_KEY, "public"),
"117:5: " + getCheckMessage(MSG_KEY, "final"),
"118:5: " + getCheckMessage(MSG_KEY, "static"),
"120:5: " + getCheckMessage(MSG_KEY, "public"),
"121:5: " + getCheckMessage(MSG_KEY, "abstract"),
};
verify(checkConfig, getPath("InputModifier.java"), expected);
}
@ -73,7 +75,7 @@ public class RedundantModifierTest
final DefaultConfiguration checkConfig =
createCheckConfig(RedundantModifierCheck.class);
final String[] expected = {
"3:9: Redundant 'final' modifier.",
"3:9: " + getCheckMessage(MSG_KEY, "final"),
};
verify(checkConfig,
new File("src/test/resources-noncompilable/com/puppycrawl/tools/"