Skip to content

Commit 17e7f25

Browse files
committed
Merge pull request #75 from adangel:update-pmd-core-7.0.0-SNAPSHOT
Update to PMD 7.0.0-SNAPSHOT (upcoming 7.0.0-rc4) #75
2 parents 7fbef10 + fd24676 commit 17e7f25

File tree

8 files changed

+55
-37
lines changed

8 files changed

+55
-37
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Next
44

5-
* **Bump required pmd-core version to 7.0.0-rc3.**
5+
* **Bump required pmd-core version to 7.0.0-rc4.**
66

77
**Fixed issues:**
88

@@ -17,6 +17,7 @@
1717
* [#69](https://github.com/pmd/pmd-designer/pull/69) Perform the persistence asynchronously to not block the main (UI) thread #69 by [@adangel](https://github.com/adangel)
1818
* [#70](https://github.com/pmd/pmd-designer/pull/70) Fix drag and drop for tests case violations by [@adangel](https://github.com/adangel)
1919
* [#74](https://github.com/pmd/pmd-designer/pull/74) Remove commons-io by [@adangel](https://github.com/adangel)
20+
* [#75](https://github.com/pmd/pmd-designer/pull/75) Update to PMD 7.0.0-SNAPSHOT (upcoming 7.0.0-rc4) by [@adangel](https://github.com/adangel)
2021

2122
See https://github.com/pmd/pmd-designer/milestone/11
2223

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</developers>
5555

5656
<properties>
57-
<pmd.core.version>7.0.0-rc3</pmd.core.version>
57+
<pmd.core.version>7.0.0-SNAPSHOT</pmd.core.version>
5858
<openjfx.version>11.0.2</openjfx.version>
5959
<java.version>8</java.version>
6060
<kotlin.version>1.7.20</kotlin.version>

src/main/java/net/sourceforge/pmd/util/fxdesigner/model/PropertyDescriptorSpec.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
package net.sourceforge.pmd.util.fxdesigner.model;
66

77

8-
import java.util.HashMap;
9-
import java.util.Map;
10-
118
import org.reactfx.EventStream;
129
import org.reactfx.value.Val;
1310
import org.reactfx.value.Var;
1411

12+
import net.sourceforge.pmd.properties.NumericConstraints;
13+
import net.sourceforge.pmd.properties.PropertyBuilder;
1514
import net.sourceforge.pmd.properties.PropertyDescriptor;
16-
import net.sourceforge.pmd.properties.PropertyDescriptorField;
1715
import net.sourceforge.pmd.properties.PropertyTypeId;
18-
import net.sourceforge.pmd.properties.builders.PropertyDescriptorExternalBuilder;
1916
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsOwner;
2017
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsPersistenceUtil.PersistentProperty;
2118

@@ -40,8 +37,35 @@ public class PropertyDescriptorSpec implements SettingsOwner {
4037

4138

4239
public PropertyDescriptorSpec() {
43-
isNumerical = typeId.map(PropertyTypeId::isPropertyNumeric);
44-
isMultivalue = typeId.map(PropertyTypeId::isPropertyMultivalue);
40+
isNumerical = typeId.map(this::isPropertyNumeric);
41+
isMultivalue = typeId.map(this::isPropertyMultivalue);
42+
}
43+
44+
private Boolean isPropertyMultivalue(PropertyTypeId propertyTypeId) {
45+
switch (propertyTypeId) {
46+
case DOUBLE_LIST:
47+
case LONG_LIST:
48+
case STRING_LIST:
49+
case INTEGER_LIST:
50+
case CHARACTER_LIST:
51+
return true;
52+
default:
53+
return false;
54+
}
55+
}
56+
57+
private Boolean isPropertyNumeric(PropertyTypeId propertyTypeId) {
58+
switch (propertyTypeId) {
59+
case LONG:
60+
case DOUBLE:
61+
case INTEGER:
62+
case LONG_LIST:
63+
case DOUBLE_LIST:
64+
case INTEGER_LIST:
65+
return true;
66+
default:
67+
return false;
68+
}
4569
}
4670

4771

@@ -161,20 +185,19 @@ public PropertyDescriptorSpec deepCopy() {
161185
* @return the descriptor if it can be built
162186
*/
163187
public PropertyDescriptor<?> build() {
164-
PropertyDescriptorExternalBuilder<?> externalBuilder = getTypeId().getFactory();
165-
Map<PropertyDescriptorField, String> values = new HashMap<>();
166-
values.put(PropertyDescriptorField.NAME, getName());
167-
values.put(PropertyDescriptorField.DEFAULT_VALUE, getValue());
168-
values.put(PropertyDescriptorField.DESCRIPTION, getDescription());
169-
values.put(PropertyDescriptorField.MIN, "-2000000");
170-
values.put(PropertyDescriptorField.MAX, "+2000000");
171-
172-
return externalBuilder.build(values);
188+
PropertyBuilder propertyBuilder = getTypeId().getBuilderUtils().newBuilder(getName());
189+
Object defaultValue = getTypeId().getBuilderUtils().getXmlMapper().fromString(getValue());
190+
propertyBuilder.desc(getDescription());
191+
propertyBuilder.defaultValue(defaultValue);
192+
if (isPropertyNumeric(getTypeId())) {
193+
propertyBuilder.require(NumericConstraints.inRange(-2_000_000, +2_000_000));
194+
}
195+
return propertyBuilder.build();
173196
}
174197

175198

176199
Object parseValue() {
177-
return build().valueFrom(getValue());
200+
return getTypeId().getBuilderUtils().getXmlMapper().fromString(getValue());
178201
}
179202

180203

src/main/java/net/sourceforge/pmd/util/fxdesigner/model/XPathEvaluator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public static List<Node> evaluateQuery(Node compilationUnit,
8787
Map<String, PropertyDescriptor<?>> descriptors = properties.stream().collect(Collectors.toMap(PropertyDescriptorSpec::getName, PropertyDescriptorSpec::build));
8888
// Take in all set values or defaults
8989
Map<PropertyDescriptor<?>, Object> allProperties =
90-
descriptors.entrySet().stream()
91-
.collect(Collectors.<Entry<String, PropertyDescriptor<?>>, PropertyDescriptor<?>, Object>toMap(e -> e.getValue(), e -> propertyValues.containsKey(e.getKey()) ? e.getValue().valueFrom(propertyValues.get(e.getKey())) : e.getValue().defaultValue()));
90+
descriptors.entrySet().stream()
91+
.collect(Collectors.<Entry<String, PropertyDescriptor<?>>, PropertyDescriptor<?>, Object>toMap(
92+
e -> e.getValue(), e -> propertyValues.containsKey(e.getKey()) ? e.getValue().serializer().fromString(propertyValues.get(e.getKey())) : e.getValue().defaultValue()));
9293

9394
SaxonXPathRuleQuery xpathRule =
9495
new SaxonXPathRuleQuery(

src/main/java/net/sourceforge/pmd/util/fxdesigner/model/export/LiveTreeRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public String dumpSubtree(Node n) throws Exception {
8686

8787

8888
private static <T> String getValueAsString(PropertyDescriptor<T> d) {
89-
return d.asDelimitedString(d.defaultValue());
89+
return d.serializer().toString(d.defaultValue());
9090
}
9191

9292
private static <T> void setProperty(PropertySource bundle, PropertyDescriptor<T> d, String value) {
93-
bundle.setProperty(d, d.valueFrom(value));
93+
bundle.setProperty(d, d.serializer().fromString(value));
9494
}
9595
}

src/main/java/net/sourceforge/pmd/util/fxdesigner/popups/EditPropertyDialogController.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package net.sourceforge.pmd.util.fxdesigner.popups;
66

7-
import static net.sourceforge.pmd.properties.MultiValuePropertyDescriptor.DEFAULT_DELIMITER;
8-
import static net.sourceforge.pmd.properties.MultiValuePropertyDescriptor.DEFAULT_NUMERIC_DELIMITER;
97
import static net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil.rewireInit;
108

119
import java.net.URL;
@@ -20,9 +18,8 @@
2018
import org.reactfx.util.Try;
2119
import org.reactfx.value.Var;
2220

21+
import net.sourceforge.pmd.properties.PropertySerializer;
2322
import net.sourceforge.pmd.properties.PropertyTypeId;
24-
import net.sourceforge.pmd.properties.ValueParser;
25-
import net.sourceforge.pmd.properties.ValueParserConstants;
2623
import net.sourceforge.pmd.util.fxdesigner.app.ApplicationComponent;
2724
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
2825
import net.sourceforge.pmd.util.fxdesigner.model.PropertyDescriptorSpec;
@@ -141,20 +138,15 @@ private void registerBasicValidators() {
141138
private void registerTypeDependentValidators(PropertyTypeId typeId) {
142139
Validator<String> valueValidator = (c, val) ->
143140
ValidationResult.fromErrorIf(valueField, "The value couldn't be parsed",
144-
Try.tryGet(() -> getValueParser(typeId).valueOf(getValue())).isFailure());
141+
Try.tryGet(() -> getValueParser(typeId).fromString(getValue())).isFailure());
145142

146143

147144
validationSupport.registerValidator(valueField, valueValidator);
148145
}
149146

150147

151-
private ValueParser<?> getValueParser(PropertyTypeId typeId) {
152-
ValueParser<?> parser = typeId.getValueParser();
153-
if (typeId.isPropertyMultivalue()) {
154-
char delimiter = typeId.isPropertyNumeric() ? DEFAULT_NUMERIC_DELIMITER : DEFAULT_DELIMITER;
155-
parser = ValueParserConstants.multi(parser, delimiter);
156-
}
157-
return parser;
148+
private PropertySerializer<?> getValueParser(PropertyTypeId typeId) {
149+
return typeId.getBuilderUtils().getXmlMapper();
158150
}
159151

160152

src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AuxLanguageRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static boolean isXmlDialect(Language language) {
7575
}
7676
}
7777

78-
public static Language plainTextLanguage() {
78+
public static PlainTextLanguage plainTextLanguage() {
7979
return PlainTextLanguage.getInstance();
8080
}
8181

src/test/kotlin/net/sourceforge/pmd/util/fxdesigner/util/codearea/PlainTextLanguageTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.kotest.matchers.shouldBe
1010
import io.kotest.matchers.shouldNotBe
1111
import net.sourceforge.pmd.lang.LanguageProcessorRegistry
1212
import net.sourceforge.pmd.lang.PlainTextLanguage.PlainTextFile
13+
import net.sourceforge.pmd.lang.PmdCapableLanguage
1314
import net.sourceforge.pmd.lang.ast.Parser
1415
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter
1516
import net.sourceforge.pmd.lang.ast.test.IntelliMarker
@@ -54,7 +55,7 @@ class PlainTextLanguageTest : IntelliMarker, FunSpec({
5455
})
5556

5657
private fun String.parse(): PlainTextFile {
57-
val lang = AuxLanguageRegistry.plainTextLanguage()
58+
val lang : PmdCapableLanguage = AuxLanguageRegistry.plainTextLanguage()
5859

5960
lang.defaultVersion shouldNotBe null
6061

0 commit comments

Comments
 (0)