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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java (-3 / +16 lines)
Lines 1-23 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 BEA Systems, Inc.
2
 * Copyright (c) 2005, 2011 BEA Systems, Inc.
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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    tyeung@bea.com - initial API and implementation
9
 *    tyeung@bea.com  - initial API and implementation
10
 *    IBM Corporation - fix for bug 342757
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
13
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
14
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
15
import org.eclipse.jdt.internal.compiler.util.Util;
14
16
15
class MethodInfoWithParameterAnnotations extends MethodInfoWithAnnotations {
17
class MethodInfoWithParameterAnnotations extends MethodInfoWithAnnotations {
16
	private AnnotationInfo[][] parameterAnnotations;
18
	private AnnotationInfo[][] parameterAnnotations;
17
19
18
MethodInfoWithParameterAnnotations(MethodInfo methodInfo, AnnotationInfo[] annotations, AnnotationInfo[][] parameterAnnotations) {
20
MethodInfoWithParameterAnnotations(MethodInfo methodInfo, AnnotationInfo[] annotations, AnnotationInfo[][] parameterAnnotations) {
19
	super(methodInfo, annotations);
21
	super(methodInfo, annotations);
20
	this.parameterAnnotations = parameterAnnotations;
22
	if (methodInfo.isConstructor()) {
23
		int parametersCount = Util.getParameterCount(methodInfo.getMethodDescriptor());
24
		if (parameterAnnotations.length < parametersCount) {
25
			AnnotationInfo[][] temp = new AnnotationInfo[parametersCount][];
26
			System.arraycopy(parameterAnnotations, 0, temp, 1, parameterAnnotations.length);
27
			this.parameterAnnotations = temp;
28
		} else {
29
			this.parameterAnnotations = parameterAnnotations;
30
		}
31
	} else {
32
		this.parameterAnnotations = parameterAnnotations;
33
	}
21
}
34
}
22
35
23
public IBinaryAnnotation[] getParameterAnnotations(int index) {
36
public IBinaryAnnotation[] getParameterAnnotations(int index) {
(-)compiler/org/eclipse/jdt/internal/compiler/util/Util.java (-1 / +580 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 46-51 Link Here
46
46
47
public class Util implements SuffixConstants {
47
public class Util implements SuffixConstants {
48
48
49
	/**
50
	 * Character constant indicating the primitive type boolean in a signature.
51
	 * Value is <code>'Z'</code>.
52
	 */
53
	public static final char C_BOOLEAN 		= 'Z';
54
55
	/**
56
	 * Character constant indicating the primitive type byte in a signature.
57
	 * Value is <code>'B'</code>.
58
	 */
59
	public static final char C_BYTE 		= 'B';
60
61
	/**
62
	 * Character constant indicating the primitive type char in a signature.
63
	 * Value is <code>'C'</code>.
64
	 */
65
	public static final char C_CHAR 		= 'C';
66
67
	/**
68
	 * Character constant indicating the primitive type double in a signature.
69
	 * Value is <code>'D'</code>.
70
	 */
71
	public static final char C_DOUBLE 		= 'D';
72
73
	/**
74
	 * Character constant indicating the primitive type float in a signature.
75
	 * Value is <code>'F'</code>.
76
	 */
77
	public static final char C_FLOAT 		= 'F';
78
79
	/**
80
	 * Character constant indicating the primitive type int in a signature.
81
	 * Value is <code>'I'</code>.
82
	 */
83
	public static final char C_INT 			= 'I';
84
85
	/**
86
	 * Character constant indicating the semicolon in a signature.
87
	 * Value is <code>';'</code>.
88
	 */
89
	public static final char C_SEMICOLON 			= ';';
90
91
	/**
92
	 * Character constant indicating the colon in a signature.
93
	 * Value is <code>':'</code>.
94
	 * @since 3.0
95
	 */
96
	public static final char C_COLON 			= ':';
97
98
	/**
99
	 * Character constant indicating the primitive type long in a signature.
100
	 * Value is <code>'J'</code>.
101
	 */
102
	public static final char C_LONG			= 'J';
103
104
	/**
105
	 * Character constant indicating the primitive type short in a signature.
106
	 * Value is <code>'S'</code>.
107
	 */
108
	public static final char C_SHORT		= 'S';
109
110
	/**
111
	 * Character constant indicating result type void in a signature.
112
	 * Value is <code>'V'</code>.
113
	 */
114
	public static final char C_VOID			= 'V';
115
116
	/**
117
	 * Character constant indicating the start of a resolved type variable in a
118
	 * signature. Value is <code>'T'</code>.
119
	 * @since 3.0
120
	 */
121
	public static final char C_TYPE_VARIABLE	= 'T';
122
123
	/**
124
	 * Character constant indicating an unbound wildcard type argument
125
	 * in a signature.
126
	 * Value is <code>'*'</code>.
127
	 * @since 3.0
128
	 */
129
	public static final char C_STAR	= '*';
130
131
	/**
132
	 * Character constant indicating an exception in a signature.
133
	 * Value is <code>'^'</code>.
134
	 * @since 3.1
135
	 */
136
	public static final char C_EXCEPTION_START	= '^';
137
138
	/**
139
	 * Character constant indicating a bound wildcard type argument
140
	 * in a signature with extends clause.
141
	 * Value is <code>'+'</code>.
142
	 * @since 3.1
143
	 */
144
	public static final char C_EXTENDS	= '+';
145
146
	/**
147
	 * Character constant indicating a bound wildcard type argument
148
	 * in a signature with super clause.
149
	 * Value is <code>'-'</code>.
150
	 * @since 3.1
151
	 */
152
	public static final char C_SUPER	= '-';
153
154
	/**
155
	 * Character constant indicating the dot in a signature.
156
	 * Value is <code>'.'</code>.
157
	 */
158
	public static final char C_DOT			= '.';
159
160
	/**
161
	 * Character constant indicating the dollar in a signature.
162
	 * Value is <code>'$'</code>.
163
	 */
164
	public static final char C_DOLLAR			= '$';
165
166
	/**
167
	 * Character constant indicating an array type in a signature.
168
	 * Value is <code>'['</code>.
169
	 */
170
	public static final char C_ARRAY		= '[';
171
172
	/**
173
	 * Character constant indicating the start of a resolved, named type in a
174
	 * signature. Value is <code>'L'</code>.
175
	 */
176
	public static final char C_RESOLVED		= 'L';
177
178
	/**
179
	 * Character constant indicating the start of an unresolved, named type in a
180
	 * signature. Value is <code>'Q'</code>.
181
	 */
182
	public static final char C_UNRESOLVED	= 'Q';
183
184
	/**
185
	 * Character constant indicating the end of a named type in a signature.
186
	 * Value is <code>';'</code>.
187
	 */
188
	public static final char C_NAME_END		= ';';
189
190
	/**
191
	 * Character constant indicating the start of a parameter type list in a
192
	 * signature. Value is <code>'('</code>.
193
	 */
194
	public static final char C_PARAM_START	= '(';
195
196
	/**
197
	 * Character constant indicating the end of a parameter type list in a
198
	 * signature. Value is <code>')'</code>.
199
	 */
200
	public static final char C_PARAM_END	= ')';
201
202
	/**
203
	 * Character constant indicating the start of a formal type parameter
204
	 * (or type argument) list in a signature. Value is <code>'&lt;'</code>.
205
	 * @since 3.0
206
	 */
207
	public static final char C_GENERIC_START	= '<';
208
209
	/**
210
	 * Character constant indicating the end of a generic type list in a
211
	 * signature. Value is <code>'&gt;'</code>.
212
	 * @since 3.0
213
	 */
214
	public static final char C_GENERIC_END	= '>';
215
216
	/**
217
	 * Character constant indicating a capture of a wildcard type in a
218
	 * signature. Value is <code>'!'</code>.
219
	 * @since 3.1
220
	 */
221
	public static final char C_CAPTURE	= '!';
222
49
	public interface Displayable {
223
	public interface Displayable {
50
		String displayString(Object o);
224
		String displayString(Object o);
51
	}
225
	}
Lines 977-980 Link Here
977
			}
1151
			}
978
		}
1152
		}
979
	}
1153
	}
1154
	public static int getParameterCount(char[] methodSignature) {
1155
		try {
1156
			int count = 0;
1157
			int i = CharOperation.indexOf(C_PARAM_START, methodSignature);
1158
			if (i < 0) {
1159
				throw new IllegalArgumentException();
1160
			} else {
1161
				i++;
1162
			}
1163
			for (;;) {
1164
				if (methodSignature[i] == C_PARAM_END) {
1165
					return count;
1166
				}
1167
				int e= Util.scanTypeSignature(methodSignature, i);
1168
				if (e < 0) {
1169
					throw new IllegalArgumentException();
1170
				} else {
1171
					i = e + 1;
1172
				}
1173
				count++;
1174
			}
1175
		} catch (ArrayIndexOutOfBoundsException e) {
1176
			throw new IllegalArgumentException();
1177
		}
1178
	}
1179
1180
	/**
1181
	 * Scans the given string for a type signature starting at the given index
1182
	 * and returns the index of the last character.
1183
	 * <pre>
1184
	 * TypeSignature:
1185
	 *  |  BaseTypeSignature
1186
	 *  |  ArrayTypeSignature
1187
	 *  |  ClassTypeSignature
1188
	 *  |  TypeVariableSignature
1189
	 * </pre>
1190
	 *
1191
	 * @param string the signature string
1192
	 * @param start the 0-based character index of the first character
1193
	 * @return the 0-based character index of the last character
1194
	 * @exception IllegalArgumentException if this is not a type signature
1195
	 */
1196
	public static int scanTypeSignature(char[] string, int start) {
1197
		// need a minimum 1 char
1198
		if (start >= string.length) {
1199
			throw new IllegalArgumentException();
1200
		}
1201
		char c = string[start];
1202
		switch (c) {
1203
			case C_ARRAY :
1204
				return scanArrayTypeSignature(string, start);
1205
			case C_RESOLVED :
1206
			case C_UNRESOLVED :
1207
				return scanClassTypeSignature(string, start);
1208
			case C_TYPE_VARIABLE :
1209
				return scanTypeVariableSignature(string, start);
1210
			case C_BOOLEAN :
1211
			case C_BYTE :
1212
			case C_CHAR :
1213
			case C_DOUBLE :
1214
			case C_FLOAT :
1215
			case C_INT :
1216
			case C_LONG :
1217
			case C_SHORT :
1218
			case C_VOID :
1219
				return scanBaseTypeSignature(string, start);
1220
			case C_CAPTURE :
1221
				return scanCaptureTypeSignature(string, start);
1222
			case C_EXTENDS:
1223
			case C_SUPER:
1224
			case C_STAR:
1225
				return scanTypeBoundSignature(string, start);
1226
			default :
1227
				throw new IllegalArgumentException();
1228
		}
1229
	}
1230
1231
	/**
1232
	 * Scans the given string for a base type signature starting at the given index
1233
	 * and returns the index of the last character.
1234
	 * <pre>
1235
	 * BaseTypeSignature:
1236
	 *     <b>B</b> | <b>C</b> | <b>D</b> | <b>F</b> | <b>I</b>
1237
	 *   | <b>J</b> | <b>S</b> | <b>V</b> | <b>Z</b>
1238
	 * </pre>
1239
	 * Note that although the base type "V" is only allowed in method return types,
1240
	 * there is no syntactic ambiguity. This method will accept them anywhere
1241
	 * without complaint.
1242
	 *
1243
	 * @param string the signature string
1244
	 * @param start the 0-based character index of the first character
1245
	 * @return the 0-based character index of the last character
1246
	 * @exception IllegalArgumentException if this is not a base type signature
1247
	 */
1248
	public static int scanBaseTypeSignature(char[] string, int start) {
1249
		// need a minimum 1 char
1250
		if (start >= string.length) {
1251
			throw new IllegalArgumentException();
1252
		}
1253
		char c = string[start];
1254
		if ("BCDFIJSVZ".indexOf(c) >= 0) { //$NON-NLS-1$
1255
			return start;
1256
		} else {
1257
			throw new IllegalArgumentException();
1258
		}
1259
	}
1260
1261
	/**
1262
	 * Scans the given string for an array type signature starting at the given
1263
	 * index and returns the index of the last character.
1264
	 * <pre>
1265
	 * ArrayTypeSignature:
1266
	 *     <b>[</b> TypeSignature
1267
	 * </pre>
1268
	 *
1269
	 * @param string the signature string
1270
	 * @param start the 0-based character index of the first character
1271
	 * @return the 0-based character index of the last character
1272
	 * @exception IllegalArgumentException if this is not an array type signature
1273
	 */
1274
	public static int scanArrayTypeSignature(char[] string, int start) {
1275
		int length = string.length;
1276
		// need a minimum 2 char
1277
		if (start >= length - 1) {
1278
			throw new IllegalArgumentException();
1279
		}
1280
		char c = string[start];
1281
		if (c != C_ARRAY) {
1282
			throw new IllegalArgumentException();
1283
		}
1284
	
1285
		c = string[++start];
1286
		while(c == C_ARRAY) {
1287
			// need a minimum 2 char
1288
			if (start >= length - 1) {
1289
				throw new IllegalArgumentException();
1290
			}
1291
			c = string[++start];
1292
		}
1293
		return scanTypeSignature(string, start);
1294
	}
1295
1296
	/**
1297
	 * Scans the given string for a capture of a wildcard type signature starting at the given
1298
	 * index and returns the index of the last character.
1299
	 * <pre>
1300
	 * CaptureTypeSignature:
1301
	 *     <b>!</b> TypeBoundSignature
1302
	 * </pre>
1303
	 *
1304
	 * @param string the signature string
1305
	 * @param start the 0-based character index of the first character
1306
	 * @return the 0-based character index of the last character
1307
	 * @exception IllegalArgumentException if this is not a capture type signature
1308
	 */
1309
	public static int scanCaptureTypeSignature(char[] string, int start) {
1310
		// need a minimum 2 char
1311
		if (start >= string.length - 1) {
1312
			throw new IllegalArgumentException();
1313
		}
1314
		char c = string[start];
1315
		if (c != C_CAPTURE) {
1316
			throw new IllegalArgumentException();
1317
		}
1318
		return scanTypeBoundSignature(string, start + 1);
1319
	}
1320
1321
	/**
1322
	 * Scans the given string for a type variable signature starting at the given
1323
	 * index and returns the index of the last character.
1324
	 * <pre>
1325
	 * TypeVariableSignature:
1326
	 *     <b>T</b> Identifier <b>;</b>
1327
	 * </pre>
1328
	 *
1329
	 * @param string the signature string
1330
	 * @param start the 0-based character index of the first character
1331
	 * @return the 0-based character index of the last character
1332
	 * @exception IllegalArgumentException if this is not a type variable signature
1333
	 */
1334
	public static int scanTypeVariableSignature(char[] string, int start) {
1335
		// need a minimum 3 chars "Tx;"
1336
		if (start >= string.length - 2) {
1337
			throw new IllegalArgumentException();
1338
		}
1339
		// must start in "T"
1340
		char c = string[start];
1341
		if (c != C_TYPE_VARIABLE) {
1342
			throw new IllegalArgumentException();
1343
		}
1344
		int id = scanIdentifier(string, start + 1);
1345
		c = string[id + 1];
1346
		if (c == C_SEMICOLON) {
1347
			return id + 1;
1348
		} else {
1349
			throw new IllegalArgumentException();
1350
		}
1351
	}
1352
1353
	/**
1354
	 * Scans the given string for an identifier starting at the given
1355
	 * index and returns the index of the last character.
1356
	 * Stop characters are: ";", ":", "&lt;", "&gt;", "/", ".".
1357
	 *
1358
	 * @param string the signature string
1359
	 * @param start the 0-based character index of the first character
1360
	 * @return the 0-based character index of the last character
1361
	 * @exception IllegalArgumentException if this is not an identifier
1362
	 */
1363
	public static int scanIdentifier(char[] string, int start) {
1364
		// need a minimum 1 char
1365
		if (start >= string.length) {
1366
			throw new IllegalArgumentException();
1367
		}
1368
		int p = start;
1369
		while (true) {
1370
			char c = string[p];
1371
			if (c == '<' || c == '>' || c == ':' || c == ';' || c == '.' || c == '/') {
1372
				return p - 1;
1373
			}
1374
			p++;
1375
			if (p == string.length) {
1376
				return p - 1;
1377
			}
1378
		}
1379
	}
1380
1381
	/**
1382
	 * Scans the given string for a class type signature starting at the given
1383
	 * index and returns the index of the last character.
1384
	 * <pre>
1385
	 * ClassTypeSignature:
1386
	 *     { <b>L</b> | <b>Q</b> } Identifier
1387
	 *           { { <b>/</b> | <b>.</b> Identifier [ <b>&lt;</b> TypeArgumentSignature* <b>&gt;</b> ] }
1388
	 *           <b>;</b>
1389
	 * </pre>
1390
	 * Note that although all "/"-identifiers most come before "."-identifiers,
1391
	 * there is no syntactic ambiguity. This method will accept them without
1392
	 * complaint.
1393
	 *
1394
	 * @param string the signature string
1395
	 * @param start the 0-based character index of the first character
1396
	 * @return the 0-based character index of the last character
1397
	 * @exception IllegalArgumentException if this is not a class type signature
1398
	 */
1399
	public static int scanClassTypeSignature(char[] string, int start) {
1400
		// need a minimum 3 chars "Lx;"
1401
		if (start >= string.length - 2) {
1402
			throw new IllegalArgumentException();
1403
		}
1404
		// must start in "L" or "Q"
1405
		char c = string[start];
1406
		if (c != C_RESOLVED && c != C_UNRESOLVED) {
1407
			return -1;
1408
		}
1409
		int p = start + 1;
1410
		while (true) {
1411
			if (p >= string.length) {
1412
				throw new IllegalArgumentException();
1413
			}
1414
			c = string[p];
1415
			if (c == C_SEMICOLON) {
1416
				// all done
1417
				return p;
1418
			} else if (c == C_GENERIC_START) {
1419
				int e = scanTypeArgumentSignatures(string, p);
1420
				p = e;
1421
			} else if (c == C_DOT || c == '/') {
1422
				int id = scanIdentifier(string, p + 1);
1423
				p = id;
1424
			}
1425
			p++;
1426
		}
1427
	}
1428
1429
	/**
1430
	 * Scans the given string for a type bound signature starting at the given
1431
	 * index and returns the index of the last character.
1432
	 * <pre>
1433
	 * TypeBoundSignature:
1434
	 *     <b>[-+]</b> TypeSignature <b>;</b>
1435
	 *     <b>*</b></b>
1436
	 * </pre>
1437
	 *
1438
	 * @param string the signature string
1439
	 * @param start the 0-based character index of the first character
1440
	 * @return the 0-based character index of the last character
1441
	 * @exception IllegalArgumentException if this is not a type variable signature
1442
	 */
1443
	public static int scanTypeBoundSignature(char[] string, int start) {
1444
		// need a minimum 1 char for wildcard
1445
		if (start >= string.length) {
1446
			throw new IllegalArgumentException();
1447
		}
1448
		char c = string[start];
1449
		switch (c) {
1450
			case C_STAR :
1451
				return start;
1452
			case C_SUPER :
1453
			case C_EXTENDS :
1454
				// need a minimum 3 chars "+[I"
1455
				if (start >= string.length - 2) {
1456
					throw new IllegalArgumentException();
1457
				}
1458
				break;
1459
			default :
1460
				// must start in "+/-"
1461
					throw new IllegalArgumentException();
1462
	
1463
		}
1464
		c = string[++start];
1465
		switch (c) {
1466
			case C_CAPTURE :
1467
				return scanCaptureTypeSignature(string, start);
1468
			case C_SUPER :
1469
			case C_EXTENDS :
1470
				return scanTypeBoundSignature(string, start);
1471
			case C_RESOLVED :
1472
			case C_UNRESOLVED :
1473
				return scanClassTypeSignature(string, start);
1474
			case C_TYPE_VARIABLE :
1475
				return scanTypeVariableSignature(string, start);
1476
			case C_ARRAY :
1477
				return scanArrayTypeSignature(string, start);
1478
			case C_STAR:
1479
				return start;
1480
			default:
1481
				throw new IllegalArgumentException();
1482
		}
1483
	}
1484
1485
	/**
1486
	 * Scans the given string for a list of type argument signatures starting at
1487
	 * the given index and returns the index of the last character.
1488
	 * <pre>
1489
	 * TypeArgumentSignatures:
1490
	 *     <b>&lt;</b> TypeArgumentSignature* <b>&gt;</b>
1491
	 * </pre>
1492
	 * Note that although there is supposed to be at least one type argument, there
1493
	 * is no syntactic ambiguity if there are none. This method will accept zero
1494
	 * type argument signatures without complaint.
1495
	 *
1496
	 * @param string the signature string
1497
	 * @param start the 0-based character index of the first character
1498
	 * @return the 0-based character index of the last character
1499
	 * @exception IllegalArgumentException if this is not a list of type arguments
1500
	 * signatures
1501
	 */
1502
	public static int scanTypeArgumentSignatures(char[] string, int start) {
1503
		// need a minimum 2 char "<>"
1504
		if (start >= string.length - 1) {
1505
			throw new IllegalArgumentException();
1506
		}
1507
		char c = string[start];
1508
		if (c != C_GENERIC_START) {
1509
			throw new IllegalArgumentException();
1510
		}
1511
		int p = start + 1;
1512
		while (true) {
1513
			if (p >= string.length) {
1514
				throw new IllegalArgumentException();
1515
			}
1516
			c = string[p];
1517
			if (c == C_GENERIC_END) {
1518
				return p;
1519
			}
1520
			int e = scanTypeArgumentSignature(string, p);
1521
			p = e + 1;
1522
		}
1523
	}
1524
1525
	/**
1526
	 * Scans the given string for a type argument signature starting at the given
1527
	 * index and returns the index of the last character.
1528
	 * <pre>
1529
	 * TypeArgumentSignature:
1530
	 *     <b>&#42;</b>
1531
	 *  |  <b>+</b> TypeSignature
1532
	 *  |  <b>-</b> TypeSignature
1533
	 *  |  TypeSignature
1534
	 * </pre>
1535
	 * Note that although base types are not allowed in type arguments, there is
1536
	 * no syntactic ambiguity. This method will accept them without complaint.
1537
	 *
1538
	 * @param string the signature string
1539
	 * @param start the 0-based character index of the first character
1540
	 * @return the 0-based character index of the last character
1541
	 * @exception IllegalArgumentException if this is not a type argument signature
1542
	 */
1543
	public static int scanTypeArgumentSignature(char[] string, int start) {
1544
		// need a minimum 1 char
1545
		if (start >= string.length) {
1546
			throw new IllegalArgumentException();
1547
		}
1548
		char c = string[start];
1549
		switch (c) {
1550
			case C_STAR :
1551
				return start;
1552
			case C_EXTENDS :
1553
			case C_SUPER :
1554
				return scanTypeBoundSignature(string, start);
1555
			default :
1556
				return scanTypeSignature(string, start);
1557
		}
1558
	}
980
}
1559
}
(-)model/org/eclipse/jdt/core/Signature.java (-30 / +29 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 15-22 Link Here
15
15
16
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
17
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
18
import org.eclipse.jdt.internal.core.util.Util;
18
import org.eclipse.jdt.internal.compiler.util.Util;
19
20
19
21
/**
20
/**
22
 * Provides methods for encoding and decoding type and method signature strings.
21
 * Provides methods for encoding and decoding type and method signature strings.
Lines 149-223 Link Here
149
	 * Character constant indicating the primitive type boolean in a signature.
148
	 * Character constant indicating the primitive type boolean in a signature.
150
	 * Value is <code>'Z'</code>.
149
	 * Value is <code>'Z'</code>.
151
	 */
150
	 */
152
	public static final char C_BOOLEAN 		= 'Z';
151
	public static final char C_BOOLEAN = org.eclipse.jdt.internal.compiler.util.Util.C_BOOLEAN;
153
152
154
	/**
153
	/**
155
	 * Character constant indicating the primitive type byte in a signature.
154
	 * Character constant indicating the primitive type byte in a signature.
156
	 * Value is <code>'B'</code>.
155
	 * Value is <code>'B'</code>.
157
	 */
156
	 */
158
	public static final char C_BYTE 		= 'B';
157
	public static final char C_BYTE = org.eclipse.jdt.internal.compiler.util.Util.C_BYTE;
159
158
160
	/**
159
	/**
161
	 * Character constant indicating the primitive type char in a signature.
160
	 * Character constant indicating the primitive type char in a signature.
162
	 * Value is <code>'C'</code>.
161
	 * Value is <code>'C'</code>.
163
	 */
162
	 */
164
	public static final char C_CHAR 		= 'C';
163
	public static final char C_CHAR = org.eclipse.jdt.internal.compiler.util.Util.C_CHAR;
165
164
166
	/**
165
	/**
167
	 * Character constant indicating the primitive type double in a signature.
166
	 * Character constant indicating the primitive type double in a signature.
168
	 * Value is <code>'D'</code>.
167
	 * Value is <code>'D'</code>.
169
	 */
168
	 */
170
	public static final char C_DOUBLE 		= 'D';
169
	public static final char C_DOUBLE = org.eclipse.jdt.internal.compiler.util.Util.C_DOUBLE;
171
170
172
	/**
171
	/**
173
	 * Character constant indicating the primitive type float in a signature.
172
	 * Character constant indicating the primitive type float in a signature.
174
	 * Value is <code>'F'</code>.
173
	 * Value is <code>'F'</code>.
175
	 */
174
	 */
176
	public static final char C_FLOAT 		= 'F';
175
	public static final char C_FLOAT = org.eclipse.jdt.internal.compiler.util.Util.C_FLOAT;
177
176
178
	/**
177
	/**
179
	 * Character constant indicating the primitive type int in a signature.
178
	 * Character constant indicating the primitive type int in a signature.
180
	 * Value is <code>'I'</code>.
179
	 * Value is <code>'I'</code>.
181
	 */
180
	 */
182
	public static final char C_INT 			= 'I';
181
	public static final char C_INT = org.eclipse.jdt.internal.compiler.util.Util.C_INT;
183
182
184
	/**
183
	/**
185
	 * Character constant indicating the semicolon in a signature.
184
	 * Character constant indicating the semicolon in a signature.
186
	 * Value is <code>';'</code>.
185
	 * Value is <code>';'</code>.
187
	 */
186
	 */
188
	public static final char C_SEMICOLON 			= ';';
187
	public static final char C_SEMICOLON = org.eclipse.jdt.internal.compiler.util.Util.C_SEMICOLON;
189
188
190
	/**
189
	/**
191
	 * Character constant indicating the colon in a signature.
190
	 * Character constant indicating the colon in a signature.
192
	 * Value is <code>':'</code>.
191
	 * Value is <code>':'</code>.
193
	 * @since 3.0
192
	 * @since 3.0
194
	 */
193
	 */
195
	public static final char C_COLON 			= ':';
194
	public static final char C_COLON = org.eclipse.jdt.internal.compiler.util.Util.C_COLON;
196
195
197
	/**
196
	/**
198
	 * Character constant indicating the primitive type long in a signature.
197
	 * Character constant indicating the primitive type long in a signature.
199
	 * Value is <code>'J'</code>.
198
	 * Value is <code>'J'</code>.
200
	 */
199
	 */
201
	public static final char C_LONG			= 'J';
200
	public static final char C_LONG = org.eclipse.jdt.internal.compiler.util.Util.C_LONG;
202
201
203
	/**
202
	/**
204
	 * Character constant indicating the primitive type short in a signature.
203
	 * Character constant indicating the primitive type short in a signature.
205
	 * Value is <code>'S'</code>.
204
	 * Value is <code>'S'</code>.
206
	 */
205
	 */
207
	public static final char C_SHORT		= 'S';
206
	public static final char C_SHORT = org.eclipse.jdt.internal.compiler.util.Util.C_SHORT;
208
207
209
	/**
208
	/**
210
	 * Character constant indicating result type void in a signature.
209
	 * Character constant indicating result type void in a signature.
211
	 * Value is <code>'V'</code>.
210
	 * Value is <code>'V'</code>.
212
	 */
211
	 */
213
	public static final char C_VOID			= 'V';
212
	public static final char C_VOID = org.eclipse.jdt.internal.compiler.util.Util.C_VOID;
214
213
215
	/**
214
	/**
216
	 * Character constant indicating the start of a resolved type variable in a
215
	 * Character constant indicating the start of a resolved type variable in a
217
	 * signature. Value is <code>'T'</code>.
216
	 * signature. Value is <code>'T'</code>.
218
	 * @since 3.0
217
	 * @since 3.0
219
	 */
218
	 */
220
	public static final char C_TYPE_VARIABLE	= 'T';
219
	public static final char C_TYPE_VARIABLE = org.eclipse.jdt.internal.compiler.util.Util.C_TYPE_VARIABLE;
221
220
222
	/**
221
	/**
223
	 * Character constant indicating an unbound wildcard type argument
222
	 * Character constant indicating an unbound wildcard type argument
Lines 225-238 Link Here
225
	 * Value is <code>'*'</code>.
224
	 * Value is <code>'*'</code>.
226
	 * @since 3.0
225
	 * @since 3.0
227
	 */
226
	 */
228
	public static final char C_STAR	= '*';
227
	public static final char C_STAR = org.eclipse.jdt.internal.compiler.util.Util.C_STAR;
229
228
230
	/**
229
	/**
231
	 * Character constant indicating an exception in a signature.
230
	 * Character constant indicating an exception in a signature.
232
	 * Value is <code>'^'</code>.
231
	 * Value is <code>'^'</code>.
233
	 * @since 3.1
232
	 * @since 3.1
234
	 */
233
	 */
235
	public static final char C_EXCEPTION_START	= '^';
234
	public static final char C_EXCEPTION_START = org.eclipse.jdt.internal.compiler.util.Util.C_EXCEPTION_START;
236
235
237
	/**
236
	/**
238
	 * Character constant indicating a bound wildcard type argument
237
	 * Character constant indicating a bound wildcard type argument
Lines 240-246 Link Here
240
	 * Value is <code>'+'</code>.
239
	 * Value is <code>'+'</code>.
241
	 * @since 3.1
240
	 * @since 3.1
242
	 */
241
	 */
243
	public static final char C_EXTENDS	= '+';
242
	public static final char C_EXTENDS = org.eclipse.jdt.internal.compiler.util.Util.C_EXTENDS;
244
243
245
	/**
244
	/**
246
	 * Character constant indicating a bound wildcard type argument
245
	 * Character constant indicating a bound wildcard type argument
Lines 248-323 Link Here
248
	 * Value is <code>'-'</code>.
247
	 * Value is <code>'-'</code>.
249
	 * @since 3.1
248
	 * @since 3.1
250
	 */
249
	 */
251
	public static final char C_SUPER	= '-';
250
	public static final char C_SUPER = org.eclipse.jdt.internal.compiler.util.Util.C_SUPER;
252
251
253
	/**
252
	/**
254
	 * Character constant indicating the dot in a signature.
253
	 * Character constant indicating the dot in a signature.
255
	 * Value is <code>'.'</code>.
254
	 * Value is <code>'.'</code>.
256
	 */
255
	 */
257
	public static final char C_DOT			= '.';
256
	public static final char C_DOT = org.eclipse.jdt.internal.compiler.util.Util.C_DOT;
258
257
259
	/**
258
	/**
260
	 * Character constant indicating the dollar in a signature.
259
	 * Character constant indicating the dollar in a signature.
261
	 * Value is <code>'$'</code>.
260
	 * Value is <code>'$'</code>.
262
	 */
261
	 */
263
	public static final char C_DOLLAR			= '$';
262
	public static final char C_DOLLAR = org.eclipse.jdt.internal.compiler.util.Util.C_DOLLAR;
264
263
265
	/**
264
	/**
266
	 * Character constant indicating an array type in a signature.
265
	 * Character constant indicating an array type in a signature.
267
	 * Value is <code>'['</code>.
266
	 * Value is <code>'['</code>.
268
	 */
267
	 */
269
	public static final char C_ARRAY		= '[';
268
	public static final char C_ARRAY = org.eclipse.jdt.internal.compiler.util.Util.C_ARRAY;
270
269
271
	/**
270
	/**
272
	 * Character constant indicating the start of a resolved, named type in a
271
	 * Character constant indicating the start of a resolved, named type in a
273
	 * signature. Value is <code>'L'</code>.
272
	 * signature. Value is <code>'L'</code>.
274
	 */
273
	 */
275
	public static final char C_RESOLVED		= 'L';
274
	public static final char C_RESOLVED = org.eclipse.jdt.internal.compiler.util.Util.C_RESOLVED;
276
275
277
	/**
276
	/**
278
	 * Character constant indicating the start of an unresolved, named type in a
277
	 * Character constant indicating the start of an unresolved, named type in a
279
	 * signature. Value is <code>'Q'</code>.
278
	 * signature. Value is <code>'Q'</code>.
280
	 */
279
	 */
281
	public static final char C_UNRESOLVED	= 'Q';
280
	public static final char C_UNRESOLVED = org.eclipse.jdt.internal.compiler.util.Util.C_UNRESOLVED;
282
281
283
	/**
282
	/**
284
	 * Character constant indicating the end of a named type in a signature.
283
	 * Character constant indicating the end of a named type in a signature.
285
	 * Value is <code>';'</code>.
284
	 * Value is <code>';'</code>.
286
	 */
285
	 */
287
	public static final char C_NAME_END		= ';';
286
	public static final char C_NAME_END = org.eclipse.jdt.internal.compiler.util.Util.C_NAME_END;
288
287
289
	/**
288
	/**
290
	 * Character constant indicating the start of a parameter type list in a
289
	 * Character constant indicating the start of a parameter type list in a
291
	 * signature. Value is <code>'('</code>.
290
	 * signature. Value is <code>'('</code>.
292
	 */
291
	 */
293
	public static final char C_PARAM_START	= '(';
292
	public static final char C_PARAM_START = org.eclipse.jdt.internal.compiler.util.Util.C_PARAM_START;
294
293
295
	/**
294
	/**
296
	 * Character constant indicating the end of a parameter type list in a
295
	 * Character constant indicating the end of a parameter type list in a
297
	 * signature. Value is <code>')'</code>.
296
	 * signature. Value is <code>')'</code>.
298
	 */
297
	 */
299
	public static final char C_PARAM_END	= ')';
298
	public static final char C_PARAM_END = org.eclipse.jdt.internal.compiler.util.Util.C_PARAM_END;
300
299
301
	/**
300
	/**
302
	 * Character constant indicating the start of a formal type parameter
301
	 * Character constant indicating the start of a formal type parameter
303
	 * (or type argument) list in a signature. Value is <code>'&lt;'</code>.
302
	 * (or type argument) list in a signature. Value is <code>'&lt;'</code>.
304
	 * @since 3.0
303
	 * @since 3.0
305
	 */
304
	 */
306
	public static final char C_GENERIC_START	= '<';
305
	public static final char C_GENERIC_START = org.eclipse.jdt.internal.compiler.util.Util.C_GENERIC_START;
307
306
308
	/**
307
	/**
309
	 * Character constant indicating the end of a generic type list in a
308
	 * Character constant indicating the end of a generic type list in a
310
	 * signature. Value is <code>'&gt;'</code>.
309
	 * signature. Value is <code>'&gt;'</code>.
311
	 * @since 3.0
310
	 * @since 3.0
312
	 */
311
	 */
313
	public static final char C_GENERIC_END	= '>';
312
	public static final char C_GENERIC_END = org.eclipse.jdt.internal.compiler.util.Util.C_GENERIC_END;
314
313
315
	/**
314
	/**
316
	 * Character constant indicating a capture of a wildcard type in a
315
	 * Character constant indicating a capture of a wildcard type in a
317
	 * signature. Value is <code>'!'</code>.
316
	 * signature. Value is <code>'!'</code>.
318
	 * @since 3.1
317
	 * @since 3.1
319
	 */
318
	 */
320
	public static final char C_CAPTURE	= '!';
319
	public static final char C_CAPTURE =  org.eclipse.jdt.internal.compiler.util.Util.C_CAPTURE;
321
320
322
	/**
321
	/**
323
	 * String constant for the signature of the primitive type boolean.
322
	 * String constant for the signature of the primitive type boolean.
(-)model/org/eclipse/jdt/internal/core/BinaryType.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 510-516 Link Here
510
			index++;
510
			index++;
511
		}
511
		}
512
		int start = index;
512
		int start = index;
513
		index = Util.scanClassTypeSignature(genericSignature, start) + 1;
513
		index = org.eclipse.jdt.internal.compiler.util.Util.scanClassTypeSignature(genericSignature, start) + 1;
514
		char[] superclassSig = CharOperation.subarray(genericSignature, start, index);
514
		char[] superclassSig = CharOperation.subarray(genericSignature, start, index);
515
		return new String(ClassFile.translatedName(superclassSig));
515
		return new String(ClassFile.translatedName(superclassSig));
516
	} else {
516
	} else {
Lines 596-605 Link Here
596
			index++;
596
			index++;
597
		}
597
		}
598
		// skip superclass
598
		// skip superclass
599
		index = Util.scanClassTypeSignature(genericSignature, index) + 1;
599
		index = org.eclipse.jdt.internal.compiler.util.Util.scanClassTypeSignature(genericSignature, index) + 1;
600
		while (index  < signatureLength) {
600
		while (index  < signatureLength) {
601
			int start = index;
601
			int start = index;
602
			index = Util.scanClassTypeSignature(genericSignature, start) + 1;
602
			index = org.eclipse.jdt.internal.compiler.util.Util.scanClassTypeSignature(genericSignature, start) + 1;
603
			char[] interfaceSig = CharOperation.subarray(genericSignature, start, index);
603
			char[] interfaceSig = CharOperation.subarray(genericSignature, start, index);
604
			interfaces.add(new String(ClassFile.translatedName(interfaceSig)));
604
			interfaces.add(new String(ClassFile.translatedName(interfaceSig)));
605
		}
605
		}
(-)model/org/eclipse/jdt/internal/core/util/Disassembler.java (-14 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 546-556 Link Here
546
				IRuntimeInvisibleParameterAnnotationsAttribute attribute = (IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute;
546
				IRuntimeInvisibleParameterAnnotationsAttribute attribute = (IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute;
547
				invisibleParameterAnnotations = attribute.getParameterAnnotations();
547
				invisibleParameterAnnotations = attribute.getParameterAnnotations();
548
				length = invisibleParameterAnnotations.length;
548
				length = invisibleParameterAnnotations.length;
549
				if (length > 0) {
550
					int parameterNamesLength = parameterNames.length;
551
					if (length < parameterNamesLength) {
552
						System.arraycopy(invisibleParameterAnnotations, 0, (invisibleParameterAnnotations = new IParameterAnnotation[parameterNamesLength]), 1, length);
553
						length = parameterNamesLength;
554
					}
555
				}
549
			}
556
			}
550
			if (runtimeVisibleParameterAnnotationsAttribute != null) {
557
			if (runtimeVisibleParameterAnnotationsAttribute != null) {
551
				IRuntimeVisibleParameterAnnotationsAttribute attribute = (IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute;
558
				IRuntimeVisibleParameterAnnotationsAttribute attribute = (IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute;
552
				visibleParameterAnnotations = attribute.getParameterAnnotations();
559
				visibleParameterAnnotations = attribute.getParameterAnnotations();
553
				length = visibleParameterAnnotations.length;
560
				length = visibleParameterAnnotations.length;
561
				if (length > 0) {
562
					int parameterNamesLength = parameterNames.length;
563
					if (length < parameterNamesLength) {
564
						System.arraycopy(visibleParameterAnnotations, 0, (visibleParameterAnnotations = new IParameterAnnotation[parameterNamesLength]), 1, length);
565
						length = parameterNamesLength;
566
					}
567
				}
554
			}
568
			}
555
			int insertionPosition = CharOperation.indexOf('(', methodHeader) + 1;
569
			int insertionPosition = CharOperation.indexOf('(', methodHeader) + 1;
556
			int start = 0;
570
			int start = 0;
Lines 561-575 Link Here
561
					stringBuffer.append(' ');
575
					stringBuffer.append(' ');
562
				}
576
				}
563
				int stringBufferSize = stringBuffer.length();
577
				int stringBufferSize = stringBuffer.length();
564
				if (runtimeVisibleParameterAnnotationsAttribute != null) {
578
				if (visibleParameterAnnotations != null) {
565
					disassembleAsModifier((IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute, stringBuffer, i, lineSeparator, tabNumber, mode);
579
					disassembleAsModifier(visibleParameterAnnotations, stringBuffer, i, lineSeparator, tabNumber, mode);
566
				}
580
				}
567
				if (runtimeInvisibleParameterAnnotationsAttribute != null) {
581
				if (invisibleParameterAnnotations != null) {
568
					if (stringBuffer.length() != stringBufferSize) {
582
					if (stringBuffer.length() != stringBufferSize) {
569
						stringBuffer.append(' ');
583
						stringBuffer.append(' ');
570
						stringBufferSize = stringBuffer.length();
584
						stringBufferSize = stringBuffer.length();
571
					}
585
					}
572
					disassembleAsModifier((IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute, stringBuffer, i, lineSeparator, tabNumber, mode);
586
					disassembleAsModifier(invisibleParameterAnnotations, stringBuffer, i, lineSeparator, tabNumber, mode);
573
				}
587
				}
574
				if (i == 0 && stringBuffer.length() != stringBufferSize) {
588
				if (i == 0 && stringBuffer.length() != stringBufferSize) {
575
					stringBuffer.append(' ');
589
					stringBuffer.append(' ');
Lines 1862-1882 Link Here
1862
		}
1876
		}
1863
	}
1877
	}
1864
1878
1865
	private void disassembleAsModifier(IRuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) {
1879
	private void disassembleAsModifier(IParameterAnnotation[] parameterAnnotations, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) {
1866
		IParameterAnnotation[] parameterAnnotations = runtimeInvisibleParameterAnnotationsAttribute.getParameterAnnotations();
1867
		if (parameterAnnotations.length > index) {
1868
			disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode);
1869
		}
1870
	}
1871
1872
	private void disassembleAsModifier(IRuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) {
1873
		IParameterAnnotation[] parameterAnnotations = runtimeVisibleParameterAnnotationsAttribute.getParameterAnnotations();
1874
		if (parameterAnnotations.length > index) {
1880
		if (parameterAnnotations.length > index) {
1875
			disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode);
1881
			disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode);
1876
		}
1882
		}
1877
	}
1883
	}
1878
1884
1879
	private void disassembleAsModifier(IParameterAnnotation parameterAnnotation, StringBuffer buffer, String lineSeparator, int tabNumber, int mode) {
1885
	private void disassembleAsModifier(IParameterAnnotation parameterAnnotation, StringBuffer buffer, String lineSeparator, int tabNumber, int mode) {
1886
		if (parameterAnnotation == null) return;
1880
		IAnnotation[] annotations = parameterAnnotation.getAnnotations();
1887
		IAnnotation[] annotations = parameterAnnotation.getAnnotations();
1881
		for (int i = 0, max = annotations.length; i < max; i++) {
1888
		for (int i = 0, max = annotations.length; i < max; i++) {
1882
			if (i > 0) {
1889
			if (i > 0) {
(-)model/org/eclipse/jdt/internal/core/util/Util.java (-382 / +22 lines)
Lines 2172-2177 Link Here
2172
	}
2172
	}
2173
2173
2174
	/**
2174
	/**
2175
	 * Scans the given string for a type signature starting at the given index
2176
	 * and returns the index of the last character.
2177
	 * <pre>
2178
	 * TypeSignature:
2179
	 *  |  BaseTypeSignature
2180
	 *  |  ArrayTypeSignature
2181
	 *  |  ClassTypeSignature
2182
	 *  |  TypeVariableSignature
2183
	 * </pre>
2184
	 *
2185
	 * @param string the signature string
2186
	 * @param start the 0-based character index of the first character
2187
	 * @return the 0-based character index of the last character
2188
	 * @exception IllegalArgumentException if this is not a type signature
2189
	 */
2190
	public static int scanTypeSignature(char[] string, int start) {
2191
		// this method is used in jdt.debug
2192
		return org.eclipse.jdt.internal.compiler.util.Util.scanTypeSignature(string, start);
2193
	}
2194
	/**
2175
	 * Return a new array which is the split of the given string using the given divider. The given end
2195
	 * Return a new array which is the split of the given string using the given divider. The given end
2176
	 * is exclusive and the given start is inclusive.
2196
	 * is exclusive and the given start is inclusive.
2177
	 * <br>
2197
	 * <br>
Lines 2541-2547 Link Here
2541
				appendClassTypeSignature(string, start, buffer, compact);
2561
				appendClassTypeSignature(string, start, buffer, compact);
2542
				break;
2562
				break;
2543
			case Signature.C_TYPE_VARIABLE :
2563
			case Signature.C_TYPE_VARIABLE :
2544
				int e = Util.scanTypeVariableSignature(string, start);
2564
				int e = org.eclipse.jdt.internal.compiler.util.Util.scanTypeVariableSignature(string, start);
2545
				buffer.append(string, start + 1, e - start - 1);
2565
				buffer.append(string, start + 1, e - start - 1);
2546
				break;
2566
				break;
2547
			case Signature.C_BOOLEAN :
2567
			case Signature.C_BOOLEAN :
Lines 2721-3106 Link Here
2721
	}
2741
	}
2722
2742
2723
	/**
2743
	/**
2724
	 * Scans the given string for a type signature starting at the given index
2725
	 * and returns the index of the last character.
2726
	 * <pre>
2727
	 * TypeSignature:
2728
	 *  |  BaseTypeSignature
2729
	 *  |  ArrayTypeSignature
2730
	 *  |  ClassTypeSignature
2731
	 *  |  TypeVariableSignature
2732
	 * </pre>
2733
	 *
2734
	 * @param string the signature string
2735
	 * @param start the 0-based character index of the first character
2736
	 * @return the 0-based character index of the last character
2737
	 * @exception IllegalArgumentException if this is not a type signature
2738
	 */
2739
	public static int scanTypeSignature(char[] string, int start) {
2740
		// need a minimum 1 char
2741
		if (start >= string.length) {
2742
			throw new IllegalArgumentException();
2743
		}
2744
		char c = string[start];
2745
		switch (c) {
2746
			case Signature.C_ARRAY :
2747
				return scanArrayTypeSignature(string, start);
2748
			case Signature.C_RESOLVED :
2749
			case Signature.C_UNRESOLVED :
2750
				return scanClassTypeSignature(string, start);
2751
			case Signature.C_TYPE_VARIABLE :
2752
				return scanTypeVariableSignature(string, start);
2753
			case Signature.C_BOOLEAN :
2754
			case Signature.C_BYTE :
2755
			case Signature.C_CHAR :
2756
			case Signature.C_DOUBLE :
2757
			case Signature.C_FLOAT :
2758
			case Signature.C_INT :
2759
			case Signature.C_LONG :
2760
			case Signature.C_SHORT :
2761
			case Signature.C_VOID :
2762
				return scanBaseTypeSignature(string, start);
2763
			case Signature.C_CAPTURE :
2764
				return scanCaptureTypeSignature(string, start);
2765
			case Signature.C_EXTENDS:
2766
			case Signature.C_SUPER:
2767
			case Signature.C_STAR:
2768
				return scanTypeBoundSignature(string, start);
2769
			default :
2770
				throw new IllegalArgumentException();
2771
		}
2772
	}
2773
2774
	/**
2775
	 * Scans the given string for a base type signature starting at the given index
2776
	 * and returns the index of the last character.
2777
	 * <pre>
2778
	 * BaseTypeSignature:
2779
	 *     <b>B</b> | <b>C</b> | <b>D</b> | <b>F</b> | <b>I</b>
2780
	 *   | <b>J</b> | <b>S</b> | <b>V</b> | <b>Z</b>
2781
	 * </pre>
2782
	 * Note that although the base type "V" is only allowed in method return types,
2783
	 * there is no syntactic ambiguity. This method will accept them anywhere
2784
	 * without complaint.
2785
	 *
2786
	 * @param string the signature string
2787
	 * @param start the 0-based character index of the first character
2788
	 * @return the 0-based character index of the last character
2789
	 * @exception IllegalArgumentException if this is not a base type signature
2790
	 */
2791
	public static int scanBaseTypeSignature(char[] string, int start) {
2792
		// need a minimum 1 char
2793
		if (start >= string.length) {
2794
			throw new IllegalArgumentException();
2795
		}
2796
		char c = string[start];
2797
		if ("BCDFIJSVZ".indexOf(c) >= 0) { //$NON-NLS-1$
2798
			return start;
2799
		} else {
2800
			throw new IllegalArgumentException();
2801
		}
2802
	}
2803
2804
	/**
2805
	 * Scans the given string for an array type signature starting at the given
2806
	 * index and returns the index of the last character.
2807
	 * <pre>
2808
	 * ArrayTypeSignature:
2809
	 *     <b>[</b> TypeSignature
2810
	 * </pre>
2811
	 *
2812
	 * @param string the signature string
2813
	 * @param start the 0-based character index of the first character
2814
	 * @return the 0-based character index of the last character
2815
	 * @exception IllegalArgumentException if this is not an array type signature
2816
	 */
2817
	public static int scanArrayTypeSignature(char[] string, int start) {
2818
		int length = string.length;
2819
		// need a minimum 2 char
2820
		if (start >= length - 1) {
2821
			throw new IllegalArgumentException();
2822
		}
2823
		char c = string[start];
2824
		if (c != Signature.C_ARRAY) {
2825
			throw new IllegalArgumentException();
2826
		}
2827
2828
		c = string[++start];
2829
		while(c == Signature.C_ARRAY) {
2830
			// need a minimum 2 char
2831
			if (start >= length - 1) {
2832
				throw new IllegalArgumentException();
2833
			}
2834
			c = string[++start];
2835
		}
2836
		return scanTypeSignature(string, start);
2837
	}
2838
2839
	/**
2840
	 * Scans the given string for a capture of a wildcard type signature starting at the given
2841
	 * index and returns the index of the last character.
2842
	 * <pre>
2843
	 * CaptureTypeSignature:
2844
	 *     <b>!</b> TypeBoundSignature
2845
	 * </pre>
2846
	 *
2847
	 * @param string the signature string
2848
	 * @param start the 0-based character index of the first character
2849
	 * @return the 0-based character index of the last character
2850
	 * @exception IllegalArgumentException if this is not a capture type signature
2851
	 */
2852
	public static int scanCaptureTypeSignature(char[] string, int start) {
2853
		// need a minimum 2 char
2854
		if (start >= string.length - 1) {
2855
			throw new IllegalArgumentException();
2856
		}
2857
		char c = string[start];
2858
		if (c != Signature.C_CAPTURE) {
2859
			throw new IllegalArgumentException();
2860
		}
2861
		return scanTypeBoundSignature(string, start + 1);
2862
	}
2863
2864
	/**
2865
	 * Scans the given string for a type variable signature starting at the given
2866
	 * index and returns the index of the last character.
2867
	 * <pre>
2868
	 * TypeVariableSignature:
2869
	 *     <b>T</b> Identifier <b>;</b>
2870
	 * </pre>
2871
	 *
2872
	 * @param string the signature string
2873
	 * @param start the 0-based character index of the first character
2874
	 * @return the 0-based character index of the last character
2875
	 * @exception IllegalArgumentException if this is not a type variable signature
2876
	 */
2877
	public static int scanTypeVariableSignature(char[] string, int start) {
2878
		// need a minimum 3 chars "Tx;"
2879
		if (start >= string.length - 2) {
2880
			throw new IllegalArgumentException();
2881
		}
2882
		// must start in "T"
2883
		char c = string[start];
2884
		if (c != Signature.C_TYPE_VARIABLE) {
2885
			throw new IllegalArgumentException();
2886
		}
2887
		int id = scanIdentifier(string, start + 1);
2888
		c = string[id + 1];
2889
		if (c == Signature.C_SEMICOLON) {
2890
			return id + 1;
2891
		} else {
2892
			throw new IllegalArgumentException();
2893
		}
2894
	}
2895
2896
	/**
2897
	 * Scans the given string for an identifier starting at the given
2898
	 * index and returns the index of the last character.
2899
	 * Stop characters are: ";", ":", "&lt;", "&gt;", "/", ".".
2900
	 *
2901
	 * @param string the signature string
2902
	 * @param start the 0-based character index of the first character
2903
	 * @return the 0-based character index of the last character
2904
	 * @exception IllegalArgumentException if this is not an identifier
2905
	 */
2906
	public static int scanIdentifier(char[] string, int start) {
2907
		// need a minimum 1 char
2908
		if (start >= string.length) {
2909
			throw new IllegalArgumentException();
2910
		}
2911
		int p = start;
2912
		while (true) {
2913
			char c = string[p];
2914
			if (c == '<' || c == '>' || c == ':' || c == ';' || c == '.' || c == '/') {
2915
				return p - 1;
2916
			}
2917
			p++;
2918
			if (p == string.length) {
2919
				return p - 1;
2920
			}
2921
		}
2922
	}
2923
2924
	/**
2925
	 * Scans the given string for a class type signature starting at the given
2926
	 * index and returns the index of the last character.
2927
	 * <pre>
2928
	 * ClassTypeSignature:
2929
	 *     { <b>L</b> | <b>Q</b> } Identifier
2930
	 *           { { <b>/</b> | <b>.</b> Identifier [ <b>&lt;</b> TypeArgumentSignature* <b>&gt;</b> ] }
2931
	 *           <b>;</b>
2932
	 * </pre>
2933
	 * Note that although all "/"-identifiers most come before "."-identifiers,
2934
	 * there is no syntactic ambiguity. This method will accept them without
2935
	 * complaint.
2936
	 *
2937
	 * @param string the signature string
2938
	 * @param start the 0-based character index of the first character
2939
	 * @return the 0-based character index of the last character
2940
	 * @exception IllegalArgumentException if this is not a class type signature
2941
	 */
2942
	public static int scanClassTypeSignature(char[] string, int start) {
2943
		// need a minimum 3 chars "Lx;"
2944
		if (start >= string.length - 2) {
2945
			throw new IllegalArgumentException();
2946
		}
2947
		// must start in "L" or "Q"
2948
		char c = string[start];
2949
		if (c != Signature.C_RESOLVED && c != Signature.C_UNRESOLVED) {
2950
			return -1;
2951
		}
2952
		int p = start + 1;
2953
		while (true) {
2954
			if (p >= string.length) {
2955
				throw new IllegalArgumentException();
2956
			}
2957
			c = string[p];
2958
			if (c == Signature.C_SEMICOLON) {
2959
				// all done
2960
				return p;
2961
			} else if (c == Signature.C_GENERIC_START) {
2962
				int e = scanTypeArgumentSignatures(string, p);
2963
				p = e;
2964
			} else if (c == Signature.C_DOT || c == '/') {
2965
				int id = scanIdentifier(string, p + 1);
2966
				p = id;
2967
			}
2968
			p++;
2969
		}
2970
	}
2971
2972
	/**
2973
	 * Scans the given string for a type bound signature starting at the given
2974
	 * index and returns the index of the last character.
2975
	 * <pre>
2976
	 * TypeBoundSignature:
2977
	 *     <b>[-+]</b> TypeSignature <b>;</b>
2978
	 *     <b>*</b></b>
2979
	 * </pre>
2980
	 *
2981
	 * @param string the signature string
2982
	 * @param start the 0-based character index of the first character
2983
	 * @return the 0-based character index of the last character
2984
	 * @exception IllegalArgumentException if this is not a type variable signature
2985
	 */
2986
	public static int scanTypeBoundSignature(char[] string, int start) {
2987
		// need a minimum 1 char for wildcard
2988
		if (start >= string.length) {
2989
			throw new IllegalArgumentException();
2990
		}
2991
		char c = string[start];
2992
		switch (c) {
2993
			case Signature.C_STAR :
2994
				return start;
2995
			case Signature.C_SUPER :
2996
			case Signature.C_EXTENDS :
2997
				// need a minimum 3 chars "+[I"
2998
				if (start >= string.length - 2) {
2999
					throw new IllegalArgumentException();
3000
				}
3001
				break;
3002
			default :
3003
				// must start in "+/-"
3004
					throw new IllegalArgumentException();
3005
3006
		}
3007
		c = string[++start];
3008
		switch (c) {
3009
			case Signature.C_CAPTURE :
3010
				return scanCaptureTypeSignature(string, start);
3011
			case Signature.C_SUPER :
3012
			case Signature.C_EXTENDS :
3013
				return scanTypeBoundSignature(string, start);
3014
			case Signature.C_RESOLVED :
3015
			case Signature.C_UNRESOLVED :
3016
				return scanClassTypeSignature(string, start);
3017
			case Signature.C_TYPE_VARIABLE :
3018
				return scanTypeVariableSignature(string, start);
3019
			case Signature.C_ARRAY :
3020
				return scanArrayTypeSignature(string, start);
3021
			case Signature.C_STAR:
3022
				return start;
3023
			default:
3024
				throw new IllegalArgumentException();
3025
		}
3026
	}
3027
3028
	/**
3029
	 * Scans the given string for a list of type argument signatures starting at
3030
	 * the given index and returns the index of the last character.
3031
	 * <pre>
3032
	 * TypeArgumentSignatures:
3033
	 *     <b>&lt;</b> TypeArgumentSignature* <b>&gt;</b>
3034
	 * </pre>
3035
	 * Note that although there is supposed to be at least one type argument, there
3036
	 * is no syntactic ambiguity if there are none. This method will accept zero
3037
	 * type argument signatures without complaint.
3038
	 *
3039
	 * @param string the signature string
3040
	 * @param start the 0-based character index of the first character
3041
	 * @return the 0-based character index of the last character
3042
	 * @exception IllegalArgumentException if this is not a list of type arguments
3043
	 * signatures
3044
	 */
3045
	public static int scanTypeArgumentSignatures(char[] string, int start) {
3046
		// need a minimum 2 char "<>"
3047
		if (start >= string.length - 1) {
3048
			throw new IllegalArgumentException();
3049
		}
3050
		char c = string[start];
3051
		if (c != Signature.C_GENERIC_START) {
3052
			throw new IllegalArgumentException();
3053
		}
3054
		int p = start + 1;
3055
		while (true) {
3056
			if (p >= string.length) {
3057
				throw new IllegalArgumentException();
3058
			}
3059
			c = string[p];
3060
			if (c == Signature.C_GENERIC_END) {
3061
				return p;
3062
			}
3063
			int e = scanTypeArgumentSignature(string, p);
3064
			p = e + 1;
3065
		}
3066
	}
3067
3068
	/**
3069
	 * Scans the given string for a type argument signature starting at the given
3070
	 * index and returns the index of the last character.
3071
	 * <pre>
3072
	 * TypeArgumentSignature:
3073
	 *     <b>&#42;</b>
3074
	 *  |  <b>+</b> TypeSignature
3075
	 *  |  <b>-</b> TypeSignature
3076
	 *  |  TypeSignature
3077
	 * </pre>
3078
	 * Note that although base types are not allowed in type arguments, there is
3079
	 * no syntactic ambiguity. This method will accept them without complaint.
3080
	 *
3081
	 * @param string the signature string
3082
	 * @param start the 0-based character index of the first character
3083
	 * @return the 0-based character index of the last character
3084
	 * @exception IllegalArgumentException if this is not a type argument signature
3085
	 */
3086
	public static int scanTypeArgumentSignature(char[] string, int start) {
3087
		// need a minimum 1 char
3088
		if (start >= string.length) {
3089
			throw new IllegalArgumentException();
3090
		}
3091
		char c = string[start];
3092
		switch (c) {
3093
			case Signature.C_STAR :
3094
				return start;
3095
			case Signature.C_EXTENDS :
3096
			case Signature.C_SUPER :
3097
				return scanTypeBoundSignature(string, start);
3098
			default :
3099
				return scanTypeSignature(string, start);
3100
		}
3101
	}
3102
3103
	/**
3104
	 * Get all type arguments from an array of signatures.
2744
	 * Get all type arguments from an array of signatures.
3105
	 *
2745
	 *
3106
	 * Example:
2746
	 * Example:
Lines 3400-3406 Link Here
3400
				case Signature.C_RESOLVED :
3040
				case Signature.C_RESOLVED :
3401
					return appendClassTypeSignatureForAnchor(string, start, buffer);
3041
					return appendClassTypeSignatureForAnchor(string, start, buffer);
3402
				case Signature.C_TYPE_VARIABLE :
3042
				case Signature.C_TYPE_VARIABLE :
3403
					int e = Util.scanTypeVariableSignature(string, start);
3043
					int e = org.eclipse.jdt.internal.compiler.util.Util.scanTypeVariableSignature(string, start);
3404
					buffer.append(string, start + 1, e - start - 1);
3044
					buffer.append(string, start + 1, e - start - 1);
3405
					return e;
3045
					return e;
3406
				case Signature.C_BOOLEAN :
3046
				case Signature.C_BOOLEAN :
(-)search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 798-804 Link Here
798
		if (descriptor[0] != '(') return descriptor;
798
		if (descriptor[0] != '(') return descriptor;
799
		if (descriptor[1] != ')') {
799
		if (descriptor[1] != ')') {
800
			// remove the first synthetic parameter
800
			// remove the first synthetic parameter
801
			int start = Util.scanTypeSignature(descriptor, 1) + 1;
801
			int start = org.eclipse.jdt.internal.compiler.util.Util.scanTypeSignature(descriptor, 1) + 1;
802
			int length = descriptor.length - start;
802
			int length = descriptor.length - start;
803
			char[] signature = new char[length + 1];
803
			char[] signature = new char[length + 1];
804
			signature[0] = descriptor[0];
804
			signature[0] = descriptor[0];
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-1 / +1 lines)
Lines 789-795 Link Here
789
		assertEquals("Unexpected annotations", expected, actual);
789
		assertEquals("Unexpected annotations", expected, actual);
790
	}
790
	}
791
791
792
	private void appendAnnotation(StringBuffer buffer, IAnnotation annotation) throws JavaModelException {
792
	protected void appendAnnotation(StringBuffer buffer, IAnnotation annotation) throws JavaModelException {
793
		buffer.append('@');
793
		buffer.append('@');
794
		buffer.append(annotation.getElementName());
794
		buffer.append(annotation.getElementName());
795
		IMemberValuePair[] members = annotation.getMemberValuePairs();
795
		IMemberValuePair[] members = annotation.getMemberValuePairs();
(-)src/org/eclipse/jdt/core/tests/model/ClassFileTests.java (-2 / +46 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 207-213 Link Here
207
		"import java.lang.annotation.Retention;\n" +
207
		"import java.lang.annotation.Retention;\n" +
208
		"import java.lang.annotation.RetentionPolicy;\n" + 
208
		"import java.lang.annotation.RetentionPolicy;\n" + 
209
		"@Retention(value = RetentionPolicy.CLASS)\n" + 
209
		"@Retention(value = RetentionPolicy.CLASS)\n" + 
210
		"public @interface MyAnnotation3 {}"
210
		"public @interface MyAnnotation3 {}",
211
		"test342757/X.java",
212
		"package test342757;\n" +
213
		"public class X {\n" + 
214
		"	class B {\n" + 
215
		"		public B(@Deprecated @Annot String s) {}\n" + 
216
		"		public void foo(@Deprecated @Annot int j) {}\n" + 
217
		"	}\n" + 
218
		"}",
219
		"test342757/Annot.java",
220
		"package test342757;\n" +
221
		"import java.lang.annotation.Retention;\n" + 
222
		"import static java.lang.annotation.RetentionPolicy.*;\n" + 
223
		"@Retention(CLASS)\n" + 
224
		"@interface Annot {}",
211
	};
225
	};
212
	addLibrary(javaProject, "lib.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5);
226
	addLibrary(javaProject, "lib.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5);
213
	this.jarRoot = javaProject.getPackageFragmentRoot(getFile("/P/lib.jar"));
227
	this.jarRoot = javaProject.getPackageFragmentRoot(getFile("/P/lib.jar"));
Lines 516-521 Link Here
516
}
530
}
517
531
518
/*
532
/*
533
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=342757
534
 */
535
public void testAnnotations26() throws JavaModelException {
536
	IType type = this.jarRoot.getPackageFragment("test342757").getClassFile("X$B.class").getType();
537
	IMethod[] methods = type.getMethods();
538
	String expected =
539
			"@test342757.Annot\n" + 
540
			"@java.lang.Deprecated\n" + 
541
			"@test342757.Annot\n" + 
542
			"@java.lang.Deprecated\n";
543
	StringBuffer buffer = new StringBuffer();
544
	for (int i = 0, max = methods.length; i < max; i++) {
545
		ILocalVariable[] parameters = methods[i].getParameters();
546
		for (int j = 0, max2 = parameters.length; j < max2; j++) {
547
			IAnnotation[] annotations = parameters[j].getAnnotations();
548
			for (int n = 0; n < annotations.length; n++) {
549
				IAnnotation annotation = annotations[n];
550
				appendAnnotation(buffer, annotation);
551
				buffer.append("\n");
552
			}
553
		}
554
	}
555
	String actual = buffer.toString();
556
	if (!expected.equals(actual)) {
557
		System.out.println(displayString(actual, 2) + this.endChar);
558
	}
559
	assertEquals("Unexpected annotations", expected, actual);
560
}
561
562
/*
519
 * Ensures that no exception is thrown for a .class file name with a dot
563
 * Ensures that no exception is thrown for a .class file name with a dot
520
 * (regression test for bug 114140 assertion failed when opening a class file not not the classpath)
564
 * (regression test for bug 114140 assertion failed when opening a class file not not the classpath)
521
 */
565
 */

Return to bug 342757