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

Collapse All | Expand All

(-)model/org/eclipse/jdt/core/IJavaModelMarker.java (-3 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core;
11
package org.eclipse.jdt.core;
12
12
13
import org.eclipse.core.resources.IMarker;
14
13
/**
15
/**
14
 * Markers used by the Java model.
16
 * Markers used by the Java model.
15
 * <p>
17
 * <p>
Lines 60-68 Link Here
60
	 * Id marker attribute (value <code>"arguments"</code>). Arguments are
62
	 * Id marker attribute (value <code>"arguments"</code>). Arguments are
61
	 * concatenated into one String, prefixed with an argument count (followed
63
	 * concatenated into one String, prefixed with an argument count (followed
62
	 * with colon separator) and separated with '#' characters. For example: {
64
	 * with colon separator) and separated with '#' characters. For example: {
63
	 * "foo", "bar" } is encoded as "2:foo#bar", { } is encoded as "0: "
65
	 * "foo", "bar" } is encoded as "2:foo#bar", { } is encoded as "0:".
64
	 *
66
	 * <p>Empty argument is encoded as three spaces ("   ").</p>
67
	 * <p>If the argument contains a '#', the character is doubled.<br>
68
	 * {"foo#test", "bar" } is encoded as "2:foo##test#bar"
69
	 * </p>
70
	 * 
65
	 * @since 2.0
71
	 * @since 2.0
72
	 * @see CorrectionEngine#getProblemArguments(IMarker)
66
	 */
73
	 */
67
	String ARGUMENTS = "arguments"; //$NON-NLS-1$
74
	String ARGUMENTS = "arguments"; //$NON-NLS-1$
68
75
(-)model/org/eclipse/jdt/internal/core/ClassFileInfo.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 139-145 Link Here
139
	final Object value;
139
	final Object value;
140
	if (values.size() == 0) {
140
	if (values.size() == 0) {
141
		if ((tagBits & TagBits.AnnotationTarget) != 0)
141
		if ((tagBits & TagBits.AnnotationTarget) != 0)
142
			value = new String[0];
142
			value = CharOperation.NO_STRINGS;
143
		else
143
		else
144
			return Annotation.NO_MEMBER_VALUE_PAIRS;
144
			return Annotation.NO_MEMBER_VALUE_PAIRS;
145
	} else if (values.size() == 1) {
145
	} else if (values.size() == 1) {
(-)model/org/eclipse/jdt/internal/core/util/Util.java (-19 / +84 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 95-101 Link Here
95
		public org.eclipse.jdt.internal.compiler.ast.ASTNode get(Binding binding);
95
		public org.eclipse.jdt.internal.compiler.ast.ASTNode get(Binding binding);
96
	}
96
	}
97
97
98
	private static final String ARGUMENTS_DELIMITER = "#"; //$NON-NLS-1$
98
	private static final char ARGUMENTS_DELIMITER = '#';
99
99
100
	private static final String EMPTY_ARGUMENT = "   "; //$NON-NLS-1$
100
	private static final String EMPTY_ARGUMENT = "   "; //$NON-NLS-1$
101
101
Lines 1058-1064 Link Here
1058
			if(arguments[j].length() == 0) {
1058
			if(arguments[j].length() == 0) {
1059
				args.append(EMPTY_ARGUMENT);
1059
				args.append(EMPTY_ARGUMENT);
1060
			} else {
1060
			} else {
1061
				args.append(arguments[j]);
1061
				encodeArgument(arguments[j], args);
1062
			}
1062
			}
1063
		}
1063
		}
1064
1064
Lines 1066-1081 Link Here
1066
	}
1066
	}
1067
1067
1068
	/**
1068
	/**
1069
	 * Encode the argument by doubling the '#' if present into the argument value.
1070
	 * 
1071
	 * <p>This stores the encoded argument into the given buffer.</p>
1072
	 *
1073
	 * @param argument the given argument
1074
	 * @param buffer the buffer in which the encoded argument is stored
1075
	 */
1076
	private static void encodeArgument(String argument, StringBuffer buffer) {
1077
		for (int i = 0, max = argument.length(); i < max; i++) {
1078
			char charAt = argument.charAt(i);
1079
			switch(charAt) {
1080
				case ARGUMENTS_DELIMITER :
1081
					buffer.append(ARGUMENTS_DELIMITER).append(ARGUMENTS_DELIMITER);
1082
					break;
1083
				default:
1084
					buffer.append(charAt);
1085
			}
1086
		}
1087
	}
1088
1089
	/**
1069
	 * Separate all the arguments of a String made by getProblemArgumentsForMarker
1090
	 * Separate all the arguments of a String made by getProblemArgumentsForMarker
1070
	 */
1091
	 */
1071
	public static String[] getProblemArgumentsFromMarker(String argumentsString){
1092
	public static String[] getProblemArgumentsFromMarker(String argumentsString){
1072
		if (argumentsString == null) return null;
1093
		if (argumentsString == null) {
1094
			return null;
1095
		}
1073
		int index = argumentsString.indexOf(':');
1096
		int index = argumentsString.indexOf(':');
1074
		if(index == -1)
1097
		if(index == -1)
1075
			return null;
1098
			return null;
1076
1099
1077
		int length = argumentsString.length();
1100
		int length = argumentsString.length();
1078
		int numberOfArg;
1101
		int numberOfArg = 0;
1079
		try{
1102
		try{
1080
			numberOfArg = Integer.parseInt(argumentsString.substring(0 , index));
1103
			numberOfArg = Integer.parseInt(argumentsString.substring(0 , index));
1081
		} catch (NumberFormatException e) {
1104
		} catch (NumberFormatException e) {
Lines 1083-1104 Link Here
1083
		}
1106
		}
1084
		argumentsString = argumentsString.substring(index + 1, length);
1107
		argumentsString = argumentsString.substring(index + 1, length);
1085
1108
1086
		String[] args = new String[length];
1109
		return decodeArgumentString(numberOfArg, argumentsString);
1087
		int count = 0;
1110
	}
1088
1111
1089
		StringTokenizer tokenizer = new StringTokenizer(argumentsString, ARGUMENTS_DELIMITER);
1112
	private static String[] decodeArgumentString(int length, String argumentsString) {
1090
		while(tokenizer.hasMoreTokens()) {
1113
		// decode the argumentString knowing that '#' is doubled if part of the argument value
1091
			String argument = tokenizer.nextToken();
1114
		if (length == 0) {
1092
			if(argument.equals(EMPTY_ARGUMENT))
1115
			if (argumentsString.length() != 0) {
1093
				argument = "";  //$NON-NLS-1$
1116
				return null;
1094
			args[count++] = argument;
1117
			}
1118
			return CharOperation.NO_STRINGS;
1095
		}
1119
		}
1096
1120
		String[] result = new String[length];
1097
		if(count != numberOfArg)
1121
		int count = 0;
1122
		StringBuffer buffer = new StringBuffer();
1123
		for (int i = 0, max = argumentsString.length(); i < max; i++) {
1124
			char current = argumentsString.charAt(i);
1125
			switch(current) {
1126
				case ARGUMENTS_DELIMITER :
1127
					/* check the next character. If this is also ARGUMENTS_DELIMITER then only put one into the
1128
					 * decoded argument and proceed with the next character
1129
					 */
1130
					if ((i + 1) == max) {
1131
						return null;
1132
					}
1133
					char next = argumentsString.charAt(i + 1);
1134
					if (next == ARGUMENTS_DELIMITER) {
1135
						buffer.append(ARGUMENTS_DELIMITER);
1136
						i++; // proceed with the next character
1137
					} else {
1138
						// this means the current argument is over
1139
						String currentArgumentContents = String.valueOf(buffer);
1140
						if (EMPTY_ARGUMENT.equals(currentArgumentContents)) {
1141
							currentArgumentContents = org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING;
1142
						}
1143
						result[count++] = currentArgumentContents;
1144
						if (count > length) {
1145
							// too many elements - ill-formed
1146
							return null;
1147
						}
1148
						buffer.delete(0, buffer.length());
1149
					}
1150
					break;
1151
				default :
1152
					buffer.append(current);
1153
			}
1154
		}
1155
		// process last argument
1156
		String currentArgumentContents = String.valueOf(buffer);
1157
		if (EMPTY_ARGUMENT.equals(currentArgumentContents)) {
1158
			currentArgumentContents = org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING;
1159
		}
1160
		result[count++] = currentArgumentContents;
1161
		if (count > length) {
1162
			// too many elements - ill-formed
1098
			return null;
1163
			return null;
1099
1164
		}
1100
		System.arraycopy(args, 0, args = new String[count], 0, count);
1165
		buffer.delete(0, buffer.length());
1101
		return args;
1166
		return result;
1102
	}
1167
	}
1103
1168
1104
	/**
1169
	/**
Lines 1382-1388 Link Here
1382
1447
1383
					}
1448
					}
1384
				} else {
1449
				} else {
1385
					parameterSignatures = new String[0];
1450
					parameterSignatures = CharOperation.NO_STRINGS;
1386
				}
1451
				}
1387
				return (JavaElement) declaringType.getMethod(String.valueOf(methodDeclaration.selector), parameterSignatures);
1452
				return (JavaElement) declaringType.getMethod(String.valueOf(methodDeclaration.selector), parameterSignatures);
1388
			}
1453
			}
(-)src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java (+3 lines)
Lines 180-185 Link Here
180
180
181
		// Creation of imports
181
		// Creation of imports
182
		CreateImportsTests.class,
182
		CreateImportsTests.class,
183
		
184
		// Util tests
185
		UtilTests.class,
183
	};
186
	};
184
187
185
	Class[] deprecatedClasses = getDeprecatedJDOMTestClasses();
188
	Class[] deprecatedClasses = getDeprecatedJDOMTestClasses();
(-)src/org/eclipse/jdt/core/tests/model/UtilTests.java (+78 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
12
13
import org.eclipse.jdt.internal.core.util.Util;
14
15
import junit.framework.Test;
16
17
public class UtilTests extends AbstractJavaModelTests {
18
19
	static {
20
//		TESTS_PREFIX = "testInvalidCompilerOptions";
21
//		TESTS_NAMES = new String[] { "test028"};
22
	}
23
24
	public UtilTests(String name) {
25
		super(name);
26
	}
27
28
	public static Test suite() {
29
		return buildModelTestSuite(UtilTests.class);
30
	}
31
	public void test001() {
32
		String[] arguments = Util.getProblemArgumentsFromMarker("1:foo");
33
		assertStringsEqual("Wrong arguments", new String[] {"foo"}, arguments);
34
	}
35
	public void test002() {
36
		String[] arguments = Util.getProblemArgumentsFromMarker("2:foo#bar");
37
		assertStringsEqual("Wrong arguments", new String[] {"foo", "bar"}, arguments);
38
	}
39
	public void test003() {
40
		String[] arguments = Util.getProblemArgumentsFromMarker("1:   ");
41
		assertStringsEqual("Wrong arguments", new String[] {""}, arguments);
42
	}
43
	public void test004() {
44
		String[] arguments = Util.getProblemArgumentsFromMarker("0:");
45
		assertStringsEqual("Wrong arguments", new String[0], arguments);
46
	}
47
	public void test005() {
48
		String[] arguments = Util.getProblemArgumentsFromMarker("3:Task<capture##1-of ?>#getTaskListeners#   ");
49
		assertStringsEqual("Wrong arguments", new String[] {"Task<capture#1-of ?>", "getTaskListeners", ""}, arguments);
50
	}
51
	public void test006() {
52
		String[] arguments = new String[] {"Task<capture#1-of ?>", "getTaskListeners", ""};
53
		String[] result = Util.getProblemArgumentsFromMarker(Util.getProblemArgumentsForMarker(arguments));
54
		assertStringsEqual("Wrong arguments", arguments, result);
55
	}
56
	public void test007() {
57
		assertNull("Not null", Util.getProblemArgumentsFromMarker("tt:Task<capture##1-of ?>#getTaskListeners#   "));
58
	}
59
	public void test008() {
60
		assertNull("Not null", Util.getProblemArgumentsFromMarker("3Task<capture##1-of ?>#getTaskListeners#   "));
61
	}
62
	public void test009() {
63
		assertNull("Not null", Util.getProblemArgumentsFromMarker(null));
64
	}
65
	public void test010() {
66
		assertNull("Not null", Util.getProblemArgumentsFromMarker("0:Task"));
67
	}
68
	public void test011() {
69
		String[] arguments = new String[] {"", "", ""};
70
		String[] result = Util.getProblemArgumentsFromMarker(Util.getProblemArgumentsForMarker(arguments));
71
		assertStringsEqual("Wrong arguments", arguments, result);
72
	}
73
	public void test012() {
74
		String[] arguments = new String[] {"foo#test", "bar"};
75
		String[] result = Util.getProblemArgumentsFromMarker(Util.getProblemArgumentsForMarker(arguments));
76
		assertStringsEqual("Wrong arguments", arguments, result);
77
	}
78
}

Return to bug 302587