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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java (-1 / +78 lines)
Lines 12-23 Link Here
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.internal.compiler.codegen.AttributeNamesConstants;
14
import org.eclipse.jdt.internal.compiler.codegen.AttributeNamesConstants;
15
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
15
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
17
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
17
import org.eclipse.jdt.internal.compiler.util.Util;
18
import org.eclipse.jdt.internal.compiler.util.Util;
18
19
19
public class MethodInfo extends ClassFileStruct implements IBinaryMethod, Comparable {
20
public class MethodInfo extends ClassFileStruct implements IBinaryMethod, Comparable {
20
	static private final char[][] noException = CharOperation.NO_CHAR_CHAR;
21
	static private final char[][] noException = CharOperation.NO_CHAR_CHAR;
22
	static private final char[][] noArgumentNames = CharOperation.NO_CHAR_CHAR;
21
	protected int accessFlags;
23
	protected int accessFlags;
22
	protected int attributeBytes;
24
	protected int attributeBytes;
23
	protected char[] descriptor;
25
	protected char[] descriptor;
Lines 26-31 Link Here
26
	protected char[] signature;
28
	protected char[] signature;
27
	protected int signatureUtf8Offset;
29
	protected int signatureUtf8Offset;
28
	protected long tagBits;
30
	protected long tagBits;
31
	protected char[][] argumentNames;
32
	protected int argumentNamesIndex;
29
33
30
public static MethodInfo createMethod(byte classFileBytes[], int offsets[], int offset) {
34
public static MethodInfo createMethod(byte classFileBytes[], int offsets[], int offset) {
31
	MethodInfo methodInfo = new MethodInfo(classFileBytes, offsets, offset);
35
	MethodInfo methodInfo = new MethodInfo(classFileBytes, offsets, offset);
Lines 193-199 Link Here
193
 * @see org.eclipse.jdt.internal.compiler.env.IGenericMethod#getArgumentNames()
197
 * @see org.eclipse.jdt.internal.compiler.env.IGenericMethod#getArgumentNames()
194
 */
198
 */
195
public char[][] getArgumentNames() {
199
public char[][] getArgumentNames() {
196
	return null;
200
	if (this.argumentNames == null) {
201
		readCodeAttribute();
202
	}
203
	return this.argumentNames;
197
}
204
}
198
public Object getDefaultValue() {
205
public Object getDefaultValue() {
199
	return null;
206
	return null;
Lines 283-288 Link Here
283
	getMethodDescriptor();
290
	getMethodDescriptor();
284
	getExceptionTypeNames();
291
	getExceptionTypeNames();
285
	getGenericSignature();
292
	getGenericSignature();
293
	getArgumentNames();
286
	reset();
294
	reset();
287
}
295
}
288
/**
296
/**
Lines 404-407 Link Here
404
	.append(desc)
412
	.append(desc)
405
	.append('}');
413
	.append('}');
406
}
414
}
415
private void readCodeAttribute() {
416
	int attributesCount = u2At(6);
417
	int readOffset = 8;
418
	if (attributesCount != 0) {
419
		for (int i = 0; i < attributesCount; i++) {
420
			int utf8Offset = constantPoolOffsets[u2At(readOffset)] - structOffset;
421
			char[] attributeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
422
			if (CharOperation.equals(attributeName, AttributeNamesConstants.CodeName)) {
423
				decodeCodeAttribute(readOffset);
424
				if (this.argumentNames == null) {
425
					this.argumentNames = noArgumentNames;
426
				}
427
				return;
428
			} else {
429
				readOffset += (6 + u4At(readOffset + 2));
430
			}
431
		}
432
	}
433
	this.argumentNames = noArgumentNames;
434
}
435
private void decodeCodeAttribute(int offset) {
436
	int readOffset = offset + 10;
437
	int codeLength = (int) u4At(readOffset);
438
	readOffset += (4 + codeLength);
439
	int exceptionTableLength = u2At(readOffset);
440
	readOffset += 2;
441
	if (exceptionTableLength != 0) {
442
		for (int i = 0; i < exceptionTableLength; i++) {
443
			readOffset += 8;
444
		}
445
	}
446
	int attributesCount = u2At(readOffset);
447
	readOffset += 2;
448
	for (int i = 0; i < attributesCount; i++) {
449
		int utf8Offset = constantPoolOffsets[u2At(readOffset)] - structOffset;
450
		char[] attributeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
451
		if (CharOperation.equals(attributeName, AttributeNamesConstants.LocalVariableTableName)) {
452
			decodeLocalVariableAttribute(readOffset, codeLength);
453
		}
454
		readOffset += (6 + u4At(readOffset + 2));
455
	}
456
}
457
private void decodeLocalVariableAttribute(int offset, int codeLength) {
458
	int readOffset = offset + 6;
459
	final int length = u2At(readOffset);
460
	if (length != 0) {
461
		readOffset += 2;
462
		this.argumentNames = new char[length][];
463
		this.argumentNamesIndex = 0;
464
		for (int i = 0; i < length; i++) {
465
			int startPC = u2At(readOffset);
466
			if (startPC == 0) {
467
				int nameIndex = u2At(4 + readOffset);
468
				int utf8Offset = constantPoolOffsets[nameIndex] - structOffset;
469
				char[] localVariableName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
470
				if (!CharOperation.equals(localVariableName, ConstantPool.This)) {
471
					this.argumentNames[this.argumentNamesIndex++] = localVariableName;
472
				}
473
			} else {
474
				break;
475
			}
476
			readOffset += 10;
477
		}
478
		if (this.argumentNamesIndex != this.argumentNames.length) {
479
			// resize
480
			System.arraycopy(this.argumentNames, 0, (this.argumentNames = new char[this.argumentNamesIndex][]), 0, this.argumentNamesIndex);
481
		}
482
	}
483
}
407
}
484
}
(-)model/org/eclipse/jdt/internal/core/BinaryMethod.java (-49 / +66 lines)
Lines 173-222 Link Here
173
		if ((modifiers & ClassFileConstants.AccSynthetic) != 0) {
173
		if ((modifiers & ClassFileConstants.AccSynthetic) != 0) {
174
			return this.parameterNames = getRawParameterNames(paramCount);
174
			return this.parameterNames = getRawParameterNames(paramCount);
175
		}
175
		}
176
 		String javadocContents = null;
176
		String javadocContents = null;
177
 		IType declaringType = this.getDeclaringType();
177
		IType declaringType = this.getDeclaringType();
178
		PerProjectInfo projectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(this.getJavaProject().getProject());
178
		PerProjectInfo projectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(this.getJavaProject().getProject());
179
 		synchronized (projectInfo.javadocCache) {
179
		synchronized (projectInfo.javadocCache) {
180
 			javadocContents = (String) projectInfo.javadocCache.get(declaringType);
180
			javadocContents = (String) projectInfo.javadocCache.get(declaringType);
181
 			if (javadocContents == null) {
181
			if (javadocContents == null) {
182
 				projectInfo.javadocCache.put(declaringType, BinaryType.EMPTY_JAVADOC);
182
				projectInfo.javadocCache.put(declaringType, BinaryType.EMPTY_JAVADOC);
183
 			}
183
			}
184
 		}
184
		}
185
 		if (javadocContents == null) {
185
		if (javadocContents == null) {
186
 			long timeOut = 50; // default value
186
			long timeOut = 50; // default value
187
 			try {
187
			try {
188
 				String option = this.getJavaProject().getOption(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, true);
188
				String option = this.getJavaProject().getOption(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, true);
189
 				if (option != null) {
189
				if (option != null) {
190
 					timeOut = Long.parseLong(option);
190
					timeOut = Long.parseLong(option);
191
 				}
191
				}
192
 			} catch(NumberFormatException e) {
192
			} catch(NumberFormatException e) {
193
 				// ignore
193
				// ignore
194
 			}
194
			}
195
 			if (timeOut == 0) {
195
			if (timeOut == 0) {
196
 				// don't try to fetch the values
196
				// don't try to fetch the values
197
 				return this.parameterNames = getRawParameterNames(paramCount);
197
				return this.parameterNames = getRawParameterNames(paramCount);
198
 			}
198
			}
199
 			final class ParametersNameCollector {
199
			final class ParametersNameCollector {
200
 				String javadoc;
200
				String javadoc;
201
 				public void setJavadoc(String s) {
201
				public void setJavadoc(String s) {
202
 					this.javadoc = s;
202
					this.javadoc = s;
203
 				}
203
				}
204
 				public String getJavadoc() {
204
				public String getJavadoc() {
205
 					return this.javadoc;
205
					return this.javadoc;
206
 				}
206
				}
207
 	 		}
207
			}
208
 			/*
208
			/*
209
 			 * The declaring type is not in the cache yet. The thread wil retrieve the javadoc contents
209
			 * The declaring type is not in the cache yet. The thread wil retrieve the javadoc contents
210
 			 */
210
			 */
211
	 		final ParametersNameCollector nameCollector = new ParametersNameCollector();
211
			final ParametersNameCollector nameCollector = new ParametersNameCollector();
212
			Thread collect = new Thread() {
212
			Thread collect = new Thread() {
213
				public void run() {
213
				public void run() {
214
					try {
214
					try {
215
						// this call has a side-effect on the per project info cache
215
						// this call has a side-effect on the per project info cache
216
						nameCollector.setJavadoc(BinaryMethod.this.getAttachedJavadoc(null));
216
						nameCollector.setJavadoc(BinaryMethod.this.getAttachedJavadoc(null));
217
			        } catch (JavaModelException e) {
217
					} catch (JavaModelException e) {
218
	 		        	// ignore
218
						// ignore
219
	 		        }
219
					}
220
					synchronized(nameCollector) {
220
					synchronized(nameCollector) {
221
						nameCollector.notify();
221
						nameCollector.notify();
222
					}
222
					}
Lines 231-247 Link Here
231
				}
231
				}
232
			}
232
			}
233
			javadocContents = nameCollector.getJavadoc();
233
			javadocContents = nameCollector.getJavadoc();
234
 		} else if (javadocContents != BinaryType.EMPTY_JAVADOC){
234
		} else if (javadocContents != BinaryType.EMPTY_JAVADOC){
235
 			// need to extract the part relative to the binary method since javadoc contains the javadoc for the declaring type
235
			// need to extract the part relative to the binary method since javadoc contains the javadoc for the declaring type
236
 			try {
236
			try {
237
 				javadocContents = extractJavadoc(declaringType, javadocContents);
237
				javadocContents = extractJavadoc(declaringType, javadocContents);
238
 			} catch(JavaModelException e) {
238
			} catch(JavaModelException e) {
239
 				// ignore
239
				// ignore
240
 			}
240
			}
241
 		} else {
241
		} else {
242
 			// we don't want to set the parameter names
242
			// let's see if we can retrieve them from the debug infos
243
 			return getRawParameterNames(paramCount);
243
			char[][] argumentNames = info.getArgumentNames();
244
 		}
244
			if (argumentNames != null && argumentNames.length == paramCount) {
245
				String[] names = new String[paramCount];
246
				for (int i = 0; i < paramCount; i++) {
247
					names[i] = new String(argumentNames[i]);
248
				}
249
				return this.parameterNames = names;
250
			}
251
			return getRawParameterNames(paramCount);
252
		}
245
		if (javadocContents != null && javadocContents != BinaryType.EMPTY_JAVADOC) {
253
		if (javadocContents != null && javadocContents != BinaryType.EMPTY_JAVADOC) {
246
			final int indexOfOpenParen = javadocContents.indexOf('(');
254
			final int indexOfOpenParen = javadocContents.indexOf('(');
247
			if (indexOfOpenParen != -1) {
255
			if (indexOfOpenParen != -1) {
Lines 268-273 Link Here
268
				}
276
				}
269
			}
277
			}
270
		}
278
		}
279
		// let's see if we can retrieve them from the debug infos
280
		char[][] argumentNames = info.getArgumentNames();
281
		if (argumentNames != null && argumentNames.length == paramCount) {
282
			String[] names = new String[paramCount];
283
			for (int i = 0; i < paramCount; i++) {
284
				names[i] = new String(argumentNames[i]);
285
			}
286
			return this.parameterNames = names;
287
		}
271
	}
288
	}
272
	// if still no parameter names, produce fake ones
289
	// if still no parameter names, produce fake ones
273
	return this.parameterNames = getRawParameterNames(paramCount);
290
	return this.parameterNames = getRawParameterNames(paramCount);

Return to bug 102473