Remove usages of EnumeratedProperty

This commit is contained in:
Clément Fournier
2018-12-06 15:17:16 +01:00
parent 159095292c
commit 4962bc2831
6 changed files with 33 additions and 30 deletions

View File

@ -46,7 +46,7 @@ public class XPathRule extends AbstractRule {
tmp.put(XPATH_2_0, XPATH_2_0);
XPATH_VERSIONS = Collections.unmodifiableMap(tmp);
}
// published, can't be converted
public static final EnumeratedProperty<String> VERSION_DESCRIPTOR = EnumeratedProperty.<String>named("version")
.desc("XPath specification version")
.mappings(XPATH_VERSIONS)

View File

@ -24,6 +24,7 @@ import net.sourceforge.pmd.properties.SimpleEnumeratedPropertyTest.Foo;
*
* @author Brian Remedios
*/
@Deprecated
public class SimpleEnumeratedPropertyTest extends AbstractPropertyDescriptorTester<Foo> {
private static final String[] KEYS = {"bar", "na", "bee", "coo"};

View File

@ -23,8 +23,9 @@ import net.sourceforge.pmd.lang.java.ast.ASTName;
import net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode;
import net.sourceforge.pmd.lang.java.ast.AbstractJavaNode;
import net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSignature;
import net.sourceforge.pmd.properties.EnumeratedProperty;
import net.sourceforge.pmd.properties.EnumeratedProperty.EnumPBuilder;
import net.sourceforge.pmd.properties.PropertyBuilder.GenericPropertyBuilder;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
@ -36,27 +37,25 @@ public class CommentRequiredRule extends AbstractCommentRule {
private static final Map<String, String> DESCRIPTOR_NAME_TO_COMMENT_TYPE = new HashMap<>();
private static final EnumeratedProperty<CommentRequirement> ACCESSOR_CMT_DESCRIPTOR
private static final PropertyDescriptor<CommentRequirement> ACCESSOR_CMT_DESCRIPTOR
= requirementPropertyBuilder("accessorCommentRequirement", "Comments on getters and setters\"")
.defaultValue(CommentRequirement.Ignored).build();
private static final EnumeratedProperty<CommentRequirement> OVERRIDE_CMT_DESCRIPTOR
private static final PropertyDescriptor<CommentRequirement> OVERRIDE_CMT_DESCRIPTOR
= requirementPropertyBuilder("methodWithOverrideCommentRequirement", "Comments on @Override methods")
.defaultValue(CommentRequirement.Ignored).build();
private static final EnumeratedProperty<CommentRequirement> HEADER_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("headerCommentRequirement", "Header comments").uiOrder(1.0f).build();
private static final EnumeratedProperty<CommentRequirement> FIELD_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("fieldCommentRequirement", "Field comments").uiOrder(2.0f).build();
private static final EnumeratedProperty<CommentRequirement> PUB_METHOD_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("publicMethodCommentRequirement", "Public method and constructor comments")
.uiOrder(3.0f).build();
private static final EnumeratedProperty<CommentRequirement> PROT_METHOD_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("protectedMethodCommentRequirement", "Protected method constructor comments")
.uiOrder(4.0f).build();
private static final EnumeratedProperty<CommentRequirement> ENUM_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("enumCommentRequirement", "Enum comments").uiOrder(5.0f).build();
private static final EnumeratedProperty<CommentRequirement> SERIAL_VERSION_UID_CMT_REQUIREMENT_DESCRIPTOR
private static final PropertyDescriptor<CommentRequirement> HEADER_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("headerCommentRequirement", "Header comments").build();
private static final PropertyDescriptor<CommentRequirement> FIELD_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("fieldCommentRequirement", "Field comments").build();
private static final PropertyDescriptor<CommentRequirement> PUB_METHOD_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("publicMethodCommentRequirement", "Public method and constructor comments").build();
private static final PropertyDescriptor<CommentRequirement> PROT_METHOD_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("protectedMethodCommentRequirement", "Protected method constructor comments").build();
private static final PropertyDescriptor<CommentRequirement> ENUM_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("enumCommentRequirement", "Enum comments").build();
private static final PropertyDescriptor<CommentRequirement> SERIAL_VERSION_UID_CMT_REQUIREMENT_DESCRIPTOR
= requirementPropertyBuilder("serialVersionUIDCommentRequired", "Serial version UID comments")
.defaultValue(CommentRequirement.Ignored).uiOrder(6.0f).build();
.defaultValue(CommentRequirement.Ignored).build();
public CommentRequiredRule() {
@ -72,7 +71,7 @@ public class CommentRequiredRule extends AbstractCommentRule {
private void checkCommentMeetsRequirement(Object data, AbstractJavaNode node,
EnumeratedProperty<CommentRequirement> descriptor) {
PropertyDescriptor<CommentRequirement> descriptor) {
switch (getProperty(descriptor)) {
case Ignored:
break;
@ -94,7 +93,7 @@ public class CommentRequiredRule extends AbstractCommentRule {
// Adds a violation
private void commentRequiredViolation(Object data, AbstractJavaNode node,
EnumeratedProperty<CommentRequirement> descriptor) {
PropertyDescriptor<CommentRequirement> descriptor) {
addViolationWithMessage(data, node,
@ -242,12 +241,10 @@ public class CommentRequiredRule extends AbstractCommentRule {
// pre-filled builder
private static EnumPBuilder<CommentRequirement> requirementPropertyBuilder(String name, String commentType) {
private static GenericPropertyBuilder<CommentRequirement> requirementPropertyBuilder(String name, String commentType) {
DESCRIPTOR_NAME_TO_COMMENT_TYPE.put(name, commentType);
return EnumeratedProperty.<CommentRequirement>named(name)
return PropertyFactory.enumProperty(name, CommentRequirement.mappings())
.desc(commentType + ". Possible values: " + CommentRequirement.labels())
.mappings(CommentRequirement.mappings())
.defaultValue(CommentRequirement.Required)
.type(CommentRequirement.class);
.defaultValue(CommentRequirement.Required);
}
}

View File

@ -53,6 +53,10 @@ public class EcmascriptParserOptions extends ParserOptions {
// Note: The UI order values are chosen to be larger than those built into
// XPathRule.
// These aren't converted to the new property framework
// Do we need them anyway?
public static final BooleanProperty RECORDING_COMMENTS_DESCRIPTOR = new BooleanProperty("recordingComments",
"Specifies that comments are produced in the AST.", Boolean.TRUE, 3.0f);
public static final BooleanProperty RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR = new BooleanProperty(

View File

@ -12,6 +12,7 @@ import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions;
import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions.Version;
import net.sourceforge.pmd.lang.ecmascript.ast.ASTArrayComprehension;
import net.sourceforge.pmd.lang.ecmascript.ast.ASTArrayComprehensionLoop;
import net.sourceforge.pmd.lang.ecmascript.ast.ASTArrayLiteral;
@ -65,7 +66,6 @@ import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptNode;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParserVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
import net.sourceforge.pmd.lang.rule.ImmutableLanguage;
import net.sourceforge.pmd.properties.EnumeratedProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
@ -74,10 +74,11 @@ public abstract class AbstractEcmascriptRule extends AbstractRule
private static final PropertyDescriptor<Boolean> RECORDING_COMMENTS_DESCRIPTOR = EcmascriptParserOptions.RECORDING_COMMENTS_DESCRIPTOR;
private static final PropertyDescriptor<Boolean> RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR = EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR;
private static final EnumeratedProperty<EcmascriptParserOptions.Version> RHINO_LANGUAGE_VERSION = EcmascriptParserOptions.RHINO_LANGUAGE_VERSION;
private static final PropertyDescriptor<Version> RHINO_LANGUAGE_VERSION = EcmascriptParserOptions.RHINO_LANGUAGE_VERSION;
public AbstractEcmascriptRule() {
super.setLanguage(LanguageRegistry.getLanguage(EcmascriptLanguageModule.NAME));
// Rule-specific parser options are not supported. What do we do?
definePropertyDescriptor(RECORDING_COMMENTS_DESCRIPTOR);
definePropertyDescriptor(RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR);
definePropertyDescriptor(RHINO_LANGUAGE_VERSION);

View File

@ -8,8 +8,8 @@ import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions;
import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions.Version;
import net.sourceforge.pmd.lang.rule.XPathRule;
import net.sourceforge.pmd.properties.EnumeratedProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
@ -17,7 +17,7 @@ public class EcmascriptXPathRule extends XPathRule {
private static final PropertyDescriptor<Boolean> RECORDING_COMMENTS_DESCRIPTOR = EcmascriptParserOptions.RECORDING_COMMENTS_DESCRIPTOR;
private static final PropertyDescriptor<Boolean> RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR = EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR;
private static final EnumeratedProperty<EcmascriptParserOptions.Version> RHINO_LANGUAGE_VERSION = EcmascriptParserOptions.RHINO_LANGUAGE_VERSION;
private static final PropertyDescriptor<Version> RHINO_LANGUAGE_VERSION = EcmascriptParserOptions.RHINO_LANGUAGE_VERSION;
public EcmascriptXPathRule() {
super.setLanguage(LanguageRegistry.getLanguage(EcmascriptLanguageModule.NAME));