diff --git a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java index 4af3f7924..e53c11ca3 100644 --- a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java +++ b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014-2016 Pivotal, Inc. + * Copyright (c) 2014-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 @@ -12,6 +12,8 @@ package org.springframework.ide.vscode.commons.util; import java.util.Collection; +import javax.inject.Provider; + import com.google.common.collect.ImmutableSet; /** @@ -22,7 +24,7 @@ import com.google.common.collect.ImmutableSet; public class EnumValueParser implements ValueParser { private String typeName; - private Collection values; + private Provider> values; public EnumValueParser(String typeName, String... values) { @@ -30,12 +32,16 @@ public class EnumValueParser implements ValueParser { } public EnumValueParser(String typeName, Collection values) { + this(typeName, () -> values); + } + + public EnumValueParser(String typeName, Provider> values) { this.typeName = typeName; this.values = values; } public Object parse(String str) { - Collection values = this.values; + Collection values = this.values.get(); //If values is not known (null) then just assume the str is acceptable. if (values==null || values.contains(str)) { return str; 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 778500476..b444900da 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 @@ -19,7 +19,6 @@ import org.springframework.ide.vscode.commons.util.Renderable; import org.springframework.ide.vscode.commons.util.Renderables; import org.springframework.ide.vscode.commons.yaml.schema.YType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory; -import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YTypedPropertyImpl; @@ -56,10 +55,12 @@ public class ManifestYmlSchema implements YamlSchema { YAtomicType t_buildpack = f.yatomic("Buildpack"); t_buildpack.addHintProvider(this.buildpackProvider); - YType t_service_string = f.yatomic("String"); - if (servicesProvider != null && t_service_string instanceof AbstractType) { - ((AbstractType)t_service_string).addHintProvider(servicesProvider); - } + YAtomicType t_service_string = f.yatomic("String"); + if (servicesProvider != null) { + t_service_string.addHintProvider(servicesProvider); + t_service_string + .parseWith(ManifestYmlValueParsers.fromHints(t_service_string.toString(), servicesProvider)); + } YType t_services = f.yseq(t_service_string); YAtomicType t_boolean = f.yenum("boolean", "true", "false"); 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 a1dae8b28..0d922f9de 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 @@ -10,12 +10,18 @@ *******************************************************************************/ package org.springframework.ide.vscode.manifest.yaml; +import java.util.Collection; import java.util.Set; +import javax.inject.Provider; + import org.springframework.ide.vscode.commons.util.Assert; +import org.springframework.ide.vscode.commons.util.EnumValueParser; import org.springframework.ide.vscode.commons.util.ValueParser; +import org.springframework.ide.vscode.commons.yaml.schema.YValueHint; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Sets; /** @@ -87,4 +93,22 @@ public class ManifestYmlValueParsers { }; } + public static ValueParser fromHints(String typeName, Provider> hintProvider) { + Provider> values= () -> { + Collection hints = hintProvider.get(); + if (hints != null) { + Builder builder = ImmutableSet.builder(); + + for (YValueHint hint : hints ) { + builder.add(hint.getValue()); + } + return builder.build(); + } + + return null; + }; + + return new EnumValueParser(typeName, values); + } + }