Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fc85d3662a6cebef2d3c566f2e266a424dc306be (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2004, 2020 IBM Corporation 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:
 *     Andrew Niefer (IBM Corporation) - Initial API and implementation
 *     Alexander Fedorov (ArSysOp) - Bug 561992
 *******************************************************************************/
package org.eclipse.cdt.internal.core.parser;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.cdt.core.dom.ast.ISemanticProblem;

public class ParserMessages {
	private static final String BUNDLE_NAME = ParserMessages.class.getName();
	private static ResourceBundle resourceBundle;

	static {
		try {
			resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
		} catch (MissingResourceException x) {
			resourceBundle = null;
		}
	}

	private ParserMessages() {
	}

	public static String getString(String key) {
		if (resourceBundle == null)
			return '#' + key + '#';
		try {
			return resourceBundle.getString(key);
		} catch (MissingResourceException e) {
			return '!' + key + '!';
		}
	}

	/**
	 * Gets a string from the resource bundle and formats it with the argument
	 *
	 * @param key	the string used to get the bundle value, must not be null
	 */
	public static String getFormattedString(String key, Object[] args) {
		String format = getString(key);
		return MessageFormat.format(format, args);
	}

	/**
	 * Gets a string from the resource bundle and formats it with the argument
	 *
	 * @param key	the string used to get the bundle value, must not be null
	 */
	public static String getFormattedString(String key, Object arg) {
		String format = getString(key);

		if (arg == null)
			arg = ""; //$NON-NLS-1$

		return MessageFormat.format(format, new Object[] { arg });
	}

	public static String getProblemPattern(ISemanticProblem problem) {
		String key = getProblemKey(problem.getID());
		if (key != null)
			return getString(key);
		return null;
	}

	@SuppressWarnings("nls")
	private static String getProblemKey(int id) {
		switch (id) {
		case ISemanticProblem.BINDING_AMBIGUOUS_LOOKUP:
			return "ISemanticProblem.BINDING_AMBIGUOUS_LOOKUP";
		case ISemanticProblem.BINDING_BAD_SCOPE:
			return "ISemanticProblem.BINDING_BAD_SCOPE";
		case ISemanticProblem.BINDING_CIRCULAR_INHERITANCE:
			return "ISemanticProblem.BINDING_CIRCULAR_INHERITANCE";
		case ISemanticProblem.BINDING_DEFINITION_NOT_FOUND:
			return "ISemanticProblem.BINDING_DEFINITION_NOT_FOUND";
		case ISemanticProblem.BINDING_INVALID_OVERLOAD:
			return "ISemanticProblem.BINDING_INVALID_OVERLOAD";
		case ISemanticProblem.BINDING_INVALID_REDECLARATION:
			return "ISemanticProblem.BINDING_INVALID_REDECLARATION";
		case ISemanticProblem.BINDING_INVALID_REDEFINITION:
			return "ISemanticProblem.BINDING_INVALID_REDEFINITION";
		case ISemanticProblem.BINDING_INVALID_TEMPLATE_ARGUMENTS:
			return "ISemanticProblem.BINDING_INVALID_TEMPLATE_ARGUMENTS";
		case ISemanticProblem.BINDING_INVALID_TYPE:
			return "ISemanticProblem.BINDING_INVALID_TYPE";
		case ISemanticProblem.BINDING_INVALID_USING:
			return "ISemanticProblem.BINDING_INVALID_USING";
		case ISemanticProblem.BINDING_KNR_PARAMETER_DECLARATION_NOT_FOUND:
			return "ISemanticProblem.BINDING_KNR_PARAMETER_DECLARATION_NOT_FOUND";
		case ISemanticProblem.BINDING_LABEL_STATEMENT_NOT_FOUND:
			return "ISemanticProblem.BINDING_LABEL_STATEMENT_NOT_FOUND";
		case ISemanticProblem.BINDING_MEMBER_DECLARATION_NOT_FOUND:
			return "ISemanticProblem.BINDING_MEMBER_DECLARATION_NOT_FOUND";
		case ISemanticProblem.BINDING_NO_CLASS:
			return "ISemanticProblem.BINDING_NO_CLASS";
		case ISemanticProblem.BINDING_NOT_FOUND:
			return "ISemanticProblem.BINDING_NOT_FOUND";
		case ISemanticProblem.BINDING_RECURSION_IN_LOOKUP:
			return "ISemanticProblem.BINDING_RECURSION_IN_LOOKUP";

		case ISemanticProblem.TYPE_NO_NAME:
			return "ISemanticProblem.TYPE_NO_NAME";
		case ISemanticProblem.TYPE_UNRESOLVED_NAME:
			return "ISemanticProblem.TYPE_UNRESOLVED_NAME";
		case ISemanticProblem.TYPE_AUTO_FOR_NON_STATIC_FIELD:
			return "ISemanticProblem.TYPE_AUTO_FOR_NON_STATIC_FIELD";
		case ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE:
			return "ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE";
		case ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION:
			return "ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION";
		case ISemanticProblem.TYPE_NOT_PERSISTED:
			return "ISemanticProblem.TYPE_NOT_PERSISTED";
		case ISemanticProblem.TYPE_ENUMERATION_EXPECTED:
			return "ISemanticProblem.TYPE_ENUMERATION_EXPECTED";
		case ISemanticProblem.TYPE_CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE:
			return "ISemanticProblem.TYPE_CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE";
		case ISemanticProblem.TYPE_AUTO_FOR_VIRTUAL_METHOD:
			return "ISemanticProblem.TYPE_AUTO_FOR_VIRTUAL_METHOD";
		}
		return null;
	}
}

Back to the top