Commit 3664895f authored by Stephane Nicoll's avatar Stephane Nicoll

Polish

parent fd0b1c63
...@@ -217,8 +217,8 @@ The JSON object contained in the `hints` array can contain the following attribu ...@@ -217,8 +217,8 @@ The JSON object contained in the `hints` array can contain the following attribu
the value and may have a description the value and may have a description
|`providers` |`providers`
| ProviderHint[] | ValueProvider[]
| A list of providers as defined by the `ValueHint` object (see below). Each entry defines | 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. the name of the provider and its parameters, if any.
|=== |===
...@@ -283,7 +283,7 @@ property, you can provide additional meta-data that: ...@@ -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. 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 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`, example above, we provide 3 values for the `server.tomcat.compression` property: `on`,
`off` and `force`. `off` and `force`.
...@@ -330,7 +330,7 @@ the most effective approach to auto-completion if your IDE supports it. ...@@ -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 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 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 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: ...@@ -345,7 +345,7 @@ The table below summarizes the list of supported providers:
|Name | Description |Name | Description
|`any` |`any`
|Permit any additional values to be provided. |Permit any additional value to be provided.
|`class-reference` |`class-reference`
|Auto-complete the classes available in the project. Usually constrained by a base |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: ...@@ -363,7 +363,7 @@ The table below summarizes the list of supported providers:
by a base class that is specified via the `target` parameter. by a base class that is specified via the `target` parameter.
|`spring-profile-name` |`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> { ...@@ -40,14 +40,14 @@ public class ItemHint implements Comparable<ItemHint> {
private final List<ValueHint> values; 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.name = toCanonicalName(name);
this.values = (values != null ? new ArrayList<ValueHint>(values) this.values = (values != null ? new ArrayList<ValueHint>(values)
: new ArrayList<ValueHint>()); : new ArrayList<ValueHint>());
this.providers = (providers != null ? new ArrayList<ProviderHint>(providers) this.providers = (providers != null ? new ArrayList<ValueProvider>(providers)
: new ArrayList<ProviderHint>()); : new ArrayList<ValueProvider>());
} }
private String toCanonicalName(String name) { private String toCanonicalName(String name) {
...@@ -68,7 +68,7 @@ public class ItemHint implements Comparable<ItemHint> { ...@@ -68,7 +68,7 @@ public class ItemHint implements Comparable<ItemHint> {
return Collections.unmodifiableList(this.values); return Collections.unmodifiableList(this.values);
} }
public List<ProviderHint> getProviders() { public List<ValueProvider> getProviders() {
return Collections.unmodifiableList(this.providers); return Collections.unmodifiableList(this.providers);
} }
...@@ -79,7 +79,7 @@ public class ItemHint implements Comparable<ItemHint> { ...@@ -79,7 +79,7 @@ public class ItemHint implements Comparable<ItemHint> {
public static ItemHint newHint(String name, ValueHint... values) { public static ItemHint newHint(String name, ValueHint... values) {
return new ItemHint(name, Arrays.asList(values), return new ItemHint(name, Arrays.asList(values),
Collections.<ProviderHint> emptyList()); Collections.<ValueProvider> emptyList());
} }
@Override @Override
...@@ -115,13 +115,13 @@ public class ItemHint implements Comparable<ItemHint> { ...@@ -115,13 +115,13 @@ public class ItemHint implements Comparable<ItemHint> {
} }
public static class ProviderHint { public static class ValueProvider {
private final String name; private final String name;
private final Map<String, Object> parameters; 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.name = name;
this.parameters = parameters; this.parameters = parameters;
} }
......
...@@ -107,20 +107,20 @@ public class JsonMarshaller { ...@@ -107,20 +107,20 @@ public class JsonMarshaller {
} }
if (!hint.getProviders().isEmpty()) { if (!hint.getProviders().isEmpty()) {
JSONArray providersArray = new JSONArray(); JSONArray providersArray = new JSONArray();
for (ItemHint.ProviderHint providerHint : hint.getProviders()) { for (ItemHint.ValueProvider valueProvider : hint.getProviders()) {
JSONObject providerHintObject = new JSONOrderedObject(); JSONObject valueProviderObject = new JSONOrderedObject();
providerHintObject.put("name", providerHint.getName()); valueProviderObject.put("name", valueProvider.getName());
if (providerHint.getParameters() != null if (valueProvider.getParameters() != null
&& !providerHint.getParameters().isEmpty()) { && !valueProvider.getParameters().isEmpty()) {
JSONObject parametersObject = new JSONOrderedObject(); JSONObject parametersObject = new JSONOrderedObject();
for (Map.Entry<String, Object> entry : providerHint.getParameters() for (Map.Entry<String, Object> entry : valueProvider.getParameters()
.entrySet()) { .entrySet()) {
parametersObject.put(entry.getKey(), parametersObject.put(entry.getKey(),
extractItemValue(entry.getValue())); extractItemValue(entry.getValue()));
} }
providerHintObject.put("parameters", parametersObject); valueProviderObject.put("parameters", parametersObject);
} }
providersArray.put(providerHintObject); providersArray.put(valueProviderObject);
} }
jsonObject.put("providers", providersArray); jsonObject.put("providers", providersArray);
} }
...@@ -203,11 +203,11 @@ public class JsonMarshaller { ...@@ -203,11 +203,11 @@ public class JsonMarshaller {
values.add(toValueHint((JSONObject) valuesArray.get(i))); 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")) { if (object.has("providers")) {
JSONArray providersObject = object.getJSONArray("providers"); JSONArray providersObject = object.getJSONArray("providers");
for (int i = 0; i < providersObject.length(); i++) { 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); return new ItemHint(name, values, providers);
...@@ -219,7 +219,7 @@ public class JsonMarshaller { ...@@ -219,7 +219,7 @@ public class JsonMarshaller {
return new ItemHint.ValueHint(value, description); return new ItemHint.ValueHint(value, description);
} }
private ItemHint.ProviderHint toProviderHint(JSONObject object) { private ItemHint.ValueProvider toValueProvider(JSONObject object) {
String name = object.getString("name"); String name = object.getString("name");
Map<String, Object> parameters = new HashMap<String, Object>(); Map<String, Object> parameters = new HashMap<String, Object>();
if (object.has("parameters")) { if (object.has("parameters")) {
...@@ -230,7 +230,7 @@ public class JsonMarshaller { ...@@ -230,7 +230,7 @@ public class JsonMarshaller {
parameters.put(key, value); parameters.put(key, value);
} }
} }
return new ItemHint.ProviderHint(name, parameters); return new ItemHint.ValueProvider(name, parameters);
} }
private Object readItemValue(Object value) { private Object readItemValue(Object value) {
......
...@@ -384,9 +384,9 @@ public class ConfigurationMetadataAnnotationProcessorTests { ...@@ -384,9 +384,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public void mergingOfHintWithProvider() throws Exception { public void mergingOfHintWithProvider() throws Exception {
writeAdditionalHints(new ItemHint("simple.theName", writeAdditionalHints(new ItemHint("simple.theName",
Collections.<ItemHint.ValueHint> emptyList(), Arrays.asList( Collections.<ItemHint.ValueHint> emptyList(), Arrays.asList(
new ItemHint.ProviderHint("first", Collections new ItemHint.ValueProvider("first", Collections
.<String, Object> singletonMap("target", "org.foo")), .<String, Object> singletonMap("target", "org.foo")),
new ItemHint.ProviderHint("second", null)))); new ItemHint.ValueProvider("second", null))));
ConfigurationMetadata metadata = compile(SimpleProperties.class); ConfigurationMetadata metadata = compile(SimpleProperties.class);
assertThat(metadata, assertThat(metadata,
containsHint("simple.the-name") containsHint("simple.the-name")
......
...@@ -209,15 +209,15 @@ public class ConfigurationMetadataMatchers { ...@@ -209,15 +209,15 @@ public class ConfigurationMetadataMatchers {
private final List<ValueHintMatcher> values; private final List<ValueHintMatcher> values;
private final List<ProviderHintMatcher> providers; private final List<ValueProviderMatcher> providers;
public ContainsHintMatcher(String name) { public ContainsHintMatcher(String name) {
this(name, new ArrayList<ValueHintMatcher>(), this(name, new ArrayList<ValueHintMatcher>(),
new ArrayList<ProviderHintMatcher>()); new ArrayList<ValueProviderMatcher>());
} }
public ContainsHintMatcher(String name, List<ValueHintMatcher> values, public ContainsHintMatcher(String name, List<ValueHintMatcher> values,
List<ProviderHintMatcher> providers) { List<ValueProviderMatcher> providers) {
this.name = name; this.name = name;
this.values = values; this.values = values;
this.providers = providers; this.providers = providers;
...@@ -238,7 +238,7 @@ public class ConfigurationMetadataMatchers { ...@@ -238,7 +238,7 @@ public class ConfigurationMetadataMatchers {
return false; return false;
} }
} }
for (ProviderHintMatcher provider : this.providers) { for (ValueProviderMatcher provider : this.providers) {
if (!provider.matches(itemHint)) { if (!provider.matches(itemHint)) {
return false; return false;
} }
...@@ -277,9 +277,9 @@ public class ConfigurationMetadataMatchers { ...@@ -277,9 +277,9 @@ public class ConfigurationMetadataMatchers {
public ContainsHintMatcher withProvider(int index, String provider, public ContainsHintMatcher withProvider(int index, String provider,
Map<String, Object> parameters) { Map<String, Object> parameters) {
List<ProviderHintMatcher> providers = new ArrayList<ProviderHintMatcher>( List<ValueProviderMatcher> providers = new ArrayList<ValueProviderMatcher>(
this.providers); this.providers);
providers.add(new ProviderHintMatcher(index, provider, parameters)); providers.add(new ValueProviderMatcher(index, provider, parameters));
return new ContainsHintMatcher(this.name, this.values, providers); return new ContainsHintMatcher(this.name, this.values, providers);
} }
...@@ -347,12 +347,12 @@ public class ConfigurationMetadataMatchers { ...@@ -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 int index;
private final String name; private final String name;
private final Map<String, Object> parameters; 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.index = index;
this.name = name; this.name = name;
this.parameters = parameters; this.parameters = parameters;
...@@ -364,14 +364,14 @@ public class ConfigurationMetadataMatchers { ...@@ -364,14 +364,14 @@ public class ConfigurationMetadataMatchers {
if (this.index + 1 > hint.getProviders().size()) { if (this.index + 1 > hint.getProviders().size()) {
return false; return false;
} }
ItemHint.ProviderHint providerHint = hint.getProviders().get(this.index); ItemHint.ValueProvider valueProvider = hint.getProviders().get(this.index);
if (this.name != null && !this.name.equals(providerHint.getName())) { if (this.name != null && !this.name.equals(valueProvider.getName())) {
return false; return false;
} }
if (this.parameters != null) { if (this.parameters != null) {
for (Map.Entry<String, Object> entry : this.parameters.entrySet()) { for (Map.Entry<String, Object> entry : this.parameters.entrySet()) {
if (!IsMapContaining.hasEntry(entry.getKey(), entry.getValue()) if (!IsMapContaining.hasEntry(entry.getKey(), entry.getValue())
.matches(providerHint.getParameters())) { .matches(valueProvider.getParameters())) {
return false; return false;
} }
} }
...@@ -381,7 +381,7 @@ public class ConfigurationMetadataMatchers { ...@@ -381,7 +381,7 @@ public class ConfigurationMetadataMatchers {
@Override @Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("provider hint "); description.appendText("value provider ");
if (this.name != null) { if (this.name != null) {
description.appendText(" name ").appendValue(this.name); description.appendText(" name ").appendValue(this.name);
} }
......
...@@ -58,9 +58,9 @@ public class JsonMarshallerTests { ...@@ -58,9 +58,9 @@ public class JsonMarshallerTests {
metadata.add(ItemHint.newHint("a.b")); metadata.add(ItemHint.newHint("a.b"));
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"), metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"),
new ItemHint.ValueHint(456, null))); 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")), "first", Collections.<String, Object> singletonMap("target", "foo")),
new ItemHint.ProviderHint("second", null)))); new ItemHint.ValueProvider("second", null))));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JsonMarshaller marshaller = new JsonMarshaller(); JsonMarshaller marshaller = new JsonMarshaller();
marshaller.write(metadata, outputStream); marshaller.write(metadata, outputStream);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment