/*******************************************************************************
 * 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
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.commons.util;

import java.util.Collection;

import javax.inject.Provider;

import com.google.common.collect.ImmutableSet;

/**
 * Parser for checking a 'Enum' style values.
 *
 * @author Kris De Volder
 */
public class EnumValueParser implements ValueParser {

	private String typeName;
	private Provider<Collection<String>> values;
	

	public EnumValueParser(String typeName, String... values) {
		this(typeName, ImmutableSet.copyOf(values));
	}

	public EnumValueParser(String typeName, Collection<String> values) {
		this(typeName, () -> values);
	}
	
	public EnumValueParser(String typeName, Provider<Collection<String>> values) {
		this.typeName = typeName;
		this.values = values;
	}

	public Object parse(String str) {
		Collection<String> 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;
		} else {
			throw new IllegalArgumentException(createErrorMessage(str, values));
		}
	}

	protected String createErrorMessage(String parseString, Collection<String> values2) {
		return "'"+parseString+"' is not valid for Enum '"+typeName+"'. Valid values are: "+values;
	}

}

@@ -1283,16 +1283,278 @@
  str) %7B%0A
+%09%09// IMPORTANT: check the text FIRST before fetching values%0A%09%09// from the hints provider, as the hints provider may be expensive when resolving values%0A%09%09if (!StringUtil.hasText(str)) %7B%0A%09%09%09throw new IllegalArgumentException(createBlankTextErrorMessage());%0A%09%09%7D%0A%09%09%0A
 %09%09Collec
@@ -1820,16 +1820,119 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09protected String createBlankTextErrorMessage() %7B%0A%09%09return %22'%22+typeName+%22'%22 + %22 cannot be blank.%22;%0A%09%7D%0A%0A
 %09protect

Handle case where text is blank in the enum parser