/*******************************************************************************
 * Copyright (c) 2012 itemis AG (http://www.itemis.eu) and others.
 * 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
 *******************************************************************************/
package org.eclipse.xtext.validation;

import java.util.Map;

import org.apache.log4j.Logger;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.preferences.IPreferenceValues;
import org.eclipse.xtext.preferences.PreferenceKey;

/**
 * @author Sven Efftinge - Initial contribution and API
 * @since 2.4
 */
public class IssueSeverities {
	
	private final static Logger log = Logger.getLogger(IssueSeverities.class);
	
	private IPreferenceValues preferenceValues;
	private Map<String, PreferenceKey> configurableIssueCodes;
	private SeverityConverter converter;

	public IssueSeverities(IPreferenceValues preferenceValues, Map<String, PreferenceKey> configurableIssueCodes, SeverityConverter converter) {
		this.preferenceValues = preferenceValues;
		this.configurableIssueCodes = configurableIssueCodes;
		this.converter = converter;
	}

	public Severity getSeverity(String code) {
		if (!configurableIssueCodes.containsKey(code))
			return Severity.ERROR;
		final String value = preferenceValues.getPreference(configurableIssueCodes.get(code));
		try {
			return converter.stringToSeverity(value);
		} catch (IllegalArgumentException e) {
			log.error(e.getMessage(), e);
			return Severity.ERROR;
		}
	}
	
	public boolean isIgnored(String code) {
		return getSeverity(code) == null;
	}
}

@@ -1420,16 +1420,165 @@
 y(code))
+ %7B%0A%09%09%09log.error(%22Configurable issue code '%22 + code + %22' is not registered. Check the binding for %22 + ConfigurableIssueCodesProvider.class.getName());
 %0A%09%09%09retu
@@ -1589,22 +1589,27 @@
 everity.
-ERROR;
+IGNORE;%0A%09%09%7D
 %0A%09%09final
@@ -1840,13 +1840,14 @@
 ity.
-ERR
+IGN
 OR
+E
 ;%0A%09%09

return ignore severity and log an error if a configurable issue is not registered. Updated launch configurations.