diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/CFServicesValueParser.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/CFServicesValueParser.java new file mode 100644 index 000000000..50c05771a --- /dev/null +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/CFServicesValueParser.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.manifest.yaml; + +import java.util.Collection; +import java.util.concurrent.Callable; + +import org.springframework.ide.vscode.commons.util.EnumValueParser; + +public class CFServicesValueParser extends EnumValueParser { + + public CFServicesValueParser(String typeName, Callable> values) { + super(typeName, values); + } + + protected String createErrorMessage(String parseString, Collection values) { + return "There is no service instance called '" + parseString + "'. Available service instances are: " + values; + } + +} diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java index 60bdd3a04..74af343e2 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java @@ -67,7 +67,8 @@ public class ManifestYmlSchema implements YamlSchema { YAtomicType t_service_string = f.yatomic("Service"); if (servicesProvider != null) { t_service_string.addHintProvider(servicesProvider); - t_service_string.parseWith(ManifestYmlValueParsers.fromHints(t_service_string.toString(), servicesProvider)); + t_service_string.parseWith(new CFServicesValueParser(t_service_string.toString(), + ManifestYmlValueParsers.getValuesFromHints(servicesProvider))); } YType t_services = f.yseq(t_service_string); diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlValueParsers.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlValueParsers.java index 505377e26..92c2af451 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlValueParsers.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlValueParsers.java @@ -93,6 +93,12 @@ public class ManifestYmlValueParsers { } public static ValueParser fromHints(String typeName, Callable> hintProvider) { + Callable> values = getValuesFromHints(hintProvider); + + return new EnumValueParser(typeName, values); + } + + public static Callable> getValuesFromHints(Callable> hintProvider) { Callable> values= () -> { Collection hints = hintProvider.call(); if (hints != null) { @@ -106,8 +112,7 @@ public class ManifestYmlValueParsers { return null; }; - - return new EnumValueParser(typeName, values); + return values; } }