Fix property names with successive capital letters

Previously, if a property name had successive capital letters, the
generated meta-data would clean it in such a way it is defined as a
regular word. For instance a `myFOO` property would be written as
`my-foo` in the meta-data.

It turns out this decision is wrong as the binder has no way to compute
back the name of the property and therefore `my-foo` wouldn't bind to
`setMyFOO` as it should.

This commit updates the meta-data name generation algorithm to properly
identify such cases: `myFOO` now translates to `my-f-o-o`. While the
generated name is a bit ugly, it now provides a consistent binding
experience.

Closes gh-5330
This commit is contained in:
Stephane Nicoll
2016-06-27 12:02:34 +02:00
parent 8d491f278b
commit 17f8a244de
3 changed files with 56 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,35 +33,45 @@ public class ConfigurationMetadataTests {
assertThat(toDashedCase("simpleCamelCase"), is("simple-camel-case"));
}
@Test
public void toDashedCaseUpperCamelCaseSuffix() {
assertThat(toDashedCase("myDLQ"), is("my-d-l-q"));
}
@Test
public void toDashedCaseUpperCamelCaseMiddle() {
assertThat(toDashedCase("someDLQKey"), is("some-d-l-q-key"));
}
@Test
public void toDashedCaseWordsUnderscore() {
assertThat(toDashedCase("Word_With_underscore"), is("word_with_underscore"));
assertThat(toDashedCase("Word_With_underscore"), is("word-with-underscore"));
}
@Test
public void toDashedCaseWordsSeveralUnderscores() {
assertThat(toDashedCase("Word___With__underscore"),
is("word___with__underscore"));
is("word---with--underscore"));
}
@Test
public void toDashedCaseLowerCaseUnderscore() {
assertThat(toDashedCase("lower_underscore"), is("lower_underscore"));
assertThat(toDashedCase("lower_underscore"), is("lower-underscore"));
}
@Test
public void toDashedCaseUpperUnderscore() {
assertThat(toDashedCase("UPPER_UNDERSCORE"), is("upper_underscore"));
public void toDashedCaseUpperUnderscoreSuffix() {
assertThat(toDashedCase("my_DLQ"), is("my-d-l-q"));
}
@Test
public void toDashedCaseUpperUnderscoreMiddle() {
assertThat(toDashedCase("some_DLQ_key"), is("some-d-l-q-key"));
}
@Test
public void toDashedCaseMultipleUnderscores() {
assertThat(toDashedCase("super___crazy"), is("super___crazy"));
}
@Test
public void toDashedCaseUppercase() {
assertThat(toDashedCase("UPPERCASE"), is("uppercase"));
assertThat(toDashedCase("super___crazy"), is("super---crazy"));
}
@Test