Polish
This commit is contained in:
@@ -217,8 +217,8 @@ The JSON object contained in the `hints` array can contain the following attribu
|
||||
the value and may have a description
|
||||
|
||||
|`providers`
|
||||
| ProviderHint[]
|
||||
| A list of providers as defined by the `ValueHint` object (see below). Each entry defines
|
||||
| ValueProvider[]
|
||||
| A list of providers as defined by the `ValueProvider` object (see below). Each entry defines
|
||||
the name of the provider and its parameters, if any.
|
||||
|
||||
|===
|
||||
@@ -283,7 +283,7 @@ property, you can provide additional meta-data that:
|
||||
can discover the list of potential values based on the project's context.
|
||||
|
||||
|
||||
==== Value hints
|
||||
==== Value hint
|
||||
The `name` attribute of each hint refers to the `name` of a property. In the initial
|
||||
example above, we provide 3 values for the `server.tomcat.compression` property: `on`,
|
||||
`off` and `force`.
|
||||
@@ -330,7 +330,7 @@ the most effective approach to auto-completion if your IDE supports it.
|
||||
|
||||
|
||||
|
||||
==== Provider hints
|
||||
==== Value provider
|
||||
Providers are a powerful way of attaching semantics to a property. We define in the section
|
||||
below the official providers that you can use for your own hints. Bare in mind however that
|
||||
your favorite IDE may implement some of these or none of them. It could eventually provide
|
||||
@@ -345,7 +345,7 @@ The table below summarizes the list of supported providers:
|
||||
|Name | Description
|
||||
|
||||
|`any`
|
||||
|Permit any additional values to be provided.
|
||||
|Permit any additional value to be provided.
|
||||
|
||||
|`class-reference`
|
||||
|Auto-complete the classes available in the project. Usually constrained by a base
|
||||
@@ -363,7 +363,7 @@ The table below summarizes the list of supported providers:
|
||||
by a base class that is specified via the `target` parameter.
|
||||
|
||||
|`spring-profile-name`
|
||||
|Auto-complete the available profile names in the project.
|
||||
|Auto-complete the available Spring profile names in the project.
|
||||
|
||||
|===
|
||||
|
||||
|
||||
@@ -40,14 +40,14 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
|
||||
private final List<ValueHint> values;
|
||||
|
||||
private final List<ProviderHint> providers;
|
||||
private final List<ValueProvider> providers;
|
||||
|
||||
public ItemHint(String name, List<ValueHint> values, List<ProviderHint> providers) {
|
||||
public ItemHint(String name, List<ValueHint> values, List<ValueProvider> providers) {
|
||||
this.name = toCanonicalName(name);
|
||||
this.values = (values != null ? new ArrayList<ValueHint>(values)
|
||||
: new ArrayList<ValueHint>());
|
||||
this.providers = (providers != null ? new ArrayList<ProviderHint>(providers)
|
||||
: new ArrayList<ProviderHint>());
|
||||
this.providers = (providers != null ? new ArrayList<ValueProvider>(providers)
|
||||
: new ArrayList<ValueProvider>());
|
||||
}
|
||||
|
||||
private String toCanonicalName(String name) {
|
||||
@@ -68,7 +68,7 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
return Collections.unmodifiableList(this.values);
|
||||
}
|
||||
|
||||
public List<ProviderHint> getProviders() {
|
||||
public List<ValueProvider> getProviders() {
|
||||
return Collections.unmodifiableList(this.providers);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
|
||||
public static ItemHint newHint(String name, ValueHint... values) {
|
||||
return new ItemHint(name, Arrays.asList(values),
|
||||
Collections.<ProviderHint> emptyList());
|
||||
Collections.<ValueProvider> emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,13 +115,13 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
|
||||
}
|
||||
|
||||
public static class ProviderHint {
|
||||
public static class ValueProvider {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Map<String, Object> parameters;
|
||||
|
||||
public ProviderHint(String name, Map<String, Object> parameters) {
|
||||
public ValueProvider(String name, Map<String, Object> parameters) {
|
||||
this.name = name;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@@ -107,20 +107,20 @@ public class JsonMarshaller {
|
||||
}
|
||||
if (!hint.getProviders().isEmpty()) {
|
||||
JSONArray providersArray = new JSONArray();
|
||||
for (ItemHint.ProviderHint providerHint : hint.getProviders()) {
|
||||
JSONObject providerHintObject = new JSONOrderedObject();
|
||||
providerHintObject.put("name", providerHint.getName());
|
||||
if (providerHint.getParameters() != null
|
||||
&& !providerHint.getParameters().isEmpty()) {
|
||||
for (ItemHint.ValueProvider valueProvider : hint.getProviders()) {
|
||||
JSONObject valueProviderObject = new JSONOrderedObject();
|
||||
valueProviderObject.put("name", valueProvider.getName());
|
||||
if (valueProvider.getParameters() != null
|
||||
&& !valueProvider.getParameters().isEmpty()) {
|
||||
JSONObject parametersObject = new JSONOrderedObject();
|
||||
for (Map.Entry<String, Object> entry : providerHint.getParameters()
|
||||
for (Map.Entry<String, Object> entry : valueProvider.getParameters()
|
||||
.entrySet()) {
|
||||
parametersObject.put(entry.getKey(),
|
||||
extractItemValue(entry.getValue()));
|
||||
}
|
||||
providerHintObject.put("parameters", parametersObject);
|
||||
valueProviderObject.put("parameters", parametersObject);
|
||||
}
|
||||
providersArray.put(providerHintObject);
|
||||
providersArray.put(valueProviderObject);
|
||||
}
|
||||
jsonObject.put("providers", providersArray);
|
||||
}
|
||||
@@ -203,11 +203,11 @@ public class JsonMarshaller {
|
||||
values.add(toValueHint((JSONObject) valuesArray.get(i)));
|
||||
}
|
||||
}
|
||||
List<ItemHint.ProviderHint> providers = new ArrayList<ItemHint.ProviderHint>();
|
||||
List<ItemHint.ValueProvider> providers = new ArrayList<ItemHint.ValueProvider>();
|
||||
if (object.has("providers")) {
|
||||
JSONArray providersObject = object.getJSONArray("providers");
|
||||
for (int i = 0; i < providersObject.length(); i++) {
|
||||
providers.add(toProviderHint((JSONObject) providersObject.get(i)));
|
||||
providers.add(toValueProvider((JSONObject) providersObject.get(i)));
|
||||
}
|
||||
}
|
||||
return new ItemHint(name, values, providers);
|
||||
@@ -219,7 +219,7 @@ public class JsonMarshaller {
|
||||
return new ItemHint.ValueHint(value, description);
|
||||
}
|
||||
|
||||
private ItemHint.ProviderHint toProviderHint(JSONObject object) {
|
||||
private ItemHint.ValueProvider toValueProvider(JSONObject object) {
|
||||
String name = object.getString("name");
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
if (object.has("parameters")) {
|
||||
@@ -230,7 +230,7 @@ public class JsonMarshaller {
|
||||
parameters.put(key, value);
|
||||
}
|
||||
}
|
||||
return new ItemHint.ProviderHint(name, parameters);
|
||||
return new ItemHint.ValueProvider(name, parameters);
|
||||
}
|
||||
|
||||
private Object readItemValue(Object value) {
|
||||
|
||||
@@ -384,9 +384,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
public void mergingOfHintWithProvider() throws Exception {
|
||||
writeAdditionalHints(new ItemHint("simple.theName",
|
||||
Collections.<ItemHint.ValueHint> emptyList(), Arrays.asList(
|
||||
new ItemHint.ProviderHint("first", Collections
|
||||
new ItemHint.ValueProvider("first", Collections
|
||||
.<String, Object> singletonMap("target", "org.foo")),
|
||||
new ItemHint.ProviderHint("second", null))));
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata,
|
||||
containsHint("simple.the-name")
|
||||
|
||||
@@ -209,15 +209,15 @@ public class ConfigurationMetadataMatchers {
|
||||
|
||||
private final List<ValueHintMatcher> values;
|
||||
|
||||
private final List<ProviderHintMatcher> providers;
|
||||
private final List<ValueProviderMatcher> providers;
|
||||
|
||||
public ContainsHintMatcher(String name) {
|
||||
this(name, new ArrayList<ValueHintMatcher>(),
|
||||
new ArrayList<ProviderHintMatcher>());
|
||||
new ArrayList<ValueProviderMatcher>());
|
||||
}
|
||||
|
||||
public ContainsHintMatcher(String name, List<ValueHintMatcher> values,
|
||||
List<ProviderHintMatcher> providers) {
|
||||
List<ValueProviderMatcher> providers) {
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
this.providers = providers;
|
||||
@@ -238,7 +238,7 @@ public class ConfigurationMetadataMatchers {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (ProviderHintMatcher provider : this.providers) {
|
||||
for (ValueProviderMatcher provider : this.providers) {
|
||||
if (!provider.matches(itemHint)) {
|
||||
return false;
|
||||
}
|
||||
@@ -277,9 +277,9 @@ public class ConfigurationMetadataMatchers {
|
||||
|
||||
public ContainsHintMatcher withProvider(int index, String provider,
|
||||
Map<String, Object> parameters) {
|
||||
List<ProviderHintMatcher> providers = new ArrayList<ProviderHintMatcher>(
|
||||
List<ValueProviderMatcher> providers = new ArrayList<ValueProviderMatcher>(
|
||||
this.providers);
|
||||
providers.add(new ProviderHintMatcher(index, provider, parameters));
|
||||
providers.add(new ValueProviderMatcher(index, provider, parameters));
|
||||
return new ContainsHintMatcher(this.name, this.values, providers);
|
||||
}
|
||||
|
||||
@@ -347,12 +347,12 @@ public class ConfigurationMetadataMatchers {
|
||||
|
||||
}
|
||||
|
||||
public static class ProviderHintMatcher extends BaseMatcher<ItemHint> {
|
||||
public static class ValueProviderMatcher extends BaseMatcher<ItemHint> {
|
||||
private final int index;
|
||||
private final String name;
|
||||
private final Map<String, Object> parameters;
|
||||
|
||||
public ProviderHintMatcher(int index, String name, Map<String, Object> parameters) {
|
||||
public ValueProviderMatcher(int index, String name, Map<String, Object> parameters) {
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
this.parameters = parameters;
|
||||
@@ -364,14 +364,14 @@ public class ConfigurationMetadataMatchers {
|
||||
if (this.index + 1 > hint.getProviders().size()) {
|
||||
return false;
|
||||
}
|
||||
ItemHint.ProviderHint providerHint = hint.getProviders().get(this.index);
|
||||
if (this.name != null && !this.name.equals(providerHint.getName())) {
|
||||
ItemHint.ValueProvider valueProvider = hint.getProviders().get(this.index);
|
||||
if (this.name != null && !this.name.equals(valueProvider.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (this.parameters != null) {
|
||||
for (Map.Entry<String, Object> entry : this.parameters.entrySet()) {
|
||||
if (!IsMapContaining.hasEntry(entry.getKey(), entry.getValue())
|
||||
.matches(providerHint.getParameters())) {
|
||||
.matches(valueProvider.getParameters())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -381,7 +381,7 @@ public class ConfigurationMetadataMatchers {
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("provider hint ");
|
||||
description.appendText("value provider ");
|
||||
if (this.name != null) {
|
||||
description.appendText(" name ").appendValue(this.name);
|
||||
}
|
||||
|
||||
@@ -58,9 +58,9 @@ public class JsonMarshallerTests {
|
||||
metadata.add(ItemHint.newHint("a.b"));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"),
|
||||
new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(new ItemHint("d", null, Arrays.asList(new ItemHint.ProviderHint(
|
||||
metadata.add(new ItemHint("d", null, Arrays.asList(new ItemHint.ValueProvider(
|
||||
"first", Collections.<String, Object> singletonMap("target", "foo")),
|
||||
new ItemHint.ProviderHint("second", null))));
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
|
||||
Reference in New Issue
Block a user