forked from phoedos/pmd
Specialised BasicPropertyDescriptorFactory
This commit is contained in:
@ -43,10 +43,11 @@ public class EcmascriptParserOptions extends ParserOptions {
|
||||
}
|
||||
}
|
||||
|
||||
private static final String[] VERSION_LABELS = new String[] { Version.VERSION_DEFAULT.getLabel(),
|
||||
Version.VERSION_1_0.getLabel(), Version.VERSION_1_1.getLabel(), Version.VERSION_1_2.getLabel(),
|
||||
Version.VERSION_1_3.getLabel(), Version.VERSION_1_4.getLabel(), Version.VERSION_1_5.getLabel(),
|
||||
Version.VERSION_1_6.getLabel(), Version.VERSION_1_7.getLabel(), Version.VERSION_1_8.getLabel(), };
|
||||
private static final String[] VERSION_LABELS = {Version.VERSION_DEFAULT.getLabel(),
|
||||
Version.VERSION_1_0.getLabel(), Version.VERSION_1_1.getLabel(), Version.VERSION_1_2.getLabel(),
|
||||
Version.VERSION_1_3.getLabel(), Version.VERSION_1_4.getLabel(), Version.VERSION_1_5.getLabel(),
|
||||
Version.VERSION_1_6.getLabel(), Version.VERSION_1_7.getLabel(),
|
||||
Version.VERSION_1_8.getLabel(), };
|
||||
|
||||
// Note: The UI order values are chosen to be larger than those built into
|
||||
// XPathRule.
|
||||
@ -58,24 +59,22 @@ public class EcmascriptParserOptions extends ParserOptions {
|
||||
public static final EnumeratedProperty<Version> RHINO_LANGUAGE_VERSION = new EnumeratedProperty<>(
|
||||
"rhinoLanguageVersion",
|
||||
"Specifies the Rhino Language Version to use for parsing. Defaults to Rhino default.", VERSION_LABELS,
|
||||
Version.values(), 0, 5.0f);
|
||||
Version.values(), 0, Version.class, 5.0f);
|
||||
|
||||
private boolean recordingComments;
|
||||
private boolean recordingLocalJsDocComments;
|
||||
private Version rhinoLanguageVersion;
|
||||
|
||||
public EcmascriptParserOptions() {
|
||||
this.recordingComments = RECORDING_COMMENTS_DESCRIPTOR.defaultValue().booleanValue();
|
||||
this.recordingLocalJsDocComments = RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR.defaultValue().booleanValue();
|
||||
this.rhinoLanguageVersion = (Version) RHINO_LANGUAGE_VERSION
|
||||
.valueFrom((String) RHINO_LANGUAGE_VERSION.defaultValue());
|
||||
this.recordingComments = RECORDING_COMMENTS_DESCRIPTOR.defaultValue();
|
||||
this.recordingLocalJsDocComments = RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR.defaultValue();
|
||||
this.rhinoLanguageVersion = RHINO_LANGUAGE_VERSION.defaultValue();
|
||||
}
|
||||
|
||||
public EcmascriptParserOptions(Rule rule) {
|
||||
this.recordingComments = rule.getProperty(RECORDING_COMMENTS_DESCRIPTOR);
|
||||
this.recordingLocalJsDocComments = rule.getProperty(RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR);
|
||||
this.rhinoLanguageVersion = (Version) RHINO_LANGUAGE_VERSION
|
||||
.valueFrom((String) rule.getProperty(RHINO_LANGUAGE_VERSION));
|
||||
this.rhinoLanguageVersion = rule.getProperty(RHINO_LANGUAGE_VERSION);
|
||||
}
|
||||
|
||||
public boolean isRecordingComments() {
|
||||
|
@ -13,6 +13,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions.Version;
|
||||
import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.BooleanProperty;
|
||||
|
||||
@ -46,10 +47,10 @@ public class EcmascriptParserOptionsTest {
|
||||
rule.setProperty(EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR, false);
|
||||
assertFalse(((EcmascriptParserOptions) rule.getParserOptions()).isRecordingLocalJsDocComments());
|
||||
|
||||
rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, "default");
|
||||
rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, Version.VERSION_DEFAULT);
|
||||
assertEquals(EcmascriptParserOptions.Version.VERSION_DEFAULT,
|
||||
((EcmascriptParserOptions) rule.getParserOptions()).getRhinoLanguageVersion());
|
||||
rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, "1.8");
|
||||
rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, Version.VERSION_1_8);
|
||||
assertEquals(EcmascriptParserOptions.Version.VERSION_1_8,
|
||||
((EcmascriptParserOptions) rule.getParserOptions()).getRhinoLanguageVersion());
|
||||
}
|
||||
@ -66,8 +67,8 @@ public class EcmascriptParserOptionsTest {
|
||||
|
||||
@Test
|
||||
public void testEqualsHashcode() throws Exception {
|
||||
BooleanProperty[] properties = new BooleanProperty[] { EcmascriptParserOptions.RECORDING_COMMENTS_DESCRIPTOR,
|
||||
EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR, };
|
||||
BooleanProperty[] properties = {EcmascriptParserOptions.RECORDING_COMMENTS_DESCRIPTOR,
|
||||
EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR, };
|
||||
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
BooleanProperty property = properties[i];
|
||||
|
Reference in New Issue
Block a user