Skip to content

Commit

Permalink
Update to PMD 7.0.0-SNAPSHOT
Browse files Browse the repository at this point in the history
Mostly adjust Property API changes
  • Loading branch information
adangel committed Sep 28, 2023
1 parent 529d92f commit b0076b6
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Next

* **Bump required pmd-core version to 7.0.0-rc3.**
* **Bump required pmd-core version to 7.0.0-SNAPSHOT.**

**Fixed issues:**

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</developers>

<properties>
<pmd.core.version>7.0.0-rc3</pmd.core.version>
<pmd.core.version>7.0.0-SNAPSHOT</pmd.core.version>
<openjfx.version>11.0.2</openjfx.version>
<java.version>8</java.version>
<kotlin.version>1.7.20</kotlin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
package net.sourceforge.pmd.util.fxdesigner.model;


import java.util.HashMap;
import java.util.Map;

import org.reactfx.EventStream;
import org.reactfx.value.Val;
import org.reactfx.value.Var;

import net.sourceforge.pmd.properties.NumericConstraints;
import net.sourceforge.pmd.properties.PropertyBuilder;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyDescriptorField;
import net.sourceforge.pmd.properties.PropertyTypeId;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorExternalBuilder;
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsOwner;
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsPersistenceUtil.PersistentProperty;

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


public PropertyDescriptorSpec() {
isNumerical = typeId.map(PropertyTypeId::isPropertyNumeric);
isMultivalue = typeId.map(PropertyTypeId::isPropertyMultivalue);
isNumerical = typeId.map(this::isPropertyNumeric);
isMultivalue = typeId.map(this::isPropertyMultivalue);
}

private Boolean isPropertyMultivalue(PropertyTypeId propertyTypeId) {
switch (propertyTypeId) {
case DOUBLE_LIST:
case LONG_LIST:
case STRING_LIST:
case INTEGER_LIST:
case CHARACTER_LIST:
return true;
default:
return false;
}
}

private Boolean isPropertyNumeric(PropertyTypeId propertyTypeId) {
switch (propertyTypeId) {
case LONG:
case DOUBLE:
case INTEGER:
case LONG_LIST:
case DOUBLE_LIST:
case INTEGER_LIST:
return true;
default:
return false;
}
}


Expand Down Expand Up @@ -161,20 +185,19 @@ public PropertyDescriptorSpec deepCopy() {
* @return the descriptor if it can be built
*/
public PropertyDescriptor<?> build() {
PropertyDescriptorExternalBuilder<?> externalBuilder = getTypeId().getFactory();
Map<PropertyDescriptorField, String> values = new HashMap<>();
values.put(PropertyDescriptorField.NAME, getName());
values.put(PropertyDescriptorField.DEFAULT_VALUE, getValue());
values.put(PropertyDescriptorField.DESCRIPTION, getDescription());
values.put(PropertyDescriptorField.MIN, "-2000000");
values.put(PropertyDescriptorField.MAX, "+2000000");

return externalBuilder.build(values);
PropertyBuilder propertyBuilder = getTypeId().getBuilderUtils().newBuilder(getName());
Object defaultValue = getTypeId().getBuilderUtils().getXmlMapper().fromString(getValue());
propertyBuilder.desc(getDescription());
propertyBuilder.defaultValue(defaultValue);
if (isPropertyNumeric(getTypeId())) {
propertyBuilder.require(NumericConstraints.inRange(-2_000_000, +2_000_000));
}
return propertyBuilder.build();
}


Object parseValue() {
return build().valueFrom(getValue());
return getTypeId().getBuilderUtils().getXmlMapper().fromString(getValue());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ public static List<Node> evaluateQuery(Node compilationUnit,
Map<String, PropertyDescriptor<?>> descriptors = properties.stream().collect(Collectors.toMap(PropertyDescriptorSpec::getName, PropertyDescriptorSpec::build));
// Take in all set values or defaults
Map<PropertyDescriptor<?>, Object> allProperties =
descriptors.entrySet().stream()
.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()));
descriptors.entrySet().stream()
.collect(Collectors.<Entry<String, PropertyDescriptor<?>>, PropertyDescriptor<?>, Object>toMap(
e -> e.getValue(), e -> propertyValues.containsKey(e.getKey()) ? e.getValue().serializer().fromString(propertyValues.get(e.getKey())) : e.getValue().defaultValue()));

SaxonXPathRuleQuery xpathRule =
new SaxonXPathRuleQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public String dumpSubtree(Node n) throws Exception {


private static <T> String getValueAsString(PropertyDescriptor<T> d) {
return d.asDelimitedString(d.defaultValue());
return d.serializer().toString(d.defaultValue());
}

private static <T> void setProperty(PropertySource bundle, PropertyDescriptor<T> d, String value) {
bundle.setProperty(d, d.valueFrom(value));
bundle.setProperty(d, d.serializer().fromString(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

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

import static net.sourceforge.pmd.properties.MultiValuePropertyDescriptor.DEFAULT_DELIMITER;
import static net.sourceforge.pmd.properties.MultiValuePropertyDescriptor.DEFAULT_NUMERIC_DELIMITER;
import static net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil.rewireInit;

import java.net.URL;
Expand All @@ -20,9 +18,8 @@
import org.reactfx.util.Try;
import org.reactfx.value.Var;

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


validationSupport.registerValidator(valueField, valueValidator);
}


private ValueParser<?> getValueParser(PropertyTypeId typeId) {
ValueParser<?> parser = typeId.getValueParser();
if (typeId.isPropertyMultivalue()) {
char delimiter = typeId.isPropertyNumeric() ? DEFAULT_NUMERIC_DELIMITER : DEFAULT_DELIMITER;
parser = ValueParserConstants.multi(parser, delimiter);
}
return parser;
private PropertySerializer<?> getValueParser(PropertyTypeId typeId) {
return typeId.getBuilderUtils().getXmlMapper();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static boolean isXmlDialect(Language language) {
}
}

public static Language plainTextLanguage() {
public static PlainTextLanguage plainTextLanguage() {
return PlainTextLanguage.getInstance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import net.sourceforge.pmd.lang.LanguageProcessorRegistry
import net.sourceforge.pmd.lang.PlainTextLanguage.PlainTextFile
import net.sourceforge.pmd.lang.PmdCapableLanguage
import net.sourceforge.pmd.lang.ast.Parser
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter
import net.sourceforge.pmd.lang.ast.test.IntelliMarker
Expand Down Expand Up @@ -54,7 +55,7 @@ class PlainTextLanguageTest : IntelliMarker, FunSpec({
})

private fun String.parse(): PlainTextFile {
val lang = AuxLanguageRegistry.plainTextLanguage()
val lang : PmdCapableLanguage = AuxLanguageRegistry.plainTextLanguage()

lang.defaultVersion shouldNotBe null

Expand Down

0 comments on commit b0076b6

Please sign in to comment.