View | Details | Raw Unified | Return to bug 206423 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblemFactory.java (-14 / +6 lines)
Lines 131-158 Link Here
131
	return getLocalizedMessage(id, 0, problemArguments);
131
	return getLocalizedMessage(id, 0, problemArguments);
132
}
132
}
133
public final String getLocalizedMessage(int id, int elaborationId, String[] problemArguments) {
133
public final String getLocalizedMessage(int id, int elaborationId, String[] problemArguments) {
134
	String message = (String) this.messageTemplates.get(keyFromID(id & IProblem.IgnoreCategoriesMask));
134
	char[] message = ((String) this.messageTemplates.get(keyFromID(id & IProblem.IgnoreCategoriesMask))).toCharArray();
135
	if (message == null) {
135
	if (message == null) {
136
		return "Unable to retrieve the error message for problem id: " //$NON-NLS-1$
136
		return "Unable to retrieve the error message for problem id: " //$NON-NLS-1$
137
			+ (id & IProblem.IgnoreCategoriesMask) + ". Check compiler resources.";  //$NON-NLS-1$
137
			+ (id & IProblem.IgnoreCategoriesMask) + ". Check compiler resources.";  //$NON-NLS-1$
138
	}
138
	}
139
	if (elaborationId != 0) {
139
	if (elaborationId != 0) {
140
		String elaboration = (String) this.messageTemplates.get(keyFromID(elaborationId));
140
		char[] elaboration = ((String) this.messageTemplates.get(keyFromID(elaborationId))).toCharArray();
141
		if (elaboration == null) {
141
		if (elaboration == null) {
142
			return "Unable to retrieve the error message elaboration for elaboration id: " //$NON-NLS-1$
142
			return "Unable to retrieve the error message elaboration for elaboration id: " //$NON-NLS-1$
143
				+ elaborationId + ". Check compiler resources.";  //$NON-NLS-1$
143
				+ elaborationId + ". Check compiler resources.";  //$NON-NLS-1$
144
		}
144
		}
145
		// make the substitution. String.replaceAll(String,String) cannot be used since it is
145
		message = CharOperation.replace(message, FIRST_ARGUMENT, elaboration);
146
		// defined only in 1.4
147
		message = new String(CharOperation.replace(
148
				message.toCharArray(),
149
				FIRST_ARGUMENT,
150
				elaboration.toCharArray()));
151
	}
146
	}
152
147
153
	// for compatibility with MessageFormat which eliminates double quotes in original message
148
	// for compatibility with MessageFormat which eliminates double quotes in original message
154
	char[] messageWithNoDoubleQuotes =
149
	char[] messageWithNoDoubleQuotes =
155
		CharOperation.replace(message.toCharArray(), DOUBLE_QUOTES, SINGLE_QUOTE);
150
		CharOperation.replace(message, DOUBLE_QUOTES, SINGLE_QUOTE);
156
151
157
	if (problemArguments == null) return new String(messageWithNoDoubleQuotes);
152
	if (problemArguments == null) return new String(messageWithNoDoubleQuotes);
158
153
Lines 169-186 Link Here
169
			if (output == null) output = new StringBuffer(length+problemArguments.length*20);
164
			if (output == null) output = new StringBuffer(length+problemArguments.length*20);
170
			output.append(messageWithNoDoubleQuotes, start, end - start);
165
			output.append(messageWithNoDoubleQuotes, start, end - start);
171
			if ((start = CharOperation.indexOf('}', messageWithNoDoubleQuotes, end + 1)) > -1) {
166
			if ((start = CharOperation.indexOf('}', messageWithNoDoubleQuotes, end + 1)) > -1) {
172
				int index = -1;
173
				String argId = new String(messageWithNoDoubleQuotes, end + 1, start - end - 1);
174
				try {
167
				try {
175
					index = Integer.parseInt(argId);
168
					output.append(problemArguments[CharOperation.parseInt(messageWithNoDoubleQuotes, end + 1, start - end - 1)]);
176
					output.append(problemArguments[index]);
177
				} catch (NumberFormatException nfe) {
169
				} catch (NumberFormatException nfe) {
178
					output.append(messageWithNoDoubleQuotes, end + 1, start - end);
170
					output.append(messageWithNoDoubleQuotes, end + 1, start - end);
179
				} catch (ArrayIndexOutOfBoundsException e) {
171
				} catch (ArrayIndexOutOfBoundsException e) {
180
					return "Cannot bind message for problem (id: " //$NON-NLS-1$
172
					return "Cannot bind message for problem (id: " //$NON-NLS-1$
181
						+ (id & IProblem.IgnoreCategoriesMask)
173
						+ (id & IProblem.IgnoreCategoriesMask)
182
						+ ") \""  //$NON-NLS-1$
174
						+ ") \""  //$NON-NLS-1$
183
						+ message
175
						+ new String(message)
184
						+ "\" with arguments: {" //$NON-NLS-1$
176
						+ "\" with arguments: {" //$NON-NLS-1$
185
						+ Util.toString(problemArguments)
177
						+ Util.toString(problemArguments)
186
						+"}"; //$NON-NLS-1$
178
						+"}"; //$NON-NLS-1$
(-)compiler/org/eclipse/jdt/core/compiler/CharOperation.java (-1 / +22 lines)
Lines 2845-2851 Link Here
2845
			count++;
2845
			count++;
2846
	return count;
2846
	return count;
2847
}
2847
}
2848
2848
/**
2849
 * Return the int value represented by the designated subpart of array. The 
2850
 * calculation of the result for single-digit positive integers is optimized in 
2851
 * time.
2852
 * @param array the array within which the int value is to be parsed
2853
 * @param start first character of the int value in array
2854
 * @param length length of the int value in array
2855
 * @return the int value of a subpart of array
2856
 * @throws NumberFormatException if the designated subpart of array does not
2857
 *         parse to an int
2858
 */
2859
public static final int parseInt(char[] array, int start, int length) throws NumberFormatException {
2860
	if (length == 1) {
2861
		int result = array[start] - '0';
2862
		if (result < 0 || result > 9) {
2863
			throw new NumberFormatException("invalid digit"); //$NON-NLS-1$
2864
		}
2865
		return result;
2866
	} else {
2867
		return Integer.parseInt(new String(array, start, length));
2868
	}
2869
}
2849
/**
2870
/**
2850
 * Answers true if the given name starts with the given prefix, false otherwise.
2871
 * Answers true if the given name starts with the given prefix, false otherwise.
2851
 * The comparison is case sensitive.
2872
 * The comparison is case sensitive.

Return to bug 206423