Browse Source

PropertyLoader: Drop support for color values without a leading #

macos/dialog_size
weisj 3 years ago
parent
commit
1f6eb6ecf8
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 7
      property-loader/src/main/java/com/github/weisj/darklaf/properties/parser/PrimitiveParser.java
  2. 24
      property-loader/src/test/java/com/github/weisj/darklaf/properties/parser/ParserTest.java

7
property-loader/src/main/java/com/github/weisj/darklaf/properties/parser/PrimitiveParser.java

@ -37,13 +37,6 @@ public class PrimitiveParser implements PropertyParser {
if (parseResult.value.startsWith(COLOR_PREFIX)) {
Color c = ColorUtil.fromHex(parseResult.value, null, true);
ParserUtil.setNonNull(parseResult, c != null ? new DarkColorUIResource(c) : null);
} else {
Color c = ColorUtil.fromHex(parseResult.value, null, true);
ParserUtil.setNonNull(parseResult, c != null ? new DarkColorUIResource(c) : null);
if (parseResult.finished) {
ParserUtil.warning("Declaration '" + parseResult.value + "' specifies a color "
+ " without a '#' prefix, which is deprecated. Support will be dropped in future versions.");
}
}
if (parseResult.finished) return parseResult;
if (ParserUtil.startsWith(parseResult, STRING_DELIMITER)) {

24
property-loader/src/test/java/com/github/weisj/darklaf/properties/parser/ParserTest.java

@ -85,15 +85,6 @@ class ParserTest {
}
}
@Test
void testColorLegacy() {
Random r = new Random();
for (int i = 0; i < 100; i++) {
Color c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
Assertions.assertEquals(c, parse("key", ColorUtil.toHex(c)));
}
}
@Test
void testReferences() {
Assertions.assertEquals("key", Parser.parse(new ParseResult("%key", "value"), context).key);
@ -126,10 +117,6 @@ class ParserTest {
for (int i = 0; i < 100; i++) {
int w = r.nextInt();
int h = r.nextInt();
// While legacy declarations are supported these may be a valid color value.
// and parse incorrectly.
if (isValidColor(w)) continue;
if (isValidColor(h)) continue;
Assertions.assertEquals(new Dimension(w, h), parse("test.size", w + "," + h));
Assertions.assertEquals(new Dimension(w, h), parse("testSize", w + "," + h));
}
@ -139,22 +126,11 @@ class ParserTest {
Assertions.assertEquals(dim, parse("key.size", "%key.width," + dim.height));
}
private boolean isValidColor(final int value) {
return ColorUtil.fromHex(String.valueOf(value), null) != null;
}
@Test
void testInsets() {
Random r = new Random();
for (int i = 0; i < 100; i++) {
Insets insets = new Insets(r.nextInt(), r.nextInt(), r.nextInt(), r.nextInt());
// While legacy declarations are supported these may be a valid color value
// hence parse incorrectly.
if (isValidColor(insets.left)) continue;
if (isValidColor(insets.right)) continue;
if (isValidColor(insets.bottom)) continue;
if (isValidColor(insets.top)) continue;
Assertions.assertEquals(insets, parse("test.insets",
insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right));
Assertions.assertEquals(insets, parse("testInsets",

Loading…
Cancel
Save