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

Collapse All | Expand All

(-)model/org/eclipse/jdt/core/IJavaModelMarker.java (-2 / +6 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:".
66
	 * <p>Empty argument is encoded as three spaces ("   ").</p>
64
	 *
67
	 *
65
	 * @since 2.0
68
	 * @since 2.0
69
	 * @see CorrectionEngine#getProblemArguments(IMarker)
66
	 */
70
	 */
67
	String ARGUMENTS = "arguments"; //$NON-NLS-1$
71
	String ARGUMENTS = "arguments"; //$NON-NLS-1$
68
72
(-)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 (-18 / +81 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-1071 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){
Lines 1075-1081 Link Here
1075
			return null;
1096
			return null;
1076
1097
1077
		int length = argumentsString.length();
1098
		int length = argumentsString.length();
1078
		int numberOfArg;
1099
		int numberOfArg = 0;
1079
		try{
1100
		try{
1080
			numberOfArg = Integer.parseInt(argumentsString.substring(0 , index));
1101
			numberOfArg = Integer.parseInt(argumentsString.substring(0 , index));
1081
		} catch (NumberFormatException e) {
1102
		} catch (NumberFormatException e) {
Lines 1083-1104 Link Here
1083
		}
1104
		}
1084
		argumentsString = argumentsString.substring(index + 1, length);
1105
		argumentsString = argumentsString.substring(index + 1, length);
1085
1106
1086
		String[] args = new String[length];
1107
		return decodeArgumentString(numberOfArg, argumentsString);
1087
		int count = 0;
1108
	}
1088
1109
1089
		StringTokenizer tokenizer = new StringTokenizer(argumentsString, ARGUMENTS_DELIMITER);
1110
	private static String[] decodeArgumentString(int length, String argumentsString) {
1090
		while(tokenizer.hasMoreTokens()) {
1111
		// decode the argumentString knowing that '#' is doubled if part of the argument value
1091
			String argument = tokenizer.nextToken();
1112
		if (length == 0) {
1092
			if(argument.equals(EMPTY_ARGUMENT))
1113
			if (argumentsString.length() != 0) {
1093
				argument = "";  //$NON-NLS-1$
1114
				return null;
1094
			args[count++] = argument;
1115
			}
1116
			return CharOperation.NO_STRINGS;
1095
		}
1117
		}
1096
1118
		String[] result = new String[length];
1097
		if(count != numberOfArg)
1119
		int count = 0;
1120
		StringBuffer buffer = new StringBuffer();
1121
		for (int i = 0, max = argumentsString.length(); i < max; i++) {
1122
			char current = argumentsString.charAt(i);
1123
			switch(current) {
1124
				case ARGUMENTS_DELIMITER :
1125
					/* check the next character. If this is also ARGUMENTS_DELIMITER then only put one into the
1126
					 * decoded argument and proceed with the next character
1127
					 */
1128
					if ((i + 1) == max) {
1129
						return null;
1130
					}
1131
					char next = argumentsString.charAt(i + 1);
1132
					if (next == ARGUMENTS_DELIMITER) {
1133
						buffer.append(ARGUMENTS_DELIMITER);
1134
						i++; // proceed with the next character
1135
					} else {
1136
						// this means the current argument is over
1137
						String currentArgumentContents = String.valueOf(buffer);
1138
						if (EMPTY_ARGUMENT.equals(currentArgumentContents)) {
1139
							currentArgumentContents = org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING;
1140
						}
1141
						result[count++] = currentArgumentContents;
1142
						if (count > length) {
1143
							// too many elements - ill-formed
1144
							return null;
1145
						}
1146
						buffer.delete(0, buffer.length());
1147
					}
1148
					break;
1149
				default :
1150
					buffer.append(current);
1151
			}
1152
		}
1153
		// process last argument
1154
		String currentArgumentContents = String.valueOf(buffer);
1155
		if (EMPTY_ARGUMENT.equals(currentArgumentContents)) {
1156
			currentArgumentContents = org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING;
1157
		}
1158
		result[count++] = currentArgumentContents;
1159
		if (count > length) {
1160
			// too many elements - ill-formed
1098
			return null;
1161
			return null;
1099
1162
		}
1100
		System.arraycopy(args, 0, args = new String[count], 0, count);
1163
		buffer.delete(0, buffer.length());
1101
		return args;
1164
		return result;
1102
	}
1165
	}
1103
1166
1104
	/**
1167
	/**
Lines 1382-1388 Link Here
1382
1445
1383
					}
1446
					}
1384
				} else {
1447
				} else {
1385
					parameterSignatures = new String[0];
1448
					parameterSignatures = CharOperation.NO_STRINGS;
1386
				}
1449
				}
1387
				return (JavaElement) declaringType.getMethod(String.valueOf(methodDeclaration.selector), parameterSignatures);
1450
				return (JavaElement) declaringType.getMethod(String.valueOf(methodDeclaration.selector), parameterSignatures);
1388
			}
1451
			}
(-)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 (+51 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
}

Return to bug 302587