Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5fe2c704afe366eaaf7e9e76cfba9d1008c3bcf1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*******************************************************************************
 * Copyright (c) 2009, 2012 Alena Laskavaia and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Alena Laskavaia  - initial API and implementation
 *    IBM Corporation
 *******************************************************************************/
package org.eclipse.cdt.codan.core.model;

import org.eclipse.core.resources.IMarker;

/**
 * Represents Severity of the codan problem. It is directly mapped to markers
 * severity.
 *
 */
public enum CodanSeverity {
	/**
	 * Info severity
	 */
	Info(IMarker.SEVERITY_INFO),
	/**
	 * Warning severity
	 */
	Warning(IMarker.SEVERITY_WARNING),
	/**
	 * Error severity
	 */
	Error(IMarker.SEVERITY_ERROR);

	private int value;

	private CodanSeverity(int value) {
		this.value = value;
	}

	/**
	 * @return int value of the severity
	 */
	public int intValue() {
		return value;
	}

	/**
	 * @return array of string value for all severities
	 */
	public static String[] stringValues() {
		CodanSeverity[] values = values();
		String[] svalues = new String[values.length];
		for (int i = 0; i < values.length; i++) {
			CodanSeverity sev = values[i];
			svalues[i] = sev.toTranslatableString();
		}
		return svalues;
	}

	/**
	 * @param intValue
	 * @return value of severity by its integer value
	 * @since 2.0
	 */
	public static CodanSeverity valueOf(int intValue) {
		if (intValue == IMarker.SEVERITY_INFO)
			return Info;
		if (intValue == IMarker.SEVERITY_WARNING)
			return Warning;
		if (intValue == IMarker.SEVERITY_ERROR)
			return Error;
		return null;
	}

	/**
	 * @return translated string value of this CodanSeverity
	 * @since 2.0
	 */
	public String toTranslatableString() {
		switch (this) {
			case Info:
			return Messages.CodanSeverity_Info;

			case Warning:
				return Messages.CodanSeverity_Warning;

			case Error:
			default:
				return Messages.CodanSeverity_Error;
		}
	}
}

Back to the top