Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 90344 | Differences between
and this patch

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java (-2 / +9 lines)
Lines 889-895 Link Here
889
						throw new SelectionNodeFound(constructorDeclaration.binding);
889
						throw new SelectionNodeFound(constructorDeclaration.binding);
890
					} else {
890
					} else {
891
						if (constructorDeclaration.scope != null) {
891
						if (constructorDeclaration.scope != null) {
892
							throw new SelectionNodeFound(new MethodBinding(constructorDeclaration.modifiers, constructorDeclaration.selector, null, null, null, constructorDeclaration.scope.referenceType().binding));
892
							throw new SelectionNodeFound(new SourceMethodBinding(constructorDeclaration.modifiers, constructorDeclaration.selector, null, null, null, constructorDeclaration.scope.referenceType().binding));
893
						}
893
						}
894
					}
894
					}
895
				}
895
				}
Lines 919-925 Link Here
919
						throw new SelectionNodeFound(methodDeclaration.binding);
919
						throw new SelectionNodeFound(methodDeclaration.binding);
920
					} else {
920
					} else {
921
						if (methodDeclaration.scope != null) {
921
						if (methodDeclaration.scope != null) {
922
							throw new SelectionNodeFound(new MethodBinding(methodDeclaration.modifiers, methodDeclaration.selector, null, null, null, methodDeclaration.scope.referenceType().binding));
922
							MethodBinding binding;							
923
							binding = new SourceMethodBinding(methodDeclaration.modifiers, 
924
															  methodDeclaration.selector, 
925
															  null, 
926
															  null, 
927
															  null, 
928
															  methodDeclaration.scope.referenceType().binding);
929
							throw new SelectionNodeFound(binding);
923
						}
930
						}
924
					}
931
					}
925
				}
932
				}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java (+1 lines)
Lines 428-433 Link Here
428
		for (int i = 0; i < length; i++) {
428
		for (int i = 0; i < length; i++) {
429
			Annotation annotation = annotations[i];
429
			Annotation annotation = annotations[i];
430
			annotation.recipient = recipient;
430
			annotation.recipient = recipient;
431
			annotation.compilerAnnotation = new SourceAnnotation(annotation);
431
			annotationTypes[i] = annotation.resolveType(scope);
432
			annotationTypes[i] = annotation.resolveType(scope);
432
		}
433
		}
433
		// check duplicate annotations
434
		// check duplicate annotations
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java (-4 / +7 lines)
Lines 21-29 Link Here
21
	
21
	
22
	final static MemberValuePair[] NoValuePairs = new MemberValuePair[0];
22
	final static MemberValuePair[] NoValuePairs = new MemberValuePair[0];
23
	public int declarationSourceEnd;
23
	public int declarationSourceEnd;
24
	public Binding recipient;
24
	public Binding recipient;	
25
	
26
	public TypeReference type;
25
	public TypeReference type;
26
	/** 
27
	 *  The representation of this annotation in the type system. 
28
	 */
29
	public SourceAnnotation compilerAnnotation;
27
	
30
	
28
	public static long getRetentionPolicy(char[] policyName) {
31
	public static long getRetentionPolicy(char[] policyName) {
29
		if (policyName == null || policyName.length == 0)
32
		if (policyName == null || policyName.length == 0)
Lines 297-304 Link Here
297
			}
300
			}
298
		}
301
		}
299
		return this.resolvedType;
302
		return this.resolvedType;
300
	}
303
	}	
301
	
304
		
302
	public abstract void traverse(ASTVisitor visitor, BlockScope scope);
305
	public abstract void traverse(ASTVisitor visitor, BlockScope scope);
303
	public abstract void traverse(ASTVisitor visitor, CompilationUnitScope scope);
306
	public abstract void traverse(ASTVisitor visitor, CompilationUnitScope scope);
304
}
307
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java (-1 / +2 lines)
Lines 23-28 Link Here
23
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
23
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
24
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
24
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.SourceMethodBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
28
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
28
29
Lines 182-188 Link Here
182
				// declaringClass.iterator();
183
				// declaringClass.iterator();
183
				final TypeBinding collectionTypeBinding = collection.resolvedType.erasure();
184
				final TypeBinding collectionTypeBinding = collection.resolvedType.erasure();
184
				MethodBinding iteratorMethodBinding =
185
				MethodBinding iteratorMethodBinding =
185
					new MethodBinding(
186
					new SourceMethodBinding(
186
							AccPublic,
187
							AccPublic,
187
							"iterator".toCharArray(),//$NON-NLS-1$
188
							"iterator".toCharArray(),//$NON-NLS-1$
188
							scope.getJavaUtilIterator(),
189
							scope.getJavaUtilIterator(),
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java (-2 / +2 lines)
Lines 156-162 Link Here
156
		}
156
		}
157
157
158
		//============BINDING UPDATE==========================
158
		//============BINDING UPDATE==========================
159
		methodDeclaration.binding = new MethodBinding(
159
		methodDeclaration.binding = new SourceMethodBinding(
160
				methodDeclaration.modifiers, //methodDeclaration
160
				methodDeclaration.modifiers, //methodDeclaration
161
				methodBinding.selector,
161
				methodBinding.selector,
162
				methodBinding.returnType,
162
				methodBinding.returnType,
Lines 416-422 Link Here
416
		}
416
		}
417
417
418
		//============BINDING UPDATE==========================
418
		//============BINDING UPDATE==========================
419
		cd.binding = new MethodBinding(
419
		cd.binding = new SourceMethodBinding(
420
				cd.modifiers, //methodDeclaration
420
				cd.modifiers, //methodDeclaration
421
				argumentsLength == 0 ? NoParameters : argumentTypes, //arguments bindings
421
				argumentsLength == 0 ? NoParameters : argumentTypes, //arguments bindings
422
				inheritedConstructorBinding.thrownExceptions, //exceptions
422
				inheritedConstructorBinding.thrownExceptions, //exceptions
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java (-189 / +108 lines)
Lines 15-23 Link Here
15
import java.util.Arrays;
15
import java.util.Arrays;
16
16
17
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.internal.compiler.ast.Annotation;
19
import org.eclipse.jdt.internal.compiler.codegen.AttributeNamesConstants;
18
import org.eclipse.jdt.internal.compiler.codegen.AttributeNamesConstants;
20
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
21
import org.eclipse.jdt.internal.compiler.env.*;
19
import org.eclipse.jdt.internal.compiler.env.*;
22
import org.eclipse.jdt.internal.compiler.impl.Constant;
20
import org.eclipse.jdt.internal.compiler.impl.Constant;
23
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
21
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
Lines 70-75 Link Here
70
	private int constantPoolCount;
68
	private int constantPoolCount;
71
	private int[] constantPoolOffsets;
69
	private int[] constantPoolOffsets;
72
	private FieldInfo[] fields;
70
	private FieldInfo[] fields;
71
	private AnnotationInfo[] annotations;
73
	private int fieldsCount;
72
	private int fieldsCount;
74
	// initialized in case the .class file is a nested type
73
	// initialized in case the .class file is a nested type
75
	private InnerClassInfo innerInfo;
74
	private InnerClassInfo innerInfo;
Lines 216-223 Link Here
216
		if (this.methodsCount != 0) {
215
		if (this.methodsCount != 0) {
217
			this.methods = new MethodInfo[this.methodsCount];
216
			this.methods = new MethodInfo[this.methodsCount];
218
			MethodInfo method;
217
			MethodInfo method;
218
			final boolean isAnnotationType = (this.accessFlags & AccAnnotation) != 0;
219
			for (int i = 0; i < this.methodsCount; i++) {
219
			for (int i = 0; i < this.methodsCount; i++) {
220
				method = new MethodInfo(reference, this.constantPoolOffsets, readOffset);
220
				if( isAnnotationType )
221
					method = new AnnotationMethodInfo(reference, this.constantPoolOffsets, readOffset);
222
				else
223
					method = new MethodInfo(reference, this.constantPoolOffsets, readOffset);
221
				this.methods[i] = method;
224
				this.methods[i] = method;
222
				readOffset += method.sizeInBytes();
225
				readOffset += method.sizeInBytes();
223
			}
226
			}
Lines 281-289 Link Here
281
						}
284
						}
282
					}
285
					}
283
					break;
286
					break;
284
				case 'R' :
287
				case 'R' :		
285
					if (CharOperation.equals(attributeName, RuntimeVisibleAnnotationsName)) {
288
					if (CharOperation.equals(attributeName, RuntimeVisibleAnnotationsName)) {
286
						decodeStandardAnnotations(readOffset);
289
						decodeAnnotations(readOffset, true);
290
					}
291
					else if(CharOperation.equals(attributeName, RuntimeInvisibleAnnotationsName )){
292
						decodeAnnotations(readOffset, false);
287
					}
293
					}
288
					break;
294
					break;
289
			}
295
			}
Lines 294-303 Link Here
294
		}
300
		}
295
	} catch(ClassFormatException e) {
301
	} catch(ClassFormatException e) {
296
		throw e;
302
		throw e;
297
	} catch (Exception e) {
303
	} catch (Exception e) {		
304
		e.printStackTrace();
298
		throw new ClassFormatException(
305
		throw new ClassFormatException(
299
			ClassFormatException.ErrTruncatedInput, 
306
			ClassFormatException.ErrTruncatedInput, 
300
			readOffset); 
307
			readOffset);			
301
	}
308
	}
302
}
309
}
303
310
Lines 309-499 Link Here
309
public int accessFlags() {
316
public int accessFlags() {
310
	return this.accessFlags;
317
	return this.accessFlags;
311
}
318
}
312
private int decodeAnnotation(int offset) {
319
313
	int readOffset = offset;
314
	int utf8Offset = this.constantPoolOffsets[u2At(offset)];
315
	char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
316
	int numberOfPairs = u2At(offset + 2);
317
	readOffset += 4;
318
	switch(typeName.length) {
319
		case 21 :
320
			if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_INHERITED)) {
321
				this.tagBits |= TagBits.AnnotationInherited;
322
				return readOffset;		
323
			}
324
			break;
325
		case 22 :
326
			if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_DEPRECATED)) {
327
				this.tagBits |= TagBits.AnnotationDeprecated;
328
				return readOffset;		
329
			}
330
			break;
331
		case 29 :
332
			if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_TARGET)) {
333
				for (int i = 0; i < numberOfPairs; i++) {
334
					readOffset += 2;
335
					readOffset = decodeElementValueForJavaLangAnnotationTarget(readOffset);
336
				}
337
				return readOffset;		
338
			}
339
			break;
340
		case 33 :
341
			if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_DOCUMENTED)) {
342
				this.tagBits |= TagBits.AnnotationDocumented;
343
				return readOffset;		
344
			}
345
			break;
346
		case 32 :
347
			if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTION)) {
348
				for (int i = 0; i < numberOfPairs; i++) {
349
					readOffset += 2;
350
					readOffset = decodeElementValueForJavaLangAnnotationRetention(readOffset);
351
				}
352
				return readOffset;
353
			}
354
			break;
355
	}
356
	for (int i = 0; i < numberOfPairs; i++) {
357
		readOffset += 2;
358
		readOffset = decodeElementValue(readOffset);
359
	}
360
	return readOffset;
361
}
362
private int decodeElementValue(int offset) {
363
	int readOffset = offset;
364
	int tag = u1At(readOffset);
365
	readOffset++;
366
	switch(tag) {
367
		case 'B' :
368
		case 'C' :
369
		case 'D' :
370
		case 'F' :
371
		case 'I' :
372
		case 'J' :
373
		case 'S' :
374
		case 'Z' :
375
		case 's' :
376
			readOffset += 2;
377
			break;
378
		case 'e' :
379
			readOffset += 4;
380
			break;
381
		case 'c' :
382
			readOffset += 2;
383
			break;
384
		case '@' :
385
			readOffset = decodeAnnotation(readOffset);
386
			break;
387
		case '[' :
388
			int numberOfValues = u2At(readOffset);
389
			readOffset += 2;
390
			for (int i = 0; i < numberOfValues; i++) {
391
				readOffset = decodeElementValue(readOffset);
392
			}
393
			break;
394
	}
395
	return readOffset;
396
}
397
private int decodeElementValueForJavaLangAnnotationTarget(int offset) {
398
	int readOffset = offset;
399
	int tag = u1At(readOffset);
400
	readOffset++;
401
	switch(tag) {
402
		case 'B' :
403
		case 'C' :
404
		case 'D' :
405
		case 'F' :
406
		case 'I' :
407
		case 'J' :
408
		case 'S' :
409
		case 'Z' :
410
		case 's' :
411
			readOffset += 2;
412
			break;
413
		case 'e' :
414
			int utf8Offset = this.constantPoolOffsets[u2At(readOffset)];
415
			char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
416
			readOffset += 2;
417
			utf8Offset = this.constantPoolOffsets[u2At(readOffset)];
418
			char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
419
			readOffset += 2;
420
			if (typeName.length == 34 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_ELEMENTTYPE)) {
421
				this.tagBits |= Annotation.getTargetElementType(constName);
422
			}
423
			break;
424
		case 'c' :
425
			readOffset += 2;
426
			break;
427
		case '@' :
428
			readOffset = decodeAnnotation(readOffset);
429
			break;
430
		case '[' :
431
			int numberOfValues = u2At(readOffset);
432
			readOffset += 2;
433
			if (numberOfValues == 0) {
434
				this.tagBits |= TagBits.AnnotationTarget;
435
			} else {
436
				for (int i = 0; i < numberOfValues; i++) {
437
					readOffset = decodeElementValueForJavaLangAnnotationTarget(readOffset);
438
				}
439
			}
440
			break;
441
	}
442
	return readOffset;
443
}
444
private int decodeElementValueForJavaLangAnnotationRetention(int offset) {
445
	int readOffset = offset;
446
	int tag = u1At(readOffset);
447
	readOffset++;
448
	switch(tag) {
449
		case 'B' :
450
		case 'C' :
451
		case 'D' :
452
		case 'F' :
453
		case 'I' :
454
		case 'J' :
455
		case 'S' :
456
		case 'Z' :
457
		case 's' :
458
			readOffset += 2;
459
			break;
460
		case 'e' :
461
			int utf8Offset = this.constantPoolOffsets[u2At(readOffset)];
462
			char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
463
			readOffset += 2;
464
			utf8Offset = this.constantPoolOffsets[u2At(readOffset)];
465
			char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
466
			readOffset += 2;
467
			this.tagBits |= Annotation.getRetentionPolicy(constName);
468
			if (typeName.length == 38 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTIONPOLICY)) {
469
				this.tagBits |= Annotation.getRetentionPolicy(constName);
470
			}
471
			break;
472
		case 'c' :
473
			readOffset += 2;
474
			break;
475
		case '@' :
476
			readOffset = decodeAnnotation(readOffset);
477
			break;
478
		case '[' :
479
			int numberOfValues = u2At(readOffset);
480
			readOffset += 2;
481
			for (int i = 0; i < numberOfValues; i++) {
482
				readOffset = decodeElementValue(readOffset); // retention policy cannot be in an array initializer
483
			}
484
			break;
485
	}
486
	return readOffset;
487
}
488
/**
320
/**
489
 * @param offset the offset is located at the beginning of the runtime visible 
321
 * @param offset the offset is located at the beginning of the 
490
 * annotation attribute.
322
 * annotation attribute.
491
 */
323
 */
492
private void decodeStandardAnnotations(int offset) {
324
private void decodeAnnotations(int offset, boolean runtimeVisible) {
493
	int numberOfAnnotations = u2At(offset + 6);
325
	int numberOfAnnotations = u2At(offset + 6);
494
	int readOffset = offset + 8;
326
	int readOffset = offset + 8;
495
	for (int i = 0; i < numberOfAnnotations; i++) {
327
	int index = 0;
496
		readOffset = decodeAnnotation(readOffset);
328
	if( numberOfAnnotations > 0 ){		
329
		if( this.annotations == null )
330
			this.annotations = new AnnotationInfo[numberOfAnnotations];
331
		else{
332
			index = this.annotations.length;
333
			int newTotal = this.annotations.length + numberOfAnnotations;
334
			final AnnotationInfo[] newAnnos = new AnnotationInfo[newTotal];
335
			System.arraycopy(this.annotations, 0, newAnnos, 0, this.annotations.length);
336
			this.annotations = newAnnos;
337
		}
338
	}	
339
	for (int i = 0; i < numberOfAnnotations; i++, index++) {
340
		this.annotations[index] = new AnnotationInfo(reference, 
341
											    	 readOffset, 
342
													 this.constantPoolOffsets, 
343
													 runtimeVisible, false);
344
		readOffset = this.annotations[index].getLength() + readOffset;		
345
		this.tagBits |= this.annotations[index].getStandardAnnotationTagBits();		
497
	}
346
	}
498
}
347
}
499
/**
348
/**
Lines 655-660 Link Here
655
public IBinaryMethod[] getMethods() {
504
public IBinaryMethod[] getMethods() {
656
	return this.methods;
505
	return this.methods;
657
}
506
}
507
508
/**
509
 * @return the annotations or null if there is none.
510
 */
511
public IBinaryAnnotation[] getAnnotations(){
512
	return this.annotations;
513
}
658
/**
514
/**
659
 * Answer an int whose bits are set according the access constants
515
 * Answer an int whose bits are set according the access constants
660
 * defined by the VM spec.
516
 * defined by the VM spec.
Lines 967-980 Link Here
967
		}
823
		}
968
		for (int i = 0, max = methodsCount; i < max; i++) {
824
		for (int i = 0, max = methodsCount; i < max; i++) {
969
			methods[i].initialize();
825
			methods[i].initialize();
970
		}
826
		}		
971
		if (innerInfos != null) {
827
		if (innerInfos != null) {
972
			for (int i = 0, max = innerInfos.length; i < max; i++) {
828
			for (int i = 0, max = innerInfos.length; i < max; i++) {
973
				innerInfos[i].initialize();
829
				innerInfos[i].initialize();
974
			}
830
			}
975
		}
831
		}
832
		if(annotations != null){
833
			for( int i=0, max = annotations.length; i < max; i++ ){
834
				annotations[i].initialize();
835
			}
836
		}
976
		this.reset();
837
		this.reset();
977
	} catch(RuntimeException e) {
838
	} catch(RuntimeException e) {	
839
		e.printStackTrace();
978
		ClassFormatException exception = new ClassFormatException(e, this.classFileName);
840
		ClassFormatException exception = new ClassFormatException(e, this.classFileName);
979
		throw exception;
841
		throw exception;
980
	}
842
	}
Lines 1050-1053 Link Here
1050
	print.flush();
912
	print.flush();
1051
	return out.toString();
913
	return out.toString();
1052
}
914
}
915
916
public static void main(String[] args)
917
	throws ClassFormatException, IOException
918
{
919
	if( args == null || args.length != 1 ){
920
		System.err.println("ClassFileReader <filename>"); //$NON-NLS-1$
921
		System.exit(1);
922
	}
923
	File file = new File(args[0]);
924
	
925
	final ClassFileReader reader = read(file, true);	
926
927
	if(reader.annotations != null){
928
		System.err.println();
929
		for( int i=0; i<reader.annotations.length; i++ ){			
930
			System.err.println(reader.annotations[i]);			
931
		}
932
	}
933
	
934
	System.err.print("class "); //$NON-NLS-1$
935
	System.err.print( reader.getName() );
936
	final char[] superclass = reader.getSuperclassName();
937
	if( superclass != null){
938
		System.err.print( " extends " ); //$NON-NLS-1$
939
		System.err.print(superclass);
940
	}
941
	System.err.println();
942
	final char[][] interfaces = reader.getInterfaceNames();
943
	if( interfaces != null && interfaces.length > 0 ){
944
		
945
		System.err.print(" implements "); //$NON-NLS-1$
946
		for( int i=0; i<interfaces.length; i++ ){
947
			if( i != 0 )
948
				System.err.print(", " ); //$NON-NLS-1$		
949
			System.err.println(interfaces[i]);
950
		}
951
	}
952
	System.err.println();
953
	System.err.println('{');
954
	
955
	if( reader.fields != null ){
956
		for( int i=0; i<reader.fields.length; i++ ){			
957
			System.err.println(reader.fields[i]);
958
			System.err.println();
959
		}		
960
	}
961
	
962
	if( reader.methods != null ){
963
		for( int i=0; i<reader.methods.length; i++ ){			
964
			System.err.println(reader.methods[i]);
965
			System.err.println();
966
		}		
967
	}
968
	System.err.println();
969
	System.err.println('}');
970
}
971
1053
}
972
}
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileStruct.java (+1 lines)
Lines 163-168 Link Here
163
	}
163
	}
164
	return outputBuf;
164
	return outputBuf;
165
}
165
}
166
166
public static void verifyMethodNameAndSignature(char[] name, char[] signature) throws ClassFormatException {
167
public static void verifyMethodNameAndSignature(char[] name, char[] signature) throws ClassFormatException {
167
168
168
	// ensure name is not empty 
169
	// ensure name is not empty 
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.java (-58 / +62 lines)
Lines 12-18 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.IBinaryField;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
17
import org.eclipse.jdt.internal.compiler.impl.BooleanConstant;
17
import org.eclipse.jdt.internal.compiler.impl.BooleanConstant;
18
import org.eclipse.jdt.internal.compiler.impl.ByteConstant;
18
import org.eclipse.jdt.internal.compiler.impl.ByteConstant;
Lines 24-30 Link Here
24
import org.eclipse.jdt.internal.compiler.impl.LongConstant;
24
import org.eclipse.jdt.internal.compiler.impl.LongConstant;
25
import org.eclipse.jdt.internal.compiler.impl.ShortConstant;
25
import org.eclipse.jdt.internal.compiler.impl.ShortConstant;
26
import org.eclipse.jdt.internal.compiler.impl.StringConstant;
26
import org.eclipse.jdt.internal.compiler.impl.StringConstant;
27
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
28
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
27
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
29
import org.eclipse.jdt.internal.compiler.util.Util;
28
import org.eclipse.jdt.internal.compiler.util.Util;
30
29
Lines 39-44 Link Here
39
	private int signatureUtf8Offset;
38
	private int signatureUtf8Offset;
40
	private long tagBits;	
39
	private long tagBits;	
41
	private Object wrappedConstantValue;
40
	private Object wrappedConstantValue;
41
	private AnnotationInfo[] annotations;
42
/**
42
/**
43
 * @param classFileBytes byte[]
43
 * @param classFileBytes byte[]
44
 * @param offsets int[]
44
 * @param offsets int[]
Lines 64-70 Link Here
64
					break;
64
					break;
65
				case 'R' :
65
				case 'R' :
66
					if (CharOperation.equals(attributeName, RuntimeVisibleAnnotationsName)) {
66
					if (CharOperation.equals(attributeName, RuntimeVisibleAnnotationsName)) {
67
						decodeStandardAnnotations(readOffset);
67
						decodeAnnotations(readOffset, true);
68
					}
69
					else if(CharOperation.equals(attributeName, RuntimeInvisibleAnnotationsName)) {
70
						decodeAnnotations(readOffset, false);
68
					}
71
					}
69
			}
72
			}
70
		}
73
		}
Lines 79-144 Link Here
79
	}
82
	}
80
	return new String(this.getName()).compareTo(new String(((FieldInfo) o).getName()));
83
	return new String(this.getName()).compareTo(new String(((FieldInfo) o).getName()));
81
}
84
}
82
private int decodeAnnotation(int offset) {
85
83
	int readOffset = offset;
84
	int utf8Offset = this.constantPoolOffsets[u2At(offset)] - structOffset;
85
	char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
86
	int numberOfPairs = u2At(offset + 2);
87
	readOffset += 4;
88
	if (typeName.length == 22 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_DEPRECATED)) {
89
		this.tagBits |= TagBits.AnnotationDeprecated;
90
		return readOffset;		
91
	}
92
	for (int i = 0; i < numberOfPairs; i++) {
93
		readOffset += 2;
94
		readOffset = decodeElementValue(readOffset);
95
	}
96
	return readOffset;
97
}
98
private int decodeElementValue(int offset) {
99
	int readOffset = offset;
100
	int tag = u1At(readOffset);
101
	readOffset++;
102
	switch(tag) {
103
		case 'B' :
104
		case 'C' :
105
		case 'D' :
106
		case 'F' :
107
		case 'I' :
108
		case 'J' :
109
		case 'S' :
110
		case 'Z' :
111
		case 's' :
112
			readOffset += 2;
113
			break;
114
		case 'e' :
115
			readOffset += 4;
116
			break;
117
		case 'c' :
118
			readOffset += 2;
119
			break;
120
		case '@' :
121
			readOffset += decodeAnnotation(readOffset);
122
			break;
123
		case '[' :
124
			int numberOfValues = u2At(readOffset);
125
			readOffset += 2;
126
			for (int i = 0; i < numberOfValues; i++) {
127
				readOffset = decodeElementValue(readOffset);
128
			}
129
			break;
130
	}
131
	return readOffset;
132
}
133
/**
86
/**
134
 * @param offset the offset is located at the beginning of the runtime visible 
87
 * @param offset the offset is located at the beginning of the  
135
 * annotation attribute.
88
 * annotation attribute.
136
 */
89
 */
137
private void decodeStandardAnnotations(int offset) {
90
private void decodeAnnotations(int offset, boolean runtimeVisible) {
91
/*
92
int actualOffset = offset + structOffset;
93
String text = runtimeVisible ?  " runtime visible " : " runtime invisible ";
94
System.err.println("decoding field_info" + text + "annotation at " + actualOffset);
95
*/
138
	int numberOfAnnotations = u2At(offset + 6);
96
	int numberOfAnnotations = u2At(offset + 6);
139
	int readOffset = offset + 8;
97
	int readOffset = offset + 8;
140
	for (int i = 0; i < numberOfAnnotations; i++) {
98
	int index=0;
141
		readOffset = decodeAnnotation(readOffset);
99
	if( numberOfAnnotations > 0 ){		
100
		if( this.annotations == null )
101
			this.annotations = new AnnotationInfo[numberOfAnnotations];
102
		else{
103
			int curlen = this.annotations.length;
104
			index = curlen;
105
			int newTotal = curlen + numberOfAnnotations;
106
			final AnnotationInfo[] newAnnos = new AnnotationInfo[newTotal];
107
			System.arraycopy(this.annotations, 0, newAnnos, 0, curlen);
108
			this.annotations = newAnnos;
109
		}
110
	}	
111
	for (int i = 0; i < numberOfAnnotations; i++, index++) {		
112
		this.annotations[index] = new AnnotationInfo(reference, 
113
											           readOffset + structOffset, 
114
													   this.constantPoolOffsets, 
115
													   runtimeVisible, 
116
													   false);
117
		readOffset = this.annotations[index].getLength() + readOffset;		
118
		this.tagBits |= this.annotations[index].getStandardAnnotationTagBits();
142
	}
119
	}
143
}
120
}
144
/**
121
/**
Lines 211-216 Link Here
211
	}
188
	}
212
	return descriptor;
189
	return descriptor;
213
}
190
}
191
192
/**
193
 * @return the annotations or null if there is none.
194
 */
195
public IBinaryAnnotation[] getAnnotations(){
196
	return this.annotations;
197
}
198
214
/**
199
/**
215
 * Return a wrapper that contains the constant of the field.
200
 * Return a wrapper that contains the constant of the field.
216
 * @return java.lang.Object
201
 * @return java.lang.Object
Lines 269-274 Link Here
269
	getConstant();
254
	getConstant();
270
	getTypeName();
255
	getTypeName();
271
	getGenericSignature();
256
	getGenericSignature();
257
	if( annotations != null ){
258
		for( int i=0, max = annotations.length; i<max; i++ ){
259
			annotations[i].initialize();
260
		}
261
	}
272
	reset();
262
	reset();
273
}
263
}
274
/**
264
/**
Lines 365-370 Link Here
365
}
355
}
366
protected void reset() {
356
protected void reset() {
367
	this.constantPoolOffsets = null;
357
	this.constantPoolOffsets = null;
358
	if( annotations != null ){
359
		for( int i=0, max = annotations.length; i<max; i++ ){
360
			annotations[i].reset();
361
		}
362
	}
368
	super.reset();
363
	super.reset();
369
}
364
}
370
/**
365
/**
Lines 380-385 Link Here
380
}
375
}
381
public String toString() {
376
public String toString() {
382
	StringBuffer buffer = new StringBuffer(this.getClass().getName());
377
	StringBuffer buffer = new StringBuffer(this.getClass().getName());
378
	
379
	if(this.annotations != null){
380
		buffer.append('\n');
381
		for( int i=0; i<this.annotations.length; i++ ){			
382
			buffer.append(annotations[i]);
383
			buffer.append('\n');
384
		}
385
	}	
386
	
383
	int modifiers = getModifiers();
387
	int modifiers = getModifiers();
384
	return buffer
388
	return buffer
385
		.append("{") //$NON-NLS-1$
389
		.append("{") //$NON-NLS-1$
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java (-62 / +196 lines)
Lines 12-32 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.IBinaryMethod;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
17
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
18
17
19
public class MethodInfo extends ClassFileStruct implements IBinaryMethod, AttributeNamesConstants, Comparable {
18
public class MethodInfo extends ClassFileStruct implements IBinaryMethod, AttributeNamesConstants, Comparable {
20
	static private final char[][] noException = CharOperation.NO_CHAR_CHAR;
19
	static private final char[][] noException = CharOperation.NO_CHAR_CHAR;
21
	private int accessFlags;
20
	private int accessFlags;
22
	private int attributeBytes;
21
	private int attributeBytes;
23
	private int[] constantPoolOffsets;
22
	protected int[] constantPoolOffsets;
24
	private char[] descriptor;
23
	private char[] descriptor;
25
	private char[][] exceptionNames;
24
	private char[][] exceptionNames;
26
	private char[] name;
25
	private char[] name;
27
	private char[] signature;
26
	private char[] signature;
28
	private int signatureUtf8Offset;
27
	private int signatureUtf8Offset;
29
	private long tagBits;	
28
	private long tagBits;
29
	/** method annotation as well as parameter annotations 
30
	 * index 0 always contains the method annotation info.
31
	 * index 1 and onwards contains parameter annotation info. 
32
	 * If the array is of size 0, there are no annotations.
33
	 * If the array is of size 1, there are only method annotations.
34
	 * if the array has a size greater than 1, then there are at least 
35
	 * parameter annotations.
36
	 */
37
	private AnnotationInfo[][] allAnnotations;	
30
	
38
	
31
/**
39
/**
32
 * @param classFileBytes byte[]
40
 * @param classFileBytes byte[]
Lines 45-51 Link Here
45
		int utf8Offset = constantPoolOffsets[u2At(readOffset)] - structOffset;
53
		int utf8Offset = constantPoolOffsets[u2At(readOffset)] - structOffset;
46
		char[] attributeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
54
		char[] attributeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
47
		if (attributeName.length > 0) {
55
		if (attributeName.length > 0) {
48
			switch(attributeName[0]) {
56
			switch(attributeName[0]) {				
49
				case 'S' :
57
				case 'S' :
50
					if (CharOperation.equals(AttributeNamesConstants.SignatureName, attributeName)) {
58
					if (CharOperation.equals(AttributeNamesConstants.SignatureName, attributeName)) {
51
						this.signatureUtf8Offset = constantPoolOffsets[u2At(readOffset + 6)] - structOffset;
59
						this.signatureUtf8Offset = constantPoolOffsets[u2At(readOffset + 6)] - structOffset;
Lines 53-59 Link Here
53
					break;
61
					break;
54
				case 'R' :
62
				case 'R' :
55
					if (CharOperation.equals(attributeName, RuntimeVisibleAnnotationsName)) {
63
					if (CharOperation.equals(attributeName, RuntimeVisibleAnnotationsName)) {
56
						decodeStandardAnnotations(readOffset);
64
						decodeMethodAnnotations(readOffset, true);
65
					}
66
					else if (CharOperation.equals(attributeName, RuntimeInvisibleAnnotationsName)) {
67
						decodeMethodAnnotations(readOffset, false);
68
					}
69
					else if( CharOperation.equals(attributeName, RuntimeVisibleParameterAnnotationsName)){
70
						decodeParamAnnotations(readOffset, true);						
71
					}
72
					else if( CharOperation.equals(attributeName, RuntimeInvisibleParameterAnnotationsName)){
73
						decodeParamAnnotations(readOffset, false);
57
					}
74
					}
58
			}
75
			}
59
		}
76
		}
Lines 71-138 Link Here
71
	if (result != 0) return result;
88
	if (result != 0) return result;
72
	return new String(this.getMethodDescriptor()).compareTo(new String(otherMethod.getMethodDescriptor()));
89
	return new String(this.getMethodDescriptor()).compareTo(new String(otherMethod.getMethodDescriptor()));
73
}
90
}
74
private int decodeAnnotation(int offset) {
91
75
	int readOffset = offset;
92
/**
76
	int utf8Offset = this.constantPoolOffsets[u2At(offset)] - structOffset;
93
 * @param offset the offset is located at the beginning of the 
77
	char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
94
 * parameter annotation attribute.
78
	int numberOfPairs = u2At(offset + 2);
95
 */
79
	readOffset += 4;
96
private void decodeParamAnnotations(int offset, boolean runtimeVisible)
80
	if (typeName.length == 22 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_DEPRECATED)) {
97
{		
81
		this.tagBits |= TagBits.AnnotationDeprecated;
98
	// u1 num_parameters;
82
		return readOffset;		
99
	int numberOfParameters = u1At(offset + 6);
83
	}
100
	if( numberOfParameters > 0 ){
84
	for (int i = 0; i < numberOfPairs; i++) {
101
		// u2 attribute_name_index + u4 attribute_length + u1 num_parameters
85
		readOffset += 2;
102
		int readOffset = offset + 7;
86
		readOffset = decodeElementValue(readOffset);
103
		for( int i=0; i<numberOfParameters; i++ ){
104
			int numberOfAnnotations = u2At(readOffset);
105
			readOffset += 2;	    
106
			if( numberOfAnnotations > 0 ){	
107
				if(this.allAnnotations == null){
108
					this.allAnnotations = new AnnotationInfo[numberOfParameters + 1][];
109
					for(int j=0, len = numberOfParameters + 1; j < len; j++){
110
						this.allAnnotations[j] = null;
111
					}
112
				}
113
				else{
114
					if( this.allAnnotations.length == 1 ){
115
						// make room for the parameter annotations
116
						final AnnotationInfo[][] newArray = new AnnotationInfo[numberOfParameters + 1][];
117
						newArray[0] = this.allAnnotations[0];
118
						this.allAnnotations = newArray;
119
						for(int j=1; j <= numberOfParameters; j++){
120
							this.allAnnotations[j] = null;
121
						}
122
					}
123
					// else
124
					// have already initialize the field to the proper size.
125
				}
126
				final AnnotationInfo[] annos = 
127
					decodeAnnotations(readOffset, runtimeVisible, numberOfAnnotations);
128
				for( int aIndex = 0; aIndex < annos.length; aIndex ++ )
129
					readOffset += annos[aIndex].getLength();
130
				final int paramAnnoIndex = i + 1;
131
				if( this.allAnnotations[paramAnnoIndex] == null )
132
					this.allAnnotations[paramAnnoIndex] = annos;
133
				else{
134
					final int curlen = this.allAnnotations[paramAnnoIndex].length;
135
					final int newTotal = curlen + numberOfAnnotations;
136
					final AnnotationInfo[] newAnnos = new AnnotationInfo[newTotal];
137
					System.arraycopy(this.allAnnotations[paramAnnoIndex], 0, newAnnos, 0, curlen);
138
					System.arraycopy(annos, 0, newAnnos, curlen, numberOfAnnotations);
139
					this.allAnnotations[paramAnnoIndex] = newAnnos;
140
				}
141
			}
142
		}
87
	}
143
	}
88
	return readOffset;
89
}
144
}
90
private int decodeElementValue(int offset) {
145
91
	int readOffset = offset;
146
/**
92
	int tag = u1At(readOffset);
147
 * @param offset begining of the 'RuntimeVisibleAnnotation' or 'RuntimeInvisibleAnnotation'
93
	readOffset++;
148
 * attribute.
94
	switch(tag) {
149
 * @param runtimeVisible <code>true</code> to indicate decoding 'RuntimeVisibleAnnotation'
95
		case 'B' :
150
 */
96
		case 'C' :
151
private void decodeMethodAnnotations(int offset, boolean runtimeVisible){
97
		case 'D' :
152
	int numberOfAnnotations = u2At(offset + 6);
98
		case 'F' :
153
	final AnnotationInfo[] annos = decodeAnnotations(offset + 8, runtimeVisible, numberOfAnnotations);
99
		case 'I' :
154
	
100
		case 'J' :
155
	if( numberOfAnnotations > 0 ){
101
		case 'S' :
156
		if( runtimeVisible ){
102
		case 'Z' :
157
			for( int i=0; i<numberOfAnnotations; i++ ){
103
		case 's' :
158
				this.tagBits |= annos[i].getStandardAnnotationTagBits();
104
			readOffset += 2;
105
			break;
106
		case 'e' :
107
			readOffset += 4;
108
			break;
109
		case 'c' :
110
			readOffset += 2;
111
			break;
112
		case '@' :
113
			readOffset += decodeAnnotation(readOffset);
114
			break;
115
		case '[' :
116
			int numberOfValues = u2At(readOffset);
117
			readOffset += 2;
118
			for (int i = 0; i < numberOfValues; i++) {
119
				readOffset = decodeElementValue(readOffset);
120
			}
159
			}
121
			break;
160
		}
161
		
162
		if( this.allAnnotations == null )
163
			this.allAnnotations = new AnnotationInfo[][]{annos};
164
		else{
165
			int curlen = this.allAnnotations[0].length;
166
			int newTotal = curlen + numberOfAnnotations;
167
			final AnnotationInfo[] newAnnos = new AnnotationInfo[newTotal];
168
			System.arraycopy(this.allAnnotations[0], 0, newAnnos, 0, curlen);
169
			System.arraycopy(annos, 0, newAnnos, curlen, numberOfAnnotations);
170
			this.allAnnotations[0] = newAnnos;
171
		}
122
	}
172
	}
123
	return readOffset;
124
}
173
}
174
125
/**
175
/**
126
 * @param offset the offset is located at the beginning of the runtime visible 
176
 * @param offset the offset is located at the beginning of the  
127
 * annotation attribute.
177
 * annotation attribute.
128
 */
178
 */
129
private void decodeStandardAnnotations(int offset) {
179
private AnnotationInfo[] decodeAnnotations(int offset, 
130
	int numberOfAnnotations = u2At(offset + 6);
180
										   boolean runtimeVisible,
131
	int readOffset = offset + 8;
181
										   int numberOfAnnotations) {
182
	int readOffset = offset;
183
	AnnotationInfo[] result = null;
184
	if( numberOfAnnotations > 0 ){	
185
		result = new AnnotationInfo[numberOfAnnotations];	
186
	}	
187
	
132
	for (int i = 0; i < numberOfAnnotations; i++) {
188
	for (int i = 0; i < numberOfAnnotations; i++) {
133
		readOffset = decodeAnnotation(readOffset);
189
		result[i] = new AnnotationInfo(reference, 
190
									   readOffset + structOffset, 
191
									   this.constantPoolOffsets, 
192
									   runtimeVisible, 
193
									   false);		
194
		readOffset = result[i].getLength() + readOffset;		
134
	}
195
	}
196
	return result;
135
}
197
}
198
199
/**
200
 * @return the annotations or null if there is none.
201
 */
202
public IBinaryAnnotation[] getAnnotations(){
203
	if( this.allAnnotations == null || this.allAnnotations.length == 0 ) return null;
204
	return this.allAnnotations[0];
205
}
206
207
public IBinaryAnnotation[] getParameterAnnotations(int index)
208
{
209
	if(this.allAnnotations == null || this.allAnnotations.length < 2  ) return null;
210
	return this.allAnnotations[index + 1];
211
}
212
136
/**
213
/**
137
 * @see org.eclipse.jdt.internal.compiler.env.IGenericMethod#getArgumentNames()
214
 * @see org.eclipse.jdt.internal.compiler.env.IGenericMethod#getArgumentNames()
138
 */
215
 */
Lines 221-226 Link Here
221
	getMethodDescriptor();
298
	getMethodDescriptor();
222
	getExceptionTypeNames();
299
	getExceptionTypeNames();
223
	getGenericSignature();
300
	getGenericSignature();
301
	if( this.allAnnotations != null ){
302
		for( int i=0, max = this.allAnnotations.length; i<max; i++ ){
303
			if( this.allAnnotations[i] != null ){
304
				for( int aIndex=0, aMax = this.allAnnotations[i].length; aIndex<aMax; aIndex++ ){
305
					final AnnotationInfo anno = this.allAnnotations[i][aIndex];
306
					anno.initialize();					
307
				}				
308
			}
309
		}
310
	}	
224
	reset();
311
	reset();
225
}
312
}
226
/**
313
/**
Lines 306-311 Link Here
306
}
393
}
307
protected void reset() {
394
protected void reset() {
308
	this.constantPoolOffsets = null;
395
	this.constantPoolOffsets = null;
396
	if( this.allAnnotations != null ){
397
		for( int i=0, max = this.allAnnotations.length; i<max; i++ ){
398
			if( this.allAnnotations[i] != null ){
399
				final int aMax = this.allAnnotations[i].length;
400
				for( int aIndex=0; aIndex<aMax; aIndex++ ){
401
					final AnnotationInfo anno = this.allAnnotations[i][aIndex];
402
					anno.reset();					
403
				}				
404
			}
405
		}
406
	}
309
	super.reset();
407
	super.reset();
310
}
408
}
311
/**
409
/**
Lines 316-328 Link Here
316
public int sizeInBytes() {
414
public int sizeInBytes() {
317
	return attributeBytes;
415
	return attributeBytes;
318
}
416
}
319
public String toString() {
417
418
public Object getDefaultValue(){ return null; }
419
420
void toString(StringBuilder buffer)
421
{
320
	int modifiers = getModifiers();
422
	int modifiers = getModifiers();
321
	char[] desc = getGenericSignature();
423
	char[] desc = getGenericSignature();
322
	if (desc == null)
424
	if (desc == null)
323
		desc = getMethodDescriptor();
425
		desc = getMethodDescriptor();
324
	StringBuffer buffer = new StringBuffer(this.getClass().getName());
426
	
325
	return buffer
427
	buffer.append(this.getClass().getName());	
428
	
429
	final int totalNumAnno = this.allAnnotations == null ? 0 : this.allAnnotations.length;
430
	if(totalNumAnno > 0){
431
		buffer.append('\n');
432
		if(this.allAnnotations[0] != null ){
433
			for( int i=0, len = this.allAnnotations[0].length; i<len; i++ ){		
434
				
435
				buffer.append(this.allAnnotations[0][i]);
436
				buffer.append('\n');
437
			}	
438
		}
439
	}
440
	
441
	if(totalNumAnno > 1){		
442
		buffer.append('\n');
443
		for( int i=1; i<totalNumAnno; i++ ){
444
			buffer.append("param" + (i-1)); //$NON-NLS-1$
445
			buffer.append('\n');
446
			if( this.allAnnotations[i] != null ){
447
				for( int j=0, numParamAnno=this.allAnnotations[i].length; j<numParamAnno; j++){
448
					buffer.append(this.allAnnotations[i][j]);
449
					buffer.append('\n');
450
				}
451
			}
452
		}
453
	}
454
	
455
	buffer
326
		.append("{") //$NON-NLS-1$
456
		.append("{") //$NON-NLS-1$
327
		.append(
457
		.append(
328
			((modifiers & AccDeprecated) != 0 ? "deprecated " : "") //$NON-NLS-1$ //$NON-NLS-2$
458
			((modifiers & AccDeprecated) != 0 ? "deprecated " : "") //$NON-NLS-1$ //$NON-NLS-2$
Lines 335-341 Link Here
335
				+ ((modifiers & 0x0080) == 0x0080 ? "varargs " : "")) //$NON-NLS-1$ //$NON-NLS-2$
465
				+ ((modifiers & 0x0080) == 0x0080 ? "varargs " : "")) //$NON-NLS-1$ //$NON-NLS-2$
336
		.append(getSelector())
466
		.append(getSelector())
337
		.append(desc)
467
		.append(desc)
338
		.append("}") //$NON-NLS-1$
468
		.append("}"); //$NON-NLS-1$ 
339
		.toString(); 
469
}
470
public String toString() {
471
	final StringBuilder buffer = new StringBuilder();
472
	toString(buffer);
473
	return buffer.toString();
340
}
474
}
341
}
475
}
(-)compiler/org/eclipse/jdt/internal/compiler/env/IBinaryField.java (+6 lines)
Lines 13-18 Link Here
13
import org.eclipse.jdt.internal.compiler.impl.Constant;
13
import org.eclipse.jdt.internal.compiler.impl.Constant;
14
14
15
public interface IBinaryField extends IGenericField {
15
public interface IBinaryField extends IGenericField {
16
	
17
/**
18
 * @return the both runtime visible and invisible annoations that annotated this field.
19
 */
20
IBinaryAnnotation[] getAnnotations();
21
16
/**
22
/**
17
 * 
23
 * 
18
 * @return org.eclipse.jdt.internal.compiler.Constant
24
 * @return org.eclipse.jdt.internal.compiler.Constant
(-)compiler/org/eclipse/jdt/internal/compiler/env/IBinaryMethod.java (-1 / +12 lines)
Lines 16-22 Link Here
16
// member type) is also ignored by the compiler, BUT in this case it must be included
16
// member type) is also ignored by the compiler, BUT in this case it must be included
17
// in the constructor's signature.
17
// in the constructor's signature.
18
18
19
public interface IBinaryMethod extends IGenericMethod {
19
public interface IBinaryMethod extends IGenericMethod, IBinaryAnnotationMethod {
20
	
21
/**
22
 * @return the both runtime visible and invisible annoations that annotated this method.
23
 */
24
IBinaryAnnotation[] getAnnotations();
25
26
/**
27
 * @param index the index of the parameter of interest
28
 * @return the annotations on the <code>index</code>th parameter or null if none exists.
29
 */
30
IBinaryAnnotation[] getParameterAnnotations(int index);
20
31
21
/**
32
/**
22
 * Answer the resolved names of the exception types in the
33
 * Answer the resolved names of the exception types in the
(-)compiler/org/eclipse/jdt/internal/compiler/env/IBinaryType.java (+6 lines)
Lines 57-62 Link Here
57
 */
57
 */
58
58
59
IBinaryMethod[] getMethods();
59
IBinaryMethod[] getMethods();
60
61
/**
62
 * @return the both runtime visible and invisible annoations that annotated this type.
63
 */
64
IBinaryAnnotation[] getAnnotations();
65
60
/**
66
/**
61
 * Answer the resolved name of the type in the
67
 * Answer the resolved name of the type in the
62
 * class file format as specified in section 4.2 of the Java 2 VM spec.
68
 * class file format as specified in section 4.2 of the Java 2 VM spec.
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java (-1 / +1 lines)
Lines 17-23 Link Here
17
public final class ArrayBinding extends TypeBinding {
17
public final class ArrayBinding extends TypeBinding {
18
	// creation and initialization of the length field
18
	// creation and initialization of the length field
19
	// the declaringClass of this field is intentionally set to null so it can be distinguished.
19
	// the declaringClass of this field is intentionally set to null so it can be distinguished.
20
	public static final FieldBinding ArrayLength = new FieldBinding(LENGTH, IntBinding, AccPublic | AccFinal, null, Constant.NotAConstant);
20
	public static final FieldBinding ArrayLength = new SourceFieldBinding(LENGTH, IntBinding, AccPublic | AccFinal, null, Constant.NotAConstant);
21
21
22
	public TypeBinding leafComponentType;
22
	public TypeBinding leafComponentType;
23
	public int dimensions;
23
	public int dimensions;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java (-9 / +133 lines)
Lines 14-24 Link Here
14
14
15
import org.eclipse.jdt.core.compiler.CharOperation;
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
17
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
18
import org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair;
17
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
19
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
18
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
20
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
19
import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
21
import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
20
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
22
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
23
import org.eclipse.jdt.internal.compiler.env.IClassReference;
24
import org.eclipse.jdt.internal.compiler.env.IEnumConstantReference;
21
import org.eclipse.jdt.internal.compiler.env.IGenericType;
25
import org.eclipse.jdt.internal.compiler.env.IGenericType;
26
import org.eclipse.jdt.internal.compiler.impl.Constant;
22
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
27
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
23
28
24
/*
29
/*
Lines 42-47 Link Here
42
private MethodBinding[] methods;
47
private MethodBinding[] methods;
43
private ReferenceBinding[] memberTypes;
48
private ReferenceBinding[] memberTypes;
44
protected TypeVariableBinding[] typeVariables;
49
protected TypeVariableBinding[] typeVariables;
50
private AnnotationInstance[] annotations;
45
51
46
// For the link with the principle structure
52
// For the link with the principle structure
47
private LookupEnvironment environment;
53
private LookupEnvironment environment;
Lines 172-177 Link Here
172
		System.arraycopy(availableMethods, 0, availableMethods = new MethodBinding[count], 0, count);
178
		System.arraycopy(availableMethods, 0, availableMethods = new MethodBinding[count], 0, count);
173
	return availableMethods;
179
	return availableMethods;
174
}
180
}
181
182
public AnnotationInstance[] getAnnotations(){ return this.annotations; }
183
175
void cachePartsFrom(IBinaryType binaryType, boolean needFieldsAndMethods) {
184
void cachePartsFrom(IBinaryType binaryType, boolean needFieldsAndMethods) {
176
	// default initialization for super-interfaces early, in case some aborting compilation error occurs,
185
	// default initialization for super-interfaces early, in case some aborting compilation error occurs,
177
	// and still want to use binaries passed that point (e.g. type hierarchy resolver, see bug 63748).
186
	// and still want to use binaries passed that point (e.g. type hierarchy resolver, see bug 63748).
Lines 266-272 Link Here
266
		this.fields = NoFields;
275
		this.fields = NoFields;
267
		this.methods = NoMethods;
276
		this.methods = NoMethods;
268
	}
277
	}
278
	this.annotations = createAnnotations(binaryType.getAnnotations());	
279
}
280
281
private AnnotationInstance[] createAnnotations(IBinaryAnnotation[] annotationInfos ){
282
	
283
	AnnotationInstance[] result = NoAnnotations;
284
	if( annotationInfos != null ){
285
		int size = annotationInfos.length;
286
		if( size > 0 ){
287
			result = new BinaryAnnotation[size];
288
			for( int i = 0; i < size; i++ ){		
289
				result[i] = createAnnotation(annotationInfos[i]);				
290
			}
291
		}
292
	}
293
	return result;
294
}
295
296
private BinaryAnnotation createAnnotation(IBinaryAnnotation annnotationInfo )
297
{
298
	final ReferenceBinding annotationType = 
299
		environment.getTypeFromConstantPoolName(annnotationInfo.getTypeName(), 0, -1, false);
300
	final BinaryAnnotation annotation = new BinaryAnnotation(annotationType, this.environment);				 
301
	createElementValuePairs(annnotationInfo.getMemberValuePairs(), annotation);
302
	return annotation;
303
}
304
305
private void createElementValuePairs(final IBinaryElementValuePair[] pairs, 
306
							  		 final BinaryAnnotation anno)
307
{	
308
	final int len = pairs == null ? 0 : pairs.length; 
309
	anno.pairs = NoElementValuePairs;
310
	if( len > 1 ){
311
		anno.pairs = new ElementValuePair[len]; 
312
		for( int i = 0; i < len; i++ ){
313
			anno.pairs[i] = new BinaryElementValuePair(anno, 
314
										    			pairs[i].getMemberName(), 
315
													    getMemberValue(pairs[i].getMemberValue())); 				
316
		}
317
	}
269
}
318
}
319
320
private Object getMemberValue(final Object binaryValue)
321
{
322
	if( binaryValue == null ) return null;
323
	if( binaryValue instanceof Constant )
324
		return binaryValue;
325
	
326
	else if( binaryValue instanceof IClassReference ){
327
		final IClassReference ref = (IClassReference)binaryValue;
328
		return environment.getTypeFromSignature(ref.getTypeName(), 0, -1, false, null);
329
	}
330
	
331
	else if( binaryValue instanceof IEnumConstantReference ){
332
		final IEnumConstantReference ref = (IEnumConstantReference)binaryValue;
333
		final ReferenceBinding enumType = environment.getTypeFromConstantPoolName(ref.getTypeName(), 0, -1, false);
334
		return enumType.getField(ref.getEnumConstantName(), false);
335
	}
336
	else if( binaryValue instanceof Object[] ){
337
		final Object[] objects = (Object[])binaryValue;
338
		final int len = objects.length;
339
		if( len == 0 ) return objects;
340
		final Object[] values = new Object[len];
341
		for( int i = 0; i < len; i++ ){
342
			values[i] = getMemberValue(objects[i]);
343
		}
344
		return values;
345
	}
346
	else if( binaryValue instanceof IBinaryAnnotation )
347
		return createAnnotation((IBinaryAnnotation)binaryValue);
348
	
349
	// should never reach here.
350
	throw new IllegalStateException();
351
}
352
270
private void createFields(IBinaryField[] iFields, long sourceLevel) {
353
private void createFields(IBinaryField[] iFields, long sourceLevel) {
271
	this.fields = NoFields;
354
	this.fields = NoFields;
272
	if (iFields != null) {
355
	if (iFields != null) {
Lines 281-293 Link Here
281
				TypeBinding type = fieldSignature == null 
364
				TypeBinding type = fieldSignature == null 
282
					? environment.getTypeFromSignature(binaryField.getTypeName(), 0, -1, false, this) 
365
					? environment.getTypeFromSignature(binaryField.getTypeName(), 0, -1, false, this) 
283
					: environment.getTypeFromTypeSignature(new SignatureWrapper(fieldSignature), NoTypeVariables, this);
366
					: environment.getTypeFromTypeSignature(new SignatureWrapper(fieldSignature), NoTypeVariables, this);
367
				AnnotationInstance[] fieldAnnos = createAnnotations(binaryField.getAnnotations());
284
				FieldBinding field = 
368
				FieldBinding field = 
285
					new FieldBinding(
369
					new BinaryFieldBinding(
286
						binaryField.getName(), 
370
						binaryField.getName(), 
287
						type, 
371
						type, 
288
						binaryField.getModifiers() | AccUnresolved, 
372
						binaryField.getModifiers() | AccUnresolved, 
289
						this, 
373
						this, 
290
						binaryField.getConstant());
374
						binaryField.getConstant(),
375
						fieldAnnos);
291
				field.id = i; // ordinal
376
				field.id = i; // ordinal
292
				if (use15specifics)
377
				if (use15specifics)
293
					field.tagBits |= binaryField.getTagBits();
378
					field.tagBits |= binaryField.getTagBits();
Lines 304-309 Link Here
304
		methodModifiers &= ~AccVarargs; // vararg methods are not recognized until 1.5
389
		methodModifiers &= ~AccVarargs; // vararg methods are not recognized until 1.5
305
	ReferenceBinding[] exceptions = NoExceptions;
390
	ReferenceBinding[] exceptions = NoExceptions;
306
	TypeBinding[] parameters = NoParameters;
391
	TypeBinding[] parameters = NoParameters;
392
	AnnotationInstance[][] paramAnnotations = NoParamAnnotations; 
307
	TypeVariableBinding[] typeVars = NoTypeVariables;
393
	TypeVariableBinding[] typeVars = NoTypeVariables;
308
	TypeBinding returnType = null;
394
	TypeBinding returnType = null;
309
395
Lines 327-332 Link Here
327
		int size = numOfParams - startIndex;
413
		int size = numOfParams - startIndex;
328
		if (size > 0) {
414
		if (size > 0) {
329
			parameters = new TypeBinding[size];
415
			parameters = new TypeBinding[size];
416
			paramAnnotations = new AnnotationInstance[size][];
330
			index = 1;
417
			index = 1;
331
			int end = 0;   // first character is always '(' so skip it
418
			int end = 0;   // first character is always '(' so skip it
332
			for (int i = 0; i < numOfParams; i++) {
419
			for (int i = 0; i < numOfParams; i++) {
Lines 334-341 Link Here
334
				if (nextChar == 'L')
421
				if (nextChar == 'L')
335
					while ((nextChar = methodDescriptor[++end]) != ';'){/*empty*/}
422
					while ((nextChar = methodDescriptor[++end]) != ';'){/*empty*/}
336
423
337
				if (i >= startIndex)   // skip the synthetic arg if necessary
424
				if (i >= startIndex){   // skip the synthetic arg if necessary
338
					parameters[i - startIndex] = environment.getTypeFromSignature(methodDescriptor, index, end, false, this);
425
					parameters[i - startIndex] = environment.getTypeFromSignature(methodDescriptor, index, end, false, this);
426
					// 'paramAnnotations' line up with 'parameters'
427
					// int parameter to method.getParameterAnnotations() include the synthetic arg.
428
					paramAnnotations[i - startIndex] = createAnnotations(method.getParameterAnnotations(i));
429
				}
339
				index = end + 1;
430
				index = end + 1;
340
			}
431
			}
341
		}
432
		}
Lines 372-379 Link Here
372
				while (wrapper.signature[wrapper.start] != ')')
463
				while (wrapper.signature[wrapper.start] != ')')
373
					types.add(environment.getTypeFromTypeSignature(wrapper, typeVars, this));
464
					types.add(environment.getTypeFromTypeSignature(wrapper, typeVars, this));
374
				wrapper.start++; // skip ')'
465
				wrapper.start++; // skip ')'
375
				parameters = new TypeBinding[types.size()];
466
				int numParam = types.size();
376
				types.toArray(parameters);
467
				parameters = new TypeBinding[numParam];
468
				types.toArray(parameters);				
469
				
470
				paramAnnotations = new AnnotationInstance[numParam][];
471
				for( int i = 0; i < numParam; i ++ ){
472
					paramAnnotations[i] = createAnnotations( method.getParameterAnnotations(i) );
473
				}
377
			}
474
			}
378
		}
475
		}
379
476
Lines 401-410 Link Here
401
			}
498
			}
402
		}
499
		}
403
	}
500
	}
404
501
	final AnnotationInstance[] methodAnnos = createAnnotations(method.getAnnotations());
405
	MethodBinding result = method.isConstructor()
502
	
406
		? new MethodBinding(methodModifiers, parameters, exceptions, this)
503
	final MethodBinding result;
407
		: new MethodBinding(methodModifiers, method.getSelector(), returnType, parameters, exceptions, this);
504
	if( method.isConstructor() )
505
		result = new BinaryMethodBinding(methodModifiers, 
506
				 						 parameters, 
507
										 exceptions, 
508
										 this, 
509
										 methodAnnos,
510
										 paramAnnotations);
511
	else{
512
		if( isAnnotationType() ){			
513
			result = new AnnotationMethodBinding(methodModifiers, 
514
												 method.getSelector(), 
515
												 returnType,
516
												 this,
517
												 methodAnnos,
518
												 paramAnnotations,
519
												 getMemberValue(method.getDefaultValue()));
520
		}
521
		else result = new BinaryMethodBinding(methodModifiers, 
522
											  method.getSelector(), 
523
											  returnType, 
524
											  parameters, 
525
											  exceptions, 
526
											  this,
527
											  methodAnnos,
528
											  paramAnnotations); 
529
	}
530
	
408
	if (use15specifics)
531
	if (use15specifics)
409
		result.tagBits |= method.getTagBits();
532
		result.tagBits |= method.getTagBits();
410
	result.typeVariables = typeVars;
533
	result.typeVariables = typeVars;
Lines 413-418 Link Here
413
		typeVars[i].declaringElement = result;
536
		typeVars[i].declaringElement = result;
414
	return result;
537
	return result;
415
}
538
}
539
416
/**
540
/**
417
 * Create method bindings for binary type, filtering out <clinit> and synthetics
541
 * Create method bindings for binary type, filtering out <clinit> and synthetics
418
 */
542
 */
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-3 / +3 lines)
Lines 60-66 Link Here
60
			if (hierarchyIsInconsistent) { // 72468
60
			if (hierarchyIsInconsistent) { // 72468
61
				referenceContext.binding.fields = new FieldBinding[1];
61
				referenceContext.binding.fields = new FieldBinding[1];
62
				referenceContext.binding.fields[0] =
62
				referenceContext.binding.fields[0] =
63
					new FieldBinding(IncompleteHierarchy, IntBinding, AccPrivate, referenceContext.binding, null);
63
					new SourceFieldBinding(IncompleteHierarchy, IntBinding, AccPrivate, referenceContext.binding, null);
64
			} else {
64
			} else {
65
				referenceContext.binding.fields = NoFields;
65
				referenceContext.binding.fields = NoFields;
66
			}
66
			}
Lines 91-97 Link Here
91
				if (referenceContext.binding.isInterface())
91
				if (referenceContext.binding.isInterface())
92
					problemReporter().interfaceCannotHaveInitializers(referenceContext.binding, field);
92
					problemReporter().interfaceCannotHaveInitializers(referenceContext.binding, field);
93
			} else {
93
			} else {
94
				FieldBinding fieldBinding = new FieldBinding(field, null, field.modifiers | AccUnresolved, referenceContext.binding);
94
				FieldBinding fieldBinding = new SourceFieldBinding(field, null, field.modifiers | AccUnresolved, referenceContext.binding);
95
				// field's type will be resolved when needed for top level types
95
				// field's type will be resolved when needed for top level types
96
				checkAndSetModifiersForField(fieldBinding, field);
96
				checkAndSetModifiersForField(fieldBinding, field);
97
97
Lines 133-139 Link Here
133
			fieldBindings = newFieldBindings;
133
			fieldBindings = newFieldBindings;
134
		}
134
		}
135
		if (hierarchyIsInconsistent)
135
		if (hierarchyIsInconsistent)
136
			fieldBindings[count++] = new FieldBinding(IncompleteHierarchy, IntBinding, AccPrivate, referenceContext.binding, null);
136
			fieldBindings[count++] = new SourceFieldBinding(IncompleteHierarchy, IntBinding, AccPrivate, referenceContext.binding, null);
137
137
138
		if (count != fieldBindings.length)
138
		if (count != fieldBindings.length)
139
			System.arraycopy(fieldBindings, 0, fieldBindings = new FieldBinding[count], 0, count);
139
			System.arraycopy(fieldBindings, 0, fieldBindings = new FieldBinding[count], 0, count);
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java (-9 / +16 lines)
Lines 12-41 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.ast.ASTNode;
14
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
15
import org.eclipse.jdt.internal.compiler.ast.Annotation;
15
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.impl.Constant;
18
import org.eclipse.jdt.internal.compiler.impl.Constant;
18
19
19
public class FieldBinding extends VariableBinding {
20
public abstract class FieldBinding extends VariableBinding implements TypeConstants {
20
	public ReferenceBinding declaringClass;
21
	public ReferenceBinding declaringClass;	
22
	
21
protected FieldBinding() {
23
protected FieldBinding() {
22
	super(null, null, 0, null);
24
	super(null, null, 0, null);
23
	// for creating problem field
25
	// for creating problem field
24
}
26
}
25
public FieldBinding(char[] name, TypeBinding type, int modifiers, ReferenceBinding declaringClass, Constant constant) {
27
28
FieldBinding(char[] name, 
29
			 TypeBinding type, 
30
			 int modifiers, 
31
			 ReferenceBinding declaringClass, 
32
			 Constant constant)
33
{
26
	super(name, type, modifiers, constant);
34
	super(name, type, modifiers, constant);
27
	this.declaringClass = declaringClass;
35
	this.declaringClass = declaringClass;
28
}
36
}
29
public FieldBinding(FieldDeclaration field, TypeBinding type, int modifiers, ReferenceBinding declaringClass) {
37
30
	this(field.name, type, modifiers, declaringClass, null);
31
	field.binding = this; // record binding in declaration
32
}
33
// special API used to change field declaring class for runtime visibility check
38
// special API used to change field declaring class for runtime visibility check
34
public FieldBinding(FieldBinding initialFieldBinding, ReferenceBinding declaringClass) {
39
FieldBinding(FieldBinding initialFieldBinding, ReferenceBinding declaringClass) {
35
	super(initialFieldBinding.name, initialFieldBinding.type, initialFieldBinding.modifiers, initialFieldBinding.constant());
40
	super(initialFieldBinding.name, initialFieldBinding.type, initialFieldBinding.modifiers, 
41
		  initialFieldBinding.constant());
36
	this.declaringClass = declaringClass;
42
	this.declaringClass = declaringClass;
37
	this.id = initialFieldBinding.id;
43
	this.id = initialFieldBinding.id;
38
}
44
}
45
39
/* API
46
/* API
40
* Answer the receiver's binding type from Binding.BindingID.
47
* Answer the receiver's binding type from Binding.BindingID.
41
*/
48
*/
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java (-1 / +21 lines)
Lines 10-22 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
13
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
14
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.Annotation;
14
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16
import org.eclipse.jdt.internal.compiler.impl.Constant;
18
import org.eclipse.jdt.internal.compiler.impl.Constant;
17
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
19
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
18
20
19
public class LocalVariableBinding extends VariableBinding {
21
public class LocalVariableBinding extends VariableBinding implements TypeConstants {
20
22
21
	public boolean isArgument;
23
	public boolean isArgument;
22
	public int resolvedPosition; // for code generation (position in method context)
24
	public int resolvedPosition; // for code generation (position in method context)
Lines 128-133 Link Here
128
			initializationCount++;
130
			initializationCount++;
129
		}
131
		}
130
	}
132
	}
133
	
134
	public AnnotationInstance[] getAnnotations()
135
	{		
136
		if( this.isArgument && this.declaration != null){
137
			final Annotation[] argAnnos = declaration.annotations;
138
			final int numAnnotations = argAnnos == null ? 0 : argAnnos.length;
139
			AnnotationInstance[] result = NoAnnotations;
140
			if( numAnnotations > 0 ){
141
				result = new SourceAnnotation[numAnnotations];
142
				// check for errors
143
				ASTNode.resolveAnnotations(declaringScope, argAnnos, this);
144
				for( int j=0; j<numAnnotations; j++ ){
145
					result[j] = new SourceAnnotation(argAnnos[j]);
146
				}
147
			}		
148
		}
149
		return null;
150
	}
131
151
132
	public String toString() {
152
	public String toString() {
133
153
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java (-6 / +64 lines)
Lines 16-37 Link Here
16
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
17
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
18
18
19
public class MethodBinding extends Binding implements BaseTypes, TypeConstants {
19
public abstract class MethodBinding extends Binding implements BaseTypes, TypeConstants 
20
	
20
{		
21
	public int modifiers;
21
	public int modifiers;
22
	public char[] selector;
22
	public char[] selector;
23
	public TypeBinding returnType;
23
	public TypeBinding returnType;
24
	public TypeBinding[] parameters;
24
	public TypeBinding[] parameters;
25
	public ReferenceBinding[] thrownExceptions;
25
	public ReferenceBinding[] thrownExceptions;
26
	public ReferenceBinding declaringClass;
26
	public ReferenceBinding declaringClass;
27
	public TypeVariableBinding[] typeVariables = NoTypeVariables;
27
	public TypeVariableBinding[] typeVariables = NoTypeVariables;	
28
	
29
	/**
30
	 * In the majority of the time, there will no annotations at all.
31
	 * We will try to optimized the storage by packing both
32
	 * method and parameter annotation into one field. 
33
	 * 
34
	 * If there are no annotations and no parameter annotations, 
35
	 * this will be a zero-length array. 
36
	 * If this is an array of size 1, then method annotations are intialized and there 
37
	 * may or may not be parameter annotations. 
38
	 * If there are ever any parameter annotations, this will be an array of size > 1. 
39
	 * </code>null</code> in the array means not initialized.
40
	 * If the field is <code>null</code> this means it is not initalized at all.
41
	 * Binary types should always initialize this field;
42
	 * Method annotations are always at index 0 and parameter annotations 
43
	 * always start at index 1 if they are ever present.
44
	 */
45
	private AnnotationInstance[][] extendedModifiers = null;
28
	char[] signature;
46
	char[] signature;
29
	public long tagBits;
47
	public long tagBits;
30
	
48
	
31
protected MethodBinding() {
49
protected MethodBinding() {
32
	// for creating problem or synthetic method
50
	// for creating problem or synthetic method
33
}
51
}
34
public MethodBinding(int modifiers, char[] selector, TypeBinding returnType, TypeBinding[] parameters, ReferenceBinding[] thrownExceptions, ReferenceBinding declaringClass) {
52
protected MethodBinding(int modifiers,
53
						char[] selector, 
54
						TypeBinding returnType, 
55
						TypeBinding[] parameters, 
56
						ReferenceBinding[] thrownExceptions, 
57
						ReferenceBinding declaringClass)
58
{
35
	this.modifiers = modifiers;
59
	this.modifiers = modifiers;
36
	this.selector = selector;
60
	this.selector = selector;
37
	this.returnType = returnType;
61
	this.returnType = returnType;
Lines 46-63 Link Here
46
				this.modifiers |= AccStrictfp;
70
				this.modifiers |= AccStrictfp;
47
	}
71
	}
48
}
72
}
49
public MethodBinding(int modifiers, TypeBinding[] parameters, ReferenceBinding[] thrownExceptions, ReferenceBinding declaringClass) {
73
74
// constructor for creating binding representing constructor
75
protected MethodBinding(int modifiers,
76
				  		TypeBinding[] parameters,
77
				  		ReferenceBinding[] thrownExceptions,
78
				  		ReferenceBinding declaringClass)
79
{
50
	this(modifiers, TypeConstants.INIT, VoidBinding, parameters, thrownExceptions, declaringClass);
80
	this(modifiers, TypeConstants.INIT, VoidBinding, parameters, thrownExceptions, declaringClass);
51
}
81
}
82
83
52
// special API used to change method declaring class for runtime visibility check
84
// special API used to change method declaring class for runtime visibility check
53
public MethodBinding(MethodBinding initialMethodBinding, ReferenceBinding declaringClass) {
85
protected MethodBinding(MethodBinding initialMethodBinding, ReferenceBinding declaringClass) {
54
	this.modifiers = initialMethodBinding.modifiers;
86
	this.modifiers = initialMethodBinding.modifiers;
55
	this.selector = initialMethodBinding.selector;
87
	this.selector = initialMethodBinding.selector;
56
	this.returnType = initialMethodBinding.returnType;
88
	this.returnType = initialMethodBinding.returnType;
57
	this.parameters = initialMethodBinding.parameters;
89
	this.parameters = initialMethodBinding.parameters;
58
	this.thrownExceptions = initialMethodBinding.thrownExceptions;
90
	this.thrownExceptions = initialMethodBinding.thrownExceptions;
59
	this.declaringClass = declaringClass;
91
	this.declaringClass = declaringClass;
92
	this.extendedModifiers = initialMethodBinding.extendedModifiers;
60
}
93
}
94
61
/* Answer true if the argument types & the receiver's parameters are equal
95
/* Answer true if the argument types & the receiver's parameters are equal
62
*/
96
*/
63
public final boolean areParametersEqual(MethodBinding method) {
97
public final boolean areParametersEqual(MethodBinding method) {
Lines 365-370 Link Here
365
}
399
}
366
400
367
/**
401
/**
402
 * @return the annotations annotating this method.
403
 *         Return a zero-length array if none is found.
404
 */
405
public abstract AnnotationInstance[] getAnnotations();
406
407
408
409
/**
410
 * @param index the index of the parameter of interest
411
 * @return the annotations on the <code>index</code>th parameter
412
 * @throws ArrayIndexOutOfBoundsException when <code>index</code> is not valid 
413
 */
414
public abstract AnnotationInstance[] getParameterAnnotations(final int index);
415
416
417
418
/**
368
 * Compute the tagbits for standard annotations. For source types, these could require
419
 * Compute the tagbits for standard annotations. For source types, these could require
369
 * lazily resolving corresponding annotation nodes, in case of forward references.
420
 * lazily resolving corresponding annotation nodes, in case of forward references.
370
 * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits()
421
 * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits()
Lines 733-736 Link Here
733
public TypeVariableBinding[] typeVariables() {
784
public TypeVariableBinding[] typeVariables() {
734
	return this.typeVariables;
785
	return this.typeVariables;
735
}
786
}
787
788
/**
789
 * @return the default value iff this is an annotation method.
790
 *         Return <code>null</code> if there is no default value or 
791
 *         if this is not an annotaion method. 
792
 */
793
public abstract Object getDefaultValue();
736
}
794
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java (-4 / +9 lines)
Lines 287-299 Link Here
287
		if (method.isConstructor()) {
287
		if (method.isConstructor()) {
288
			if (method.isDefaultConstructor())
288
			if (method.isDefaultConstructor())
289
				modifiers |= AccIsDefaultConstructor;
289
				modifiers |= AccIsDefaultConstructor;
290
			method.binding = new MethodBinding(modifiers, null, null, declaringClass);
290
			method.binding = new SourceMethodBinding(modifiers, null, null, declaringClass);
291
			checkAndSetModifiersForConstructor(method.binding);
291
			checkAndSetModifiersForConstructor(method.binding);
292
		} else {
292
		} else {
293
			if (declaringClass.isInterface()) // interface or annotation type
293
			if (declaringClass.isInterface()) // interface or annotation type
294
				modifiers |= AccPublic | AccAbstract;
294
				modifiers |= AccPublic | AccAbstract;		
295
			method.binding =
295
			
296
				new MethodBinding(modifiers, method.selector, null, null, null, declaringClass);
296
			method.binding = new SourceMethodBinding(modifiers, 
297
													 method.selector, 
298
													 null, 
299
													 null, 
300
													 null, 
301
													 declaringClass);
297
			checkAndSetModifiersForMethod(method.binding);
302
			checkAndSetModifiersForMethod(method.binding);
298
		}
303
		}
299
		this.isStatic = method.binding.isStatic();
304
		this.isStatic = method.binding.isStatic();
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedFieldBinding.java (-1 / +6 lines)
Lines 55-60 Link Here
55
	 */
55
	 */
56
	public void setConstant(Constant constant) {
56
	public void setConstant(Constant constant) {
57
		this.originalField.setConstant(constant);
57
		this.originalField.setConstant(constant);
58
	}	
58
	}
59
	
60
	public AnnotationInstance[] getAnnotations()
61
	{
62
		return original().getAnnotations();
63
	}
59
}
64
}
60
65
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java (+16 lines)
Lines 18-23 Link Here
18
 * their signature did involve generics or not, so as to get the proper declaringClass for
18
 * their signature did involve generics or not, so as to get the proper declaringClass for
19
 * these methods.
19
 * these methods.
20
 */
20
 */
21
21
public class ParameterizedMethodBinding extends MethodBinding {
22
public class ParameterizedMethodBinding extends MethodBinding {
22
23
23
	protected MethodBinding originalMethod;
24
	protected MethodBinding originalMethod;
Lines 143-146 Link Here
143
	public MethodBinding original() {
144
	public MethodBinding original() {
144
		return this.originalMethod.original();
145
		return this.originalMethod.original();
145
	}
146
	}
147
	
148
	public AnnotationInstance[] getAnnotations()
149
	{
150
		return original().getAnnotations();
151
	}
152
	
153
	public AnnotationInstance[] getParameterAnnotations(int index)
154
	{
155
		return original().getParameterAnnotations(index);
156
	}
157
	
158
	public Object getDefaultValue()
159
	{
160
		return original().getDefaultValue();
161
	}
146
}
162
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemFieldBinding.java (+2 lines)
Lines 38-41 Link Here
38
public final int problemId() {
38
public final int problemId() {
39
	return problemId;
39
	return problemId;
40
}
40
}
41
42
public AnnotationInstance[] getAnnotations(){ return NoAnnotations; }
41
}
43
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemMethodBinding.java (+4 lines)
Lines 39-42 Link Here
39
public final int problemId() {
39
public final int problemId() {
40
	return this.problemReason;
40
	return this.problemReason;
41
}
41
}
42
43
public AnnotationInstance[] getAnnotations(){ return NoAnnotations; }
44
public AnnotationInstance[] getParameterAnnotations(int index){ return NoAnnotations; }
45
public Object getDefaultValue(){ return null; }
42
}
46
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java (-1 / +7 lines)
Lines 33-39 Link Here
33
	public char[] sourceName;
33
	public char[] sourceName;
34
	public int modifiers;
34
	public int modifiers;
35
	public PackageBinding fPackage;
35
	public PackageBinding fPackage;
36
37
	char[] fileName;
36
	char[] fileName;
38
	char[] constantPoolName;
37
	char[] constantPoolName;
39
	char[] signature;
38
	char[] signature;
Lines 857-860 Link Here
857
MethodBinding[] unResolvedMethods() { // for the MethodVerifier so it doesn't resolve types
856
MethodBinding[] unResolvedMethods() { // for the MethodVerifier so it doesn't resolve types
858
	return methods();
857
	return methods();
859
}
858
}
859
/**
860
 * @return the JSR 175 annotations that annotate this type.
861
 */
862
public AnnotationInstance[] getAnnotations()
863
{
864
	return NoAnnotations;
865
}
860
}
866
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-3 / +26 lines)
Lines 62-68 Link Here
62
	computeId();
62
	computeId();
63
}
63
}
64
private void addDefaultAbstractMethod(MethodBinding abstractMethod) {
64
private void addDefaultAbstractMethod(MethodBinding abstractMethod) {
65
	MethodBinding defaultAbstract = new MethodBinding(
65
	MethodBinding defaultAbstract = new SourceMethodBinding(
66
		abstractMethod.modifiers | AccDefaultAbstract,
66
		abstractMethod.modifiers | AccDefaultAbstract,
67
		abstractMethod.selector,
67
		abstractMethod.selector,
68
		abstractMethod.returnType,
68
		abstractMethod.returnType,
Lines 633-638 Link Here
633
	}
633
	}
634
	return this.tagBits;
634
	return this.tagBits;
635
}
635
}
636
637
public AnnotationInstance[] getAnnotations() {
638
	// make sure we first go resolve the annoations and report any problems found.
639
	getAnnotationTagBits();
640
	final TypeDeclaration typeDecl = this.scope.referenceContext;
641
	final int numAnnotations = typeDecl.annotations == null ? 0 : typeDecl.annotations.length;
642
	if( numAnnotations == 0 )
643
		return NoAnnotations;
644
	else{
645
		final AnnotationInstance[] instances = new AnnotationInstance[numAnnotations];
646
		for( int i=0; i<numAnnotations; i++ ){
647
			instances[i] = new SourceAnnotation(typeDecl.annotations[i]);
648
		}
649
		return instances;
650
	}
651
}
652
636
public MethodBinding[] getDefaultAbstractMethods() {
653
public MethodBinding[] getDefaultAbstractMethods() {
637
	int count = 0;
654
	int count = 0;
638
	for (int i = methods.length; --i >= 0;)
655
	for (int i = methods.length; --i >= 0;)
Lines 894-900 Link Here
894
	}
911
	}
895
	FieldBinding updatedField = (FieldBinding) fieldMap.get(newDeclaringClass);
912
	FieldBinding updatedField = (FieldBinding) fieldMap.get(newDeclaringClass);
896
	if (updatedField == null){
913
	if (updatedField == null){
897
		updatedField = new FieldBinding(targetField, newDeclaringClass);
914
		if( targetField instanceof SourceFieldBinding )
915
			updatedField = new SourceFieldBinding((SourceFieldBinding)targetField, newDeclaringClass);
916
		else
917
			updatedField = new BinaryFieldBinding((BinaryFieldBinding)targetField, newDeclaringClass);
898
		fieldMap.put(newDeclaringClass, updatedField);
918
		fieldMap.put(newDeclaringClass, updatedField);
899
	}
919
	}
900
	return updatedField;
920
	return updatedField;
Lines 912-918 Link Here
912
	}
932
	}
913
	MethodBinding updatedMethod = (MethodBinding) methodMap.get(newDeclaringClass);
933
	MethodBinding updatedMethod = (MethodBinding) methodMap.get(newDeclaringClass);
914
	if (updatedMethod == null){
934
	if (updatedMethod == null){
915
		updatedMethod = new MethodBinding(targetMethod, newDeclaringClass);
935
		if( targetMethod instanceof SourceMethodBinding )
936
			updatedMethod = new SourceMethodBinding((SourceMethodBinding)targetMethod, newDeclaringClass);
937
		else
938
			updatedMethod = new BinaryMethodBinding((BinaryMethodBinding)targetMethod, newDeclaringClass);
916
		methodMap.put(newDeclaringClass, updatedMethod);
939
		methodMap.put(newDeclaringClass, updatedMethod);
917
	}
940
	}
918
	return updatedMethod;
941
	return updatedMethod;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticArgumentBinding.java (+4 lines)
Lines 55-58 Link Here
55
			AccFinal,
55
			AccFinal,
56
			true);
56
			true);
57
	}
57
	}
58
	
59
	public AnnotationInstance[] getAnnotations(){ 
60
		return isArgument ? NoAnnotations : null; 
61
	}
58
}
62
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticFieldBinding.java (+2 lines)
Lines 21-24 Link Here
21
		this.index = index;
21
		this.index = index;
22
		this.tagBits |= TagBits.AnnotationResolved;
22
		this.tagBits |= TagBits.AnnotationResolved;
23
	}
23
	}
24
	
25
	public AnnotationInstance[] getAnnotations(){ return NoAnnotations; }
24
}
26
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java (+4 lines)
Lines 335-338 Link Here
335
	protected boolean isConstructorRelated() {
335
	protected boolean isConstructorRelated() {
336
		return kind == ConstructorAccess;
336
		return kind == ConstructorAccess;
337
	}
337
	}
338
	
339
	public AnnotationInstance[] getAnnotations(){ return NoAnnotations; }
340
	public AnnotationInstance[] getParameterAnnotations(int paramIndex){ return NoAnnotations; }
341
	public Object getDefaultValue(){ return null; }
338
}
342
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java (+3 lines)
Lines 133-138 Link Here
133
	ReferenceBinding[] NoSuperInterfaces = new ReferenceBinding[0];
133
	ReferenceBinding[] NoSuperInterfaces = new ReferenceBinding[0];
134
	ReferenceBinding[] NoMemberTypes = new ReferenceBinding[0];
134
	ReferenceBinding[] NoMemberTypes = new ReferenceBinding[0];
135
	TypeVariableBinding[] NoTypeVariables = new TypeVariableBinding[0];
135
	TypeVariableBinding[] NoTypeVariables = new TypeVariableBinding[0];
136
	AnnotationInstance[] NoAnnotations = new AnnotationInstance[0];
137
	ElementValuePair[] NoElementValuePairs = new ElementValuePair[0];
138
	AnnotationInstance[][] NoParamAnnotations = new AnnotationInstance[0][0];
136
	
139
	
137
	// Synthetics
140
	// Synthetics
138
	char[] INIT = "<init>".toCharArray(); //$NON-NLS-1$
141
	char[] INIT = "<init>".toCharArray(); //$NON-NLS-1$
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/UpdatedMethodBinding.java (+3 lines)
Lines 22-25 Link Here
22
	public TypeBinding constantPoolDeclaringClass() {
22
	public TypeBinding constantPoolDeclaringClass() {
23
		return this.updatedDeclaringClass;
23
		return this.updatedDeclaringClass;
24
	}
24
	}
25
	public AnnotationInstance[] getAnnotations(){ return NoAnnotations; }
26
	public AnnotationInstance[] getParameterAnnotations(int index){ return NoAnnotations; }
27
	public Object getDefaultValue(){ return null; }
25
}
28
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/VariableBinding.java (-1 / +7 lines)
Lines 51-60 Link Here
51
	public void setConstant(Constant constant) {
51
	public void setConstant(Constant constant) {
52
		this.constant = constant;
52
		this.constant = constant;
53
	}
53
	}
54
	/**
55
	 * @return the annotations iff this is a field, enum constant or parameter.
56
	 * Return null otherwise.
57
	 */
58
	public abstract AnnotationInstance[] getAnnotations();
59
	
54
	public String toString() {
60
	public String toString() {
55
		String s = (type != null) ? type.debugName() : "UNDEFINED TYPE"; //$NON-NLS-1$
61
		String s = (type != null) ? type.debugName() : "UNDEFINED TYPE"; //$NON-NLS-1$
56
		s += " "; //$NON-NLS-1$
62
		s += " "; //$NON-NLS-1$
57
		s += (name != null) ? new String(name) : "UNNAMED FIELD"; //$NON-NLS-1$
63
		s += (name != null) ? new String(name) : "UNNAMED FIELD"; //$NON-NLS-1$
58
		return s;
64
		return s;
59
	}
65
	}	
60
}
66
}
(-)dom/org/eclipse/jdt/core/dom/ASTConverter.java (+3 lines)
Lines 1892-1897 Link Here
1892
		markerAnnotation.setSourceRange(start, end - start + 1);
1892
		markerAnnotation.setSourceRange(start, end - start + 1);
1893
		if (this.resolveBindings) {
1893
		if (this.resolveBindings) {
1894
			recordNodes(markerAnnotation, annotation);
1894
			recordNodes(markerAnnotation, annotation);
1895
			markerAnnotation.resolveAnnotation();
1895
		}
1896
		}
1896
		return markerAnnotation;
1897
		return markerAnnotation;
1897
	}
1898
	}
Lines 1953-1958 Link Here
1953
		normalAnnotation.setSourceRange(start, end - start + 1);
1954
		normalAnnotation.setSourceRange(start, end - start + 1);
1954
		if (this.resolveBindings) {
1955
		if (this.resolveBindings) {
1955
			recordNodes(normalAnnotation, annotation);
1956
			recordNodes(normalAnnotation, annotation);
1957
			normalAnnotation.resolveAnnotation();
1956
		}
1958
		}
1957
		return normalAnnotation;
1959
		return normalAnnotation;
1958
	}
1960
	}
Lines 2129-2134 Link Here
2129
		singleMemberAnnotation.setSourceRange(start, end - start + 1);
2131
		singleMemberAnnotation.setSourceRange(start, end - start + 1);
2130
		if (this.resolveBindings) {
2132
		if (this.resolveBindings) {
2131
			recordNodes(singleMemberAnnotation, annotation);
2133
			recordNodes(singleMemberAnnotation, annotation);
2134
			singleMemberAnnotation.resolveAnnotation();
2132
		}
2135
		}
2133
		return singleMemberAnnotation;
2136
		return singleMemberAnnotation;
2134
	}
2137
	}
(-)dom/org/eclipse/jdt/core/dom/Annotation.java (+3 lines)
Lines 164-168 Link Here
164
	int memSize() {
164
	int memSize() {
165
		return BASE_NODE_SIZE + 1 * 4;
165
		return BASE_NODE_SIZE + 1 * 4;
166
	}
166
	}
167
	
168
	public IAnnotationInstance resolveAnnotation()
169
	{ return this.ast.getBindingResolver().resolveAnnotation(this); }
167
}
170
}
168
171
(-)dom/org/eclipse/jdt/core/dom/BindingResolver.java (-1 / +50 lines)
Lines 17-23 Link Here
17
17
18
/**
18
/**
19
 * A binding resolver is an internal mechanism for figuring out the binding
19
 * A binding resolver is an internal mechanism for figuring out the binding
20
 * for a major declaration, type, or name reference.
20
 * for a major declaration, type, or name reference. This also handles
21
 * the creation and mapping between annotations and the ast nodes that defines them
21
 * <p>
22
 * <p>
22
 * The default implementation serves as the default binding resolver
23
 * The default implementation serves as the default binding resolver
23
 * that does no resolving whatsoever. Internal subclasses do all the real work.
24
 * that does no resolving whatsoever. Internal subclasses do all the real work.
Lines 91-96 Link Here
91
	ASTNode findDeclaringNode(String bindingKey) {
92
	ASTNode findDeclaringNode(String bindingKey) {
92
		return null;
93
		return null;
93
	}
94
	}
95
	
96
	/**
97
	 * Finds the corresponding AST node from which the given annotation instance originated.
98
	 * 
99
	 * The default implementation of this method returns <code>null</code>.
100
	 * Subclasses may reimplement.
101
	 * </p>
102
	 * 
103
	 * @param instance the dom annotation
104
	 * @return the corresponding node where the bindings is declared, 
105
	 *    or <code>null</code> if none
106
	 */
107
	ASTNode findDeclaringNode(IAnnotationInstance instance){
108
		return null;
109
	}
94
110
95
	/**
111
	/**
96
	 * Allows the user to get information about the given old/new pair of
112
	 * Allows the user to get information about the given old/new pair of
Lines 164-169 Link Here
164
	}
180
	}
165
	
181
	
166
	/**
182
	/**
183
	 * Return the new annotation corresponding to the given old annotation
184
	 * <p>
185
	 * The default implementation of this method returns <code>null</code>
186
	 * Subclasses may reimplement.
187
	 * </p>
188
	 * 
189
	 * @param instance the old annotation 
190
	 * @return the new DOM annotation
191
	 */
192
	IAnnotationInstance getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance instance){
193
		return null;
194
	}
195
	
196
	/**
167
	 * Returns the compiler lookup environment used by this binding resolver.
197
	 * Returns the compiler lookup environment used by this binding resolver.
168
	 * Returns <code>null</code> if none.
198
	 * Returns <code>null</code> if none.
169
	 * 
199
	 * 
Lines 785-790 Link Here
785
	}
815
	}
786
	
816
	
787
	/**
817
	/**
818
	 * Resolves the given annotation instance and returns the DOM representation for it.
819
	 * <p>
820
	 * The implementation of {@link Annotation#resolveAnnotation()}
821
	 * forwards to this method. 
822
	 * </p>
823
	 * <p>
824
	 * The default implementation of this method returns <code>null</code>.
825
	 * Subclasses may reimplement.
826
	 * </p>
827
	 * 
828
	 * @param annotation the annotation ast node of interest
829
	 * @return the DOM annotation representation for the given ast node, or 
830
	 *    <code>null</code> if none is available
831
	 */
832
	IAnnotationInstance resolveAnnotation(Annotation annotation){
833
		return null;
834
	}	
835
	
836
	/**
788
	 * Returns the compilation unit scope used by this binding resolver.
837
	 * Returns the compilation unit scope used by this binding resolver.
789
	 * Returns <code>null</code> if none.
838
	 * Returns <code>null</code> if none.
790
	 * 
839
	 * 
(-)dom/org/eclipse/jdt/core/dom/CompilationUnit.java (+18 lines)
Lines 406-411 Link Here
406
	public ASTNode findDeclaringNode(IBinding binding) {
406
	public ASTNode findDeclaringNode(IBinding binding) {
407
		return this.ast.getBindingResolver().findDeclaringNode(binding);
407
		return this.ast.getBindingResolver().findDeclaringNode(binding);
408
	}
408
	}
409
	
410
	/**
411
	 * Finds the corresponding AST node in the given compilation unit from 
412
	 * which the given binding originated. Returns <code>null</code> if the
413
	 * binding does not correspond to any node in this compilation unit.
414
	 *
415
	 * This method always returns
416
	 * <code>null</code> when the binding object comes from a different AST.
417
	 * 
418
	 * @param instance the binding
419
	 * @return the corresponding node where the given binding is declared,
420
	 * or <code>null</code> if the binding does not correspond to a node in this
421
	 * compilation unit or if bindings were not requested when this AST was built
422
	 * @see #findDeclaringNode(String)
423
	 */
424
	public ASTNode findDeclaringNode(IAnnotationInstance instance) {
425
		return this.ast.getBindingResolver().findDeclaringNode(instance);
426
	}
409
427
410
	/**
428
	/**
411
	 * Finds the corresponding AST node in the given compilation unit from 
429
	 * Finds the corresponding AST node in the given compilation unit from 
(-)dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java (-3 / +41 lines)
Lines 90-97 Link Here
90
		Map bindingKeysToBindings;
90
		Map bindingKeysToBindings;
91
		/**
91
		/**
92
		 * This map is used to keep the correspondance between new bindings and the 
92
		 * This map is used to keep the correspondance between new bindings and the 
93
		 * compiler bindings. This is an identity map. We should only create one object
93
		 * compiler bindings as well as new annotation instances to their 
94
		 * for one binding.
94
		 * internal counterpart. 
95
		 * This is an identity map. We should only create one object
96
		 * for one binding or annotation.
97
		 * 
95
		 */
98
		 */
96
		Map compilerBindingsToASTBindings;
99
		Map compilerBindingsToASTBindings;
97
		
100
		
Lines 107-113 Link Here
107
	Map astNodesToBlockScope;
110
	Map astNodesToBlockScope;
108
	
111
	
109
	/**
112
	/**
110
	 * This map is used to get an ast node from its binding (new binding)
113
	 * This map is used to get an ast node from its binding (new binding) or DOM
111
	 */
114
	 */
112
	Map bindingsToAstNodes;
115
	Map bindingsToAstNodes;
113
	
116
	
Lines 183-188 Link Here
183
		return (ASTNode) this.bindingsToAstNodes.get(binding);
186
		return (ASTNode) this.bindingsToAstNodes.get(binding);
184
	}
187
	}
185
	
188
	
189
	synchronized ASTNode findDeclaringNode(IAnnotationInstance instance)
190
	{
191
		if( instance == null ) 
192
			return null;
193
		return (ASTNode)this.bindingsToAstNodes.get(instance);
194
	}
195
	
186
	IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) {
196
	IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) {
187
		switch (binding.kind()) {
197
		switch (binding.kind()) {
188
			case Binding.PACKAGE:
198
			case Binding.PACKAGE:
Lines 351-356 Link Here
351
		return null;
361
		return null;
352
	}
362
	}
353
	
363
	
364
	synchronized IAnnotationInstance getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance internalInstance){
365
		IAnnotationInstance domInstance = 
366
			(IAnnotationInstance) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance);
367
		if (domInstance != null) {
368
			return domInstance;
369
		}
370
		domInstance = new AnnotationInstance(internalInstance, this);
371
		this.bindingTables.compilerBindingsToASTBindings.put(internalInstance, domInstance);
372
		return domInstance;
373
	}
374
	
354
	/*
375
	/*
355
	 * Method declared on BindingResolver.
376
	 * Method declared on BindingResolver.
356
	 */
377
	 */
Lines 1398-1403 Link Here
1398
		return null;
1419
		return null;
1399
	}
1420
	}
1400
	
1421
	
1422
	synchronized IAnnotationInstance resolveAnnotation(final Annotation domASTNode)
1423
	{
1424
		Object oldNode = this.newAstToOldAst.get(domASTNode);
1425
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) {
1426
			org.eclipse.jdt.internal.compiler.ast.Annotation internalAstNode = 
1427
				(org.eclipse.jdt.internal.compiler.ast.Annotation) oldNode;
1428
			
1429
			IAnnotationInstance domAnnotation = this.getAnnotationInstance(internalAstNode.compilerAnnotation);
1430
			if (domAnnotation == null) {
1431
				return null;
1432
			}
1433
			this.bindingsToAstNodes.put(domAnnotation, domASTNode);			
1434
			return domAnnotation;
1435
		}
1436
		return null;
1437
	}
1438
	
1401
	/*
1439
	/*
1402
	 * Method declared on BindingResolver.
1440
	 * Method declared on BindingResolver.
1403
	 */
1441
	 */
(-)dom/org/eclipse/jdt/core/dom/IMethodBinding.java (-2 / +55 lines)
Lines 42-49 Link Here
42
	 * @return <code>true</code> if this is the binding for a constructor,
42
	 * @return <code>true</code> if this is the binding for a constructor,
43
	 *    and <code>false</code> if this is the binding for a method
43
	 *    and <code>false</code> if this is the binding for a method
44
	 */ 
44
	 */ 
45
	public boolean isConstructor();
45
	public boolean isConstructor();	
46
46
	
47
	/**
47
	/**
48
	 * Returns whether this binding is known to be a compiler-generated 
48
	 * Returns whether this binding is known to be a compiler-generated 
49
	 * default constructor. 
49
	 * default constructor. 
Lines 266-271 Link Here
266
	public boolean isVarargs();
266
	public boolean isVarargs();
267
	
267
	
268
	/**
268
	/**
269
	 * Return whether this binding is for an annotation method.
270
	 * 
271
	 * @return <code>true</code> iff this is the binding for an annotation method 
272
	 *         and <code>false</code> otherwise.
273
	 */
274
	public boolean isAnnotationMethod();
275
276
	/**
277
	 * Return the default value of an annotation method, iff this method
278
	 * binding represents an annotation method that has a default value.
279
	 * Return <code>null</code> otherwise.
280
	 * 
281
	 * 
282
	 * If the type of the value is a primitive type, the result is the boxed equivalent 
283
	 * (i.e., int returned as an <code>Integer</code>). If the type of the value is
284
	 * <code>String</code>, the result is the string itself. If the type of the value 
285
	 * is an enum type, <code>IVariableBinding</code> is returned. If the type of the
286
	 * value is an annotation type, <code>IAnnotationInstance</code> is returned. 
287
	 * If the type of the value is an array, then an one-dimensional array will be
288
	 * returned. If there are not defaulta value, the result is <code>null</code>.
289
	 * 	
290
	 * 
291
	 * @return the default value of an annotation method. Return <code>null</code>
292
	 * if one does not exist or if this binding is not an annotation method binding.
293
	 * This will also return <code>null</code> if no binding information is requested
294
	 * when this DOM/AST is built.
295
	 * 
296
	 */
297
	public Object getDefaultValue();
298
299
	
300
	/**
269
	 * Returns whether this method overrides the given method,
301
	 * Returns whether this method overrides the given method,
270
	 * as specified in section 6.4.2 of <em>The Java Language 
302
	 * as specified in section 6.4.2 of <em>The Java Language 
271
	 * Specification, Second Edition</em> (JLS2).
303
	 * Specification, Second Edition</em> (JLS2).
Lines 276-279 Link Here
276
	 * @since 3.1
308
	 * @since 3.1
277
	 */
309
	 */
278
	public boolean overrides(IMethodBinding method);
310
	public boolean overrides(IMethodBinding method);
311
	
312
	/**
313
	 * Return the annotations annotating this method/constructor.
314
	 * The behavior of this API is the same regardless of whether 
315
	 * this is a parameterized method or not.
316
	 * 
317
	 * @return the annotations annotating this method/costructor.
318
	 */
319
	public IAnnotationInstance[] getAnnotations();
320
	
321
	/**
322
	 * Return the annotations of a parameter of this method.
323
	 * The behavior of this API is the same regardless of whether 
324
	 * this is a parameterized method or not.
325
	 * 
326
	 * @param paramIndex the index of the parameter of interest.
327
	 * @return the annotations of the <code>paramIndex</code>th parameter
328
	 * @throws ArrayIndexOutOfBoundsException if <code>paramIndex</code> is 
329
	 * not a valid index. 
330
	 */
331
	public IAnnotationInstance[] getParameterAnnotations(int paramIndex);
279
}
332
}
(-)dom/org/eclipse/jdt/core/dom/ITypeBinding.java (+15 lines)
Lines 792-795 Link Here
792
	 * @since 2.1
792
	 * @since 2.1
793
	 */
793
	 */
794
	public String getQualifiedName();
794
	public String getQualifiedName();
795
	
796
	/**
797
	 * Return the annotations iff one of {@link #isAnnotation()}, {@link #isEnum},
798
	 * {@link #isClass} or {@link #isInterface()} returns <code>true</code>.
799
	 * Return null otherwise.
800
	 * 
801
	 * @return the annotations annotating the type if it is a reference type.
802
	 * Return null otherwise.
803
	 * @see #isAnnotation()
804
	 * @see #isEnum()
805
	 * @see #isClass()
806
	 * @see #isInterface()
807
	 * @since 3.1
808
	 */
809
	public IAnnotationInstance[] getAnnotations();
795
}
810
}
(-)dom/org/eclipse/jdt/core/dom/IVariableBinding.java (+15 lines)
Lines 150-154 Link Here
150
	 * @since 3.1
150
	 * @since 3.1
151
	 */
151
	 */
152
	public IVariableBinding getVariableDeclaration();
152
	public IVariableBinding getVariableDeclaration();
153
	
154
	/**
155
	 * Return the annotations annotating this variable if {@link #isField()} or
156
	 * {@link #isEnumConstant()} return <code>true</code> or this binding 
157
	 * is a parameter.
158
	 * If this is a field, the behavior of this API is the same regardless of whether 
159
	 * it is parameterized or not.
160
	 *  
161
	 * @return the annotations of this variable iff it is a field, an enum constant 
162
	 * or an parameter. Return <code>null</code> otherwise.
163
	 * @see #isEnumConstant()
164
	 * @see #isField()
165
	 * @since 3.1
166
	 */
167
	public IAnnotationInstance[] getAnnotations();
153
168
154
}
169
}
(-)dom/org/eclipse/jdt/core/dom/MethodBinding.java (+42 lines)
Lines 383-389 Link Here
383
		MethodVerifier methodVerifier = lookupEnvironment.methodVerifier();
383
		MethodVerifier methodVerifier = lookupEnvironment.methodVerifier();
384
		return methodVerifier.doesMethodOverride(this.binding, otherCompilerBinding);
384
		return methodVerifier.doesMethodOverride(this.binding, otherCompilerBinding);
385
	}
385
	}
386
	
387
	public IAnnotationInstance[] getAnnotations(){ 
388
		final org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance[] internalAnnotations =
389
			this.binding.getAnnotations();				
390
		final int len = internalAnnotations == null ?  0 : internalAnnotations.length;
391
		IAnnotationInstance[] domInstances = AnnotationInstance.NoAnnotations;
392
		if( len > 0 ){
393
			domInstances = new AnnotationInstance[len];
394
			for( int i=0; i<len; i++ ){
395
				domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
396
			}
397
		}
398
		return domInstances; 
399
	}
400
	
401
	public IAnnotationInstance[] getParameterAnnotations(int index){
402
		// this line may through <code>ArrayIndexOutOfBoundException()</code> if 
403
		// <code>index</code> is invalid
404
		final org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance[] internalAnnotations =
405
			this.binding.getParameterAnnotations(index);
406
		final int len = internalAnnotations == null ?  0 : internalAnnotations.length;
407
		IAnnotationInstance[] domInstances = AnnotationInstance.NoAnnotations;
408
		if( len > 0 ){
409
			domInstances = new AnnotationInstance[len];
410
			for( int i=0; i<len; i++ ){
411
				domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); 
412
			}
413
		}
414
		return domInstances; 
415
	}
416
	
417
	public boolean isAnnotationMethod()
418
	{ return this.binding instanceof org.eclipse.jdt.internal.compiler.lookup.AnnotationMethodBinding; }
386
419
420
	public Object getDefaultValue()
421
	{ 
422
		if( isAnnotationMethod() ){
423
			final Object internalObject = 
424
				((org.eclipse.jdt.internal.compiler.lookup.AnnotationMethodBinding)this.binding).getDefaultValue();
425
			return ElementValuePair.buildDOMValue(internalObject, this.binding.returnType, this.resolver);
426
		}
427
		return null;
428
	}
387
	/* 
429
	/* 
388
	 * For debugging purpose only.
430
	 * For debugging purpose only.
389
	 * @see java.lang.Object#toString()
431
	 * @see java.lang.Object#toString()
(-)dom/org/eclipse/jdt/core/dom/TypeBinding.java (+21 lines)
Lines 1029-1034 Link Here
1029
		return methodBinding.isDefaultAbstract() || methodBinding.isSynthetic() || (methodBinding.isConstructor() && isInterface());
1029
		return methodBinding.isDefaultAbstract() || methodBinding.isSynthetic() || (methodBinding.isConstructor() && isInterface());
1030
	}
1030
	}
1031
	
1031
	
1032
	public IAnnotationInstance[] getAnnotations(){ 
1033
		if( this.binding.isAnnotationType() || this.binding.isClass() ||
1034
		    this.binding.isEnum() || this.binding.isInterface() ){
1035
			final org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding refType = 
1036
				(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)this.binding;
1037
			final org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance[] 
1038
				internalAnnotations = refType.getAnnotations();
1039
			
1040
			final int len = internalAnnotations == null ? 0 : internalAnnotations.length;
1041
			IAnnotationInstance[] domInstances = AnnotationInstance.NoAnnotations;
1042
			if( len > 0 ){
1043
				domInstances = new AnnotationInstance[len];
1044
				for( int i=0; i<len; i++ ){
1045
					domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);					
1046
				}
1047
			}
1048
			return domInstances;
1049
		}
1050
		return null;
1051
	}
1052
	
1032
	/* 
1053
	/* 
1033
	 * For debugging purpose only.
1054
	 * For debugging purpose only.
1034
	 * @see java.lang.Object#toString()
1055
	 * @see java.lang.Object#toString()
(-)dom/org/eclipse/jdt/core/dom/VariableBinding.java (+17 lines)
Lines 289-294 Link Here
289
		}
289
		}
290
		return false;
290
		return false;
291
	}
291
	}
292
	
293
	public IAnnotationInstance[] getAnnotations()
294
	{ 
295
		final org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance[] internalAnnotations =
296
			this.binding.getAnnotations();
297
		// the variable is not an enum constant nor a field nor an argument.
298
		if( internalAnnotations == null ) return null;
299
		final int len = internalAnnotations.length;
300
		IAnnotationInstance[] domInstances = AnnotationInstance.NoAnnotations;
301
		if( len > 0 ){
302
			domInstances = new AnnotationInstance[len];
303
			for( int i=0; i<len; i++ ){
304
				domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
305
			}
306
		}
307
		return domInstances;                                                                  
308
	}
292
309
293
	/* 
310
	/* 
294
	 * For debugging purpose only.
311
	 * For debugging purpose only.
(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetScope.java (-1 / +8 lines)
Lines 12-17 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.lookup.ArrayBinding;
14
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.BinaryMethodBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
18
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
Lines 489-495 Link Here
489
	if (methodBinding != null) {
490
	if (methodBinding != null) {
490
		// handle the method clone() specially... cannot be protected or throw exceptions
491
		// handle the method clone() specially... cannot be protected or throw exceptions
491
		if (argumentTypes == NoParameters && CharOperation.equals(selector, CLONE))
492
		if (argumentTypes == NoParameters && CharOperation.equals(selector, CLONE))
492
			return new MethodBinding((methodBinding.modifiers & ~AccProtected) | AccPublic, CLONE, methodBinding.returnType, argumentTypes, null, object);
493
			return new BinaryMethodBinding((methodBinding.modifiers & ~AccProtected) | AccPublic, CLONE, 
494
										   methodBinding.returnType, 
495
										   argumentTypes, 
496
										   null, 
497
										   object, 
498
										   null, 
499
										   null);
493
		if (canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this))
500
		if (canBeSeenByForCodeSnippet(methodBinding, receiverType, invocationSite, this))
494
			return methodBinding;
501
			return methodBinding;
495
	}
502
	}
(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetSkeleton.java (+14 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.eval;
11
package org.eclipse.jdt.internal.eval;
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.env.IBinaryAnnotation;
14
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
15
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
15
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
17
import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
Lines 85-91 Link Here
85
		}
86
		}
86
		public long getTagBits() {
87
		public long getTagBits() {
87
			return 0;
88
			return 0;
89
		}	
90
		public IBinaryAnnotation[] getAnnotations() {
91
			return null;
92
		}
93
		
94
		public IBinaryAnnotation[] getParameterAnnotations(int index) {
95
			return null;
88
		}
96
		}
97
		
98
		public Object getDefaultValue(){ return null; }
89
}
99
}
90
	
100
	
91
/**
101
/**
Lines 148-153 Link Here
148
public char[] sourceFileName() {
158
public char[] sourceFileName() {
149
	return null;
159
	return null;
150
}
160
}
161
162
public IBinaryAnnotation[] getAnnotations() {
163
	return null;
164
}
151
public long getTagBits() {
165
public long getTagBits() {
152
	return 0;
166
	return 0;
153
}
167
}
(-)model/org/eclipse/jdt/core/JavaCore.java (-1 / +41 lines)
Lines 68-73 Link Here
68
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
68
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
69
import org.eclipse.core.runtime.preferences.IPreferencesService;
69
import org.eclipse.core.runtime.preferences.IPreferencesService;
70
import org.eclipse.core.runtime.preferences.InstanceScope;
70
import org.eclipse.core.runtime.preferences.InstanceScope;
71
import org.eclipse.jdt.core.compiler.ICompilationParticipant;
71
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
72
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
72
import org.eclipse.jdt.internal.core.*;
73
import org.eclipse.jdt.internal.core.*;
73
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
74
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
Lines 1015-1020 Link Here
1015
	}
1016
	}
1016
1017
1017
	/**
1018
	/**
1019
	 * Add a compilation participant listener dynamically.  It is not necessary
1020
	 * to call this for listeners registered with the compilationParticipants
1021
	 * extension point.
1022
	 * @param icp the listener
1023
	 * @param eventMask the set of events for which the listener will be notified,
1024
	 * built by ORing together values from CompilationParticipantEvent.
1025
	 */
1026
	public static void addCompilationParticipant(ICompilationParticipant icp, int eventMask) {
1027
		JavaModelManager.getJavaModelManager().getCompilationParticipants().add(icp, eventMask);
1028
	}
1029
1030
	/**
1018
	 * Adds the given listener for changes to Java elements.
1031
	 * Adds the given listener for changes to Java elements.
1019
	 * Has no effect if an identical listener is already registered.
1032
	 * Has no effect if an identical listener is already registered.
1020
	 *
1033
	 *
Lines 1515-1521 Link Here
1515
	public static String[] getClasspathVariableNames() {
1528
	public static String[] getClasspathVariableNames() {
1516
		return JavaModelManager.getJavaModelManager().variableNames();
1529
		return JavaModelManager.getJavaModelManager().variableNames();
1517
	}
1530
	}
1518
1531
	
1532
	/**
1533
	 * Returns an immutable list containing the subset of registered
1534
	 * listeners that have requested notification of at least one of
1535
	 * the events in the flags mask.
1536
	 * The first time this is called, it loads listeners from plugins,
1537
	 * which may cause plugins to be loaded.  If this is called on
1538
	 * multiple threads simultaneously, or if loading a plugin causes
1539
	 * this to be reentered, it may return an incomplete list of listeners,
1540
	 * but it is guaranteed not to crash or deadlock.
1541
	 * @param eventMask an ORed combination of values from ICompilationParticipant.
1542
	 * @return an immutable list of ICompilationParticipant.
1543
	 */
1544
	public static List getCompilationParticipants(int eventMask) {
1545
		return JavaModelManager.getJavaModelManager().getCompilationParticipants().get(eventMask);
1546
	}
1547
	
1519
	/**
1548
	/**
1520
	 * Returns a table of all known configurable options with their default values.
1549
	 * Returns a table of all known configurable options with their default values.
1521
	 * These options allow to configure the behaviour of the underlying components.
1550
	 * These options allow to configure the behaviour of the underlying components.
Lines 3567-3572 Link Here
3567
	}
3596
	}
3568
3597
3569
	/**
3598
	/**
3599
	 * Removes the specified compilation participant listener.  Has no effect
3600
	 * if the listener was not on the list, or if it was registered via the 
3601
	 * compilationParticipant extension point rather than a call to 
3602
	 * addCompilationParticipant.
3603
	 * @param icp the listener to remove
3604
	 */
3605
	public static void removeCompilationParticipant(ICompilationParticipant icp) {
3606
		JavaModelManager.getJavaModelManager().getCompilationParticipants().remove(icp);
3607
	}
3608
3609
	/**
3570
	 * Removes the given element changed listener.
3610
	 * Removes the given element changed listener.
3571
	 * Has no affect if an identical listener is not registered.
3611
	 * Has no affect if an identical listener is not registered.
3572
	 *
3612
	 *
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-5 / +89 lines)
Lines 15-22 Link Here
15
import org.eclipse.core.resources.*;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.jdt.core.*;
17
import org.eclipse.jdt.core.*;
18
import org.eclipse.jdt.core.compiler.*;
18
import org.eclipse.jdt.core.compiler.CharOperation;
19
import org.eclipse.jdt.core.compiler.ICompilationParticipant;
19
import org.eclipse.jdt.core.compiler.IProblem;
20
import org.eclipse.jdt.core.compiler.IProblem;
21
import org.eclipse.jdt.core.compiler.PostReconcileCompilationEvent;
20
import org.eclipse.jdt.core.dom.AST;
22
import org.eclipse.jdt.core.dom.AST;
21
import org.eclipse.jdt.internal.compiler.ASTVisitor;
23
import org.eclipse.jdt.internal.compiler.ASTVisitor;
22
import org.eclipse.jdt.internal.compiler.IProblemFactory;
24
import org.eclipse.jdt.internal.compiler.IProblemFactory;
Lines 25-30 Link Here
25
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
27
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
26
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
28
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
27
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
29
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
30
import org.eclipse.jdt.internal.core.JavaModelManager.PerWorkingCopyInfo;
28
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
31
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
29
import org.eclipse.jdt.internal.core.util.Util;
32
import org.eclipse.jdt.internal.core.util.Util;
30
33
Lines 41-47 Link Here
41
	
44
	
42
	protected String name;
45
	protected String name;
43
	public WorkingCopyOwner owner;
46
	public WorkingCopyOwner owner;
47
	
48
	/** 
49
	 * indicates if a NoOpProblemRequestor should be used when 
50
	 *  calling getPerWorkingCopyInfo
51
	 */
52
	private boolean useNoOpProblemRequestor = false;
44
53
54
	/**
55
	 * indicates if we should treat this working copy as inconsistent
56
	 * even if there wasn't a change in the underlying buffer.
57
	 */
58
	private boolean forceInconsistent = false;
59
	
60
	
45
/**
61
/**
46
 * Constructs a handle to a compilation unit with the given name in the
62
 * Constructs a handle to a compilation unit with the given name in the
47
 * specified package for the specified owner
63
 * specified package for the specified owner
Lines 758-765 Link Here
758
 * Note: the use count of the per working copy info is NOT incremented.
774
 * Note: the use count of the per working copy info is NOT incremented.
759
 */
775
 */
760
public JavaModelManager.PerWorkingCopyInfo getPerWorkingCopyInfo() {
776
public JavaModelManager.PerWorkingCopyInfo getPerWorkingCopyInfo() {
761
	return JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(this, false/*don't create*/, false/*don't record usage*/, null/*no problem requestor needed*/);
777
	
778
	if ( useNoOpProblemRequestor )
779
		return new PerWorkingCopyInfo( this, NO_OP_PROBLEM_REQUESTOR );
780
	else
781
		return JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(this, false/*don't create*/, false/*don't record usage*/, null/*no problem requestor needed*/);
762
}
782
}
783
763
/*
784
/*
764
 * @see ICompilationUnit#getPrimary()
785
 * @see ICompilationUnit#getPrimary()
765
 */
786
 */
Lines 900-906 Link Here
900
 * @see IOpenable#isConsistent()
921
 * @see IOpenable#isConsistent()
901
 */
922
 */
902
public boolean isConsistent() {
923
public boolean isConsistent() {
903
	return JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().get(this) == null;
924
	if ( forceInconsistent )
925
		return false;
926
	else	
927
		return JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().get(this) == null;
904
}
928
}
905
/**
929
/**
906
 * 
930
 * 
Lines 1084-1091 Link Here
1084
			// either way, request denied
1108
			// either way, request denied
1085
			createAST = false;
1109
			createAST = false;
1086
	}
1110
	}
1087
	ReconcileWorkingCopyOperation op = new ReconcileWorkingCopyOperation(this, createAST, astLevel, forceProblemDetection, workingCopyOwner);
1111
	
1088
	op.runOperation(monitor);
1112
	
1113
	ReconcileWorkingCopyOperation op = null;
1114
	List l = JavaCore.getCompilationParticipants(ICompilationParticipant.POST_RECONCILE_EVENT);	
1115
	if ( l != null && l.size() > 0 ) {	
1116
		// we always need an AST to pass into compilation participants
1117
		op = new ReconcileWorkingCopyOperation(this, true /*createAST*/, AST.JLS3, forceProblemDetection, workingCopyOwner);	
1118
1119
		// TODO:  try not to use these two try-catch blocks here...
1120
		try {
1121
		    try {
1122
				useNoOpProblemRequestor = true;
1123
				forceInconsistent = ! this.isConsistent();
1124
				op.runOperation(monitor);
1125
			}
1126
			finally {
1127
				useNoOpProblemRequestor = false;
1128
			}
1129
						
1130
			Iterator it = l.iterator();
1131
			while ( it.hasNext() ) {
1132
				ICompilationParticipant p = (ICompilationParticipant)it.next();
1133
				PostReconcileCompilationEvent prce = new PostReconcileCompilationEvent( this, op.ast, getJavaProject() ); 
1134
				p.notify( prce );
1135
				// TODO: do something with the result of notify...
1136
			}
1137
1138
			// save off the original AST
1139
			org.eclipse.jdt.core.dom.CompilationUnit originalAst = op.ast;
1140
1141
			// if there were ICompilationParticipants, we will reconcile again and return the ast from the second reconcile
1142
			// this causes the client to receive an AST that is correct with respect to any changes that occurred in the 
1143
			// ast as a result of files being added by compilation participants.  This second reconcile also causes any 
1144
			// problems to be reported to the correct problemRequestor, instead of the no-op problemRequestor. 
1145
			op = new ReconcileWorkingCopyOperation(this, createAST, astLevel, forceProblemDetection, workingCopyOwner);
1146
			op.runOperation(monitor);
1147
			
1148
			// if the original AST was null, assume that the working copy was consistent.
1149
			// and return null. 
1150
			if ( originalAst == null )
1151
				return null;	
1152
		}
1153
		finally {
1154
			forceInconsistent = false;
1155
		}
1156
	}
1157
	else 
1158
	{
1159
		op = new ReconcileWorkingCopyOperation(this, createAST, astLevel, forceProblemDetection, workingCopyOwner);
1160
		op.runOperation(monitor);
1161
	}
1162
1089
	return op.ast;
1163
	return op.ast;
1090
}
1164
}
1091
1165
Lines 1162-1165 Link Here
1162
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1236
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1163
}
1237
}
1164
1238
1239
1240
1241
private final static NoOpProblemRequestor  NO_OP_PROBLEM_REQUESTOR = new NoOpProblemRequestor();
1242
private final static class NoOpProblemRequestor implements IProblemRequestor {
1243
	public void    acceptProblem(IProblem problem) { /* no-op */ }
1244
	public void    beginReporting()                { /* no-op */ }
1245
	public void    endReporting()                  { /* no-op */ }
1246
	public boolean isActive()                      { return true; } 
1247
}
1248
1165
}
1249
}
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (+115 lines)
Lines 23-28 Link Here
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
24
import org.eclipse.jdt.core.*;
24
import org.eclipse.jdt.core.*;
25
import org.eclipse.jdt.core.compiler.CharOperation;
25
import org.eclipse.jdt.core.compiler.CharOperation;
26
import org.eclipse.jdt.core.compiler.ICompilationParticipant;
26
import org.eclipse.jdt.core.compiler.IProblem;
27
import org.eclipse.jdt.core.compiler.IProblem;
27
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
28
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
28
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
29
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
Lines 105-110 Link Here
105
	public static final String FORMATTER_EXTPOINT_ID = "codeFormatter" ; //$NON-NLS-1$
106
	public static final String FORMATTER_EXTPOINT_ID = "codeFormatter" ; //$NON-NLS-1$
106
	
107
	
107
	/**
108
	/**
109
	 * Name of the extension point for contributing a compilation participant
110
	 */
111
	public static final String COMPILATION_PARTICIPANT_EXTPOINT_ID = "compilationParticipant" ; //$NON-NLS-1$
112
	
113
	/**
108
	 * Value of the content-type for Java source files
114
	 * Value of the content-type for Java source files
109
	 */
115
	 */
110
	public static final String JAVA_SOURCE_CONTENT_TYPE = JavaCore.PLUGIN_ID+".javaSource" ; //$NON-NLS-1$
116
	public static final String JAVA_SOURCE_CONTENT_TYPE = JavaCore.PLUGIN_ID+".javaSource" ; //$NON-NLS-1$
Lines 141-146 Link Here
141
	
147
	
142
	public HashSet optionNames = new HashSet(20);
148
	public HashSet optionNames = new HashSet(20);
143
149
150
	public class CompilationParticipants {
151
		
152
		/** Map<ICompilationParticipant, eventMask> registered by plugins */
153
		private Map pluginCPs;
154
		
155
		/** Map<ICompilationParticipant, eventMask> from calls to add() */
156
		private Map dynamicCPs = new HashMap();
157
		
158
		/**
159
		 * @see JavaCore#addCompilationParticipant(ICompilationParticipant, int)
160
		 */
161
		public synchronized void add(ICompilationParticipant icp, int eventMask) {
162
			dynamicCPs.put(icp, new Integer(eventMask));
163
		}
164
165
		/**
166
		 * @see JavaCore#removeCompilationParticipant(ICompilationParticipant)
167
		 */
168
		public synchronized void remove(ICompilationParticipant icp) {
169
			dynamicCPs.remove(icp);
170
		}
171
		
172
		/**
173
		 * Returns an immutable list containing the subset of registered
174
		 * listeners that have requested notification of at least one of
175
		 * the events in the flags mask.
176
		 * The first time this is called, it loads listeners from plugins,
177
		 * which may cause plugins to be loaded.  If this is called on
178
		 * multiple threads simultaneously, or if loading a plugin causes
179
		 * this to be reentered, it may return an incomplete list of listeners,
180
		 * but it is guaranteed not to crash or deadlock.
181
		 * @param eventMask an ORed combination of values from ICompilationParticipant.
182
		 * @return an immutable list of ICompilationParticipant.
183
		 */
184
		public List get(int eventMask) {
185
			initPlugins();
186
			List filteredICPs = new ArrayList();
187
			Iterator it;
188
			synchronized(this) {
189
				it = dynamicCPs.entrySet().iterator();
190
				while (it.hasNext()) {
191
					Map.Entry cp = (Map.Entry)it.next();
192
					if (0 != (((Integer)cp.getValue()).intValue() | eventMask)) {
193
						filteredICPs.add(cp.getKey());
194
					}
195
				}
196
			}
197
			it = pluginCPs.entrySet().iterator();
198
			while (it.hasNext()) {
199
				Map.Entry cp = (Map.Entry)it.next();
200
				if (0 != (((Integer)cp.getValue()).intValue() | eventMask)) {
201
					filteredICPs.add(cp.getKey());
202
				}
203
			}
204
			return Collections.unmodifiableList(filteredICPs);
205
		}
206
		
207
		private void initPlugins() {
208
			synchronized (this) {
209
				if (null != pluginCPs) {
210
					return;
211
				}
212
				pluginCPs = new HashMap();
213
			}
214
			IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(
215
					JavaCore.PLUGIN_ID, COMPILATION_PARTICIPANT_EXTPOINT_ID);
216
			if (extension == null)
217
				return;
218
			IExtension[] extensions = extension.getExtensions();
219
			for(int iExtension = 0; iExtension < extensions.length; iExtension++){
220
				// for all extensions of this point...
221
				for(int i = 0; i < extensions.length; i++){
222
					IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
223
					// for all config elements named "compilationParticipant"
224
					for(int j = 0; j < configElements.length; j++){
225
						String elementName = configElements[j].getName();
226
						if (!("compilationParticipant".equals(elementName))) { //$NON-NLS-1$ - name of configElement
227
							continue;
228
						}
229
						String eventMaskStr = configElements[j].getAttribute("eventMask"); //$NON-NLS-1$ - name of attribute
230
						try {
231
							Integer eventMask;
232
							if (null != eventMaskStr) {
233
								eventMask = Integer.decode(eventMaskStr);
234
							}
235
							else {
236
								// if mask is unspecified, send it all events
237
								eventMask = new Integer(-1); 
238
							}
239
							Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ - attribute name
240
							if (execExt instanceof ICompilationParticipant){
241
								pluginCPs.put(execExt, eventMask);
242
							}
243
						} catch(CoreException e) {
244
							// TODO: what is the right way to handle exceptions?
245
							e.printStackTrace();
246
						}
247
					}
248
				}
249
			}
250
		}
251
	}
252
	
253
	private final CompilationParticipants compilationParticipants = new CompilationParticipants();
254
	
144
	/**
255
	/**
145
	 * Returns whether the given full path (for a package) conflicts with the output location
256
	 * Returns whether the given full path (for a package) conflicts with the output location
146
	 * of the given project.
257
	 * of the given project.
Lines 856-861 Link Here
856
		}
967
		}
857
		return container;			
968
		return container;			
858
	}
969
	}
970
	
971
	public CompilationParticipants getCompilationParticipants() {
972
		return compilationParticipants;
973
	}
859
974
860
	public DeltaProcessor getDeltaProcessor() {
975
	public DeltaProcessor getDeltaProcessor() {
861
		return this.deltaState.getDeltaProcessor();
976
		return this.deltaState.getDeltaProcessor();
(-)model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java (+88 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.internal.compiler.*;
19
import org.eclipse.jdt.internal.compiler.*;
20
import org.eclipse.jdt.internal.compiler.ClassFile;
20
import org.eclipse.jdt.internal.compiler.ClassFile;
21
import org.eclipse.jdt.internal.compiler.Compiler;
21
import org.eclipse.jdt.internal.compiler.Compiler;
22
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
22
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
import org.eclipse.jdt.internal.compiler.problem.*;
24
import org.eclipse.jdt.internal.compiler.problem.*;
24
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
25
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
Lines 27-32 Link Here
27
import java.io.*;
28
import java.io.*;
28
import java.util.*;
29
import java.util.*;
29
30
31
30
/**
32
/**
31
 * The abstract superclass of Java builders.
33
 * The abstract superclass of Java builders.
32
 * Provides the building and compilation mechanism
34
 * Provides the building and compilation mechanism
Lines 210-219 Link Here
210
			System.arraycopy(units, i, additionalUnits, 0, additionalUnits.length);
212
			System.arraycopy(units, i, additionalUnits, 0, additionalUnits.length);
211
			compilingFirstGroup = false;
213
			compilingFirstGroup = false;
212
			compile(toCompile, additionalUnits);
214
			compile(toCompile, additionalUnits);
215
		}	
216
	}
217
}
218
219
220
/**
221
 *  notify the ICompilationParticipants of the pre-build event 
222
 */
223
private Set notifyCompilationParticipants(ICompilationUnit[] sourceUnits) {
224
	List cps = JavaCore
225
			.getCompilationParticipants( ICompilationParticipant.PRE_BUILD_EVENT );
226
	if ( cps.isEmpty() ) {
227
		return Collections.emptySet();
228
	}
229
230
	IFile[] files = new IFile[sourceUnits.length];
231
	for ( int i = 0; i < files.length; i++ ) {
232
		if ( sourceUnits[i] instanceof SourceFile ) {
233
			files[i] = ( ( SourceFile ) sourceUnits[i] ).getFile();
234
		} else {
235
			String fname = new String( sourceUnits[i].getFileName() );
236
			javaBuilder.javaProject.getProject().getFile( fname );
213
		}
237
		}
214
	}
238
	}
239
	PreBuildCompilationEvent pbce = new PreBuildCompilationEvent( files,
240
			javaBuilder.javaProject );
241
242
	Set newFiles = new HashSet();
243
	java.util.Iterator it = cps.iterator();
244
	while ( it.hasNext() ) {
245
		ICompilationParticipant p = ( ICompilationParticipant ) it.next();
246
247
		CompilationParticipantResult cpr = p.notify( pbce );
248
		if ( cpr instanceof PreBuildCompilationResult ) {
249
			PreBuildCompilationResult pbcr = ( PreBuildCompilationResult ) cpr;
250
251
			IFile[] f = pbcr.getNewFiles();
252
			if ( f != null ) {
253
				for ( int i = 0; i < f.length; i++ )
254
					newFiles.add( f[i] );
255
			}
256
		}
257
	}
258
	return newFiles;
259
}	
260
261
262
/** 
263
 * given a source file, determine which of the project's source folders the file lives 
264
 */
265
protected ClasspathMultiDirectory getSourceLocationForFile(IFile file) {
266
	ClasspathMultiDirectory md = null;
267
	if ( file.exists() ) {
268
		md = sourceLocations[0];
269
		if ( sourceLocations.length > 1 ) {
270
			IPath sourceFileFullPath = file.getFullPath();
271
			for ( int j = 0, m = sourceLocations.length; j < m; j++ ) {
272
				if ( sourceLocations[j].sourceFolder.getFullPath()
273
						.isPrefixOf( sourceFileFullPath ) ) {
274
					md = sourceLocations[j];
275
					if ( md.exclusionPatterns == null
276
							&& md.inclusionPatterns == null )
277
						break;
278
					if ( !Util.isExcluded( file, md.inclusionPatterns,
279
							md.exclusionPatterns ) )
280
						break;
281
				}
282
			}
283
		}
284
	}
285
	return md;
215
}
286
}
216
287
288
217
void compile(SourceFile[] units, SourceFile[] additionalUnits) {
289
void compile(SourceFile[] units, SourceFile[] additionalUnits) {
218
	if (units.length == 0) return;
290
	if (units.length == 0) return;
219
	notifier.aboutToCompile(units[0]); // just to change the message
291
	notifier.aboutToCompile(units[0]); // just to change the message
Lines 236-241 Link Here
236
	notifier.checkCancel();
308
	notifier.checkCancel();
237
	try {
309
	try {
238
		inCompiler = true;
310
		inCompiler = true;
311
		
312
		// notify compilation participants, and add any new files created
313
		// by the participants into the set of files being compiled. 
314
		Set newFiles = notifyCompilationParticipants( units );
315
		if ( newFiles != null && newFiles.size() > 0 ) {
316
				SourceFile[] newUnits = new SourceFile[units.length + newFiles.size()];
317
				System.arraycopy( units, 0, newUnits, 0, units.length );
318
				Iterator it = newFiles.iterator();
319
				int idx = units.length;
320
				while ( it.hasNext() ) {
321
					IFile f = ( IFile ) it.next();
322
					newUnits[idx++] = new SourceFile( f, getSourceLocationForFile( f ) );
323
				}
324
				units = newUnits;
325
		}
326
		
239
		compiler.compile(units);
327
		compiler.compile(units);
240
	} catch (AbortCompilation ignored) {
328
	} catch (AbortCompilation ignored) {
241
		// ignore the AbortCompilcation coming from BuildNotifier.checkCancelWithinCompiler()
329
		// ignore the AbortCompilcation coming from BuildNotifier.checkCancelWithinCompiler()
(-)model/org/eclipse/jdt/internal/core/builder/SourceFile.java (+4 lines)
Lines 89-94 Link Here
89
	return this.resource.getFullPath().toString().toCharArray(); // do not know what you want to return here
89
	return this.resource.getFullPath().toString().toCharArray(); // do not know what you want to return here
90
}
90
}
91
91
92
public IFile getFile() {
93
	return resource;
94
}
95
92
public char[] getMainTypeName() {
96
public char[] getMainTypeName() {
93
	char[] typeName = this.initialTypeName.toCharArray();
97
	char[] typeName = this.initialTypeName.toCharArray();
94
	int lastIndex = CharOperation.lastIndexOf('/', typeName);
98
	int lastIndex = CharOperation.lastIndexOf('/', typeName);
(-)model/org/eclipse/jdt/internal/core/hierarchy/HierarchyBinaryType.java (+8 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.jdt.core.Signature;
13
import org.eclipse.jdt.core.Signature;
14
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.core.compiler.CharOperation;
15
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
15
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
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.env.IBinaryNestedType;
18
import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
Lines 246-251 Link Here
246
/**
247
/**
247
 * @see org.eclipse.jdt.internal.compiler.env.IBinaryType
248
 * @see org.eclipse.jdt.internal.compiler.env.IBinaryType
248
 */
249
 */
250
public IBinaryAnnotation[] getAnnotations() {
251
	return null;
252
}
253
254
/**
255
 * @see org.eclipse.jdt.internal.compiler.env.IBinaryType
256
 */
249
public char[] sourceFileName() {
257
public char[] sourceFileName() {
250
	return null;
258
	return null;
251
}
259
}
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/AnnotationInfo.java (+345 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.internal.compiler.ast.Annotation;
15
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
16
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
17
import org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair;
18
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
19
20
public class AnnotationInfo extends ClassFileStruct implements IBinaryAnnotation 
21
{		
22
	/** The name of the annotation type */
23
	private char[] typename;
24
	/** number of bytes read */
25
	private int readOffset = 0;
26
	/** non-null to indicate taht this annontation is initialized 
27
	 *  @see #getMemberValuePairs()
28
	 */
29
	private ElementValuePairInfo[] pairs;
30
	private int[] constantPoolOffsets;
31
	private long annoTagBits = 0;
32
	/**
33
	 * @param classFileBytes
34
	 * @param offset the offset into <code>classFileBytes</code> for the 
35
	 * 		  "type_index" of the annotation attribute.
36
	 * @param populate <code>true</code> to indicate to build out the annotation structure.
37
	 */
38
	AnnotationInfo(byte[] classFileBytes, 
39
	 			   int offset, 
40
				   int[] contantPoolOffsets,
41
				   boolean runtimeVisible, 
42
				   boolean populate) 
43
	{
44
		super(classFileBytes, offset);
45
		this.constantPoolOffsets = contantPoolOffsets;		
46
		this.readOffset = 0;	
47
		if( populate ){
48
			decodeAnnotation();
49
		}
50
		else	
51
			this.readOffset = scanAnnotation(0, runtimeVisible, true);
52
	}
53
	
54
	public char[] getTypeName() {
55
		return this.typename;
56
	}
57
	
58
	public IBinaryElementValuePair[] getMemberValuePairs() {
59
		if( this.pairs == null ){
60
			initialize();
61
		}
62
		return this.pairs;
63
	}
64
	
65
	public long getStandardAnnotationTagBits(){ return this.annoTagBits; }
66
	
67
	void initialize()
68
	{
69
		if(this.pairs != null ) return;
70
		this.readOffset = 0;
71
		decodeAnnotation();
72
	}
73
	
74
	/**
75
	 * @return the length of this annotation.
76
	 */
77
	int getLength(){ return this.readOffset; }
78
	
79
	/**
80
	 * Read through this annotation in order to figure out the necessary tag bits and the length 
81
	 * of this annotation. The data structure will not be flushed out.
82
	 * 
83
	 * The tag bits are derived from the following (supported) standard annotation. 
84
	 * {@link java.lang.annotation.Documented},
85
	 * {@link java.lang.annotation.Retention},
86
	 * {@link java.lang.annotation.Target}, and
87
	 * {@link java.lang.Deprecated}
88
	 * 
89
	 * @param expectRuntimeVisibleAnno <code>true</cod> to indicate that this is a runtime-visible annotation
90
	 * @param toplevel <code>false</code> to indicate that an nested annotation is read. <code>true</code>
91
	 * 		  otherwis.e
92
	 * @return the next offset to read.
93
	 */
94
	private int scanAnnotation(int offset, boolean expectRuntimeVisibleAnno, boolean toplevel)
95
	{
96
		int curOffset = offset;
97
		int utf8Offset = this.constantPoolOffsets[u2At(offset)] - structOffset;
98
		char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
99
		if(toplevel)
100
			this.typename = typeName;
101
		int numberOfPairs = u2At(offset + 2);
102
		// u2 type_index + u2 number_member_value_pair
103
		curOffset += 4;
104
		if(expectRuntimeVisibleAnno && toplevel){	
105
			switch(typeName.length) {
106
				case 21 :
107
					if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_INHERITED)) {
108
						this.annoTagBits |= TagBits.AnnotationInherited;
109
						return curOffset;		
110
					}
111
					break;
112
				case 22 :
113
					if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_DEPRECATED)) {
114
						this.annoTagBits |= TagBits.AnnotationDeprecated;
115
						return curOffset;		
116
					}
117
					break;
118
				case 29 :
119
					if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_TARGET)) {		
120
						curOffset += 2;
121
						return readTargetValue(curOffset);
122
					}
123
					break;
124
				case 33 :
125
					if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_DOCUMENTED)) {
126
						this.annoTagBits |= TagBits.AnnotationDocumented;
127
						return curOffset;		
128
					}
129
					break;
130
				case 32 :
131
					if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTION)) {
132
						curOffset += 2;
133
						return readRetentionPolicy(curOffset);
134
					}
135
					break;
136
			}
137
		}
138
		for (int i = 0; i < numberOfPairs; i++) {
139
			// u2 member_name_index
140
			curOffset += 2;
141
			curOffset = scanElementValue(curOffset);
142
		}
143
		return curOffset;
144
	}
145
	
146
	/** 
147
	 * @param offset the offset to start reading.
148
	 * @return the next offset to read.
149
	 */
150
	private int scanElementValue(int offset) {
151
		int curOffset = offset;
152
		int tag = u1At(curOffset);
153
		curOffset++;
154
		switch(tag) {
155
			case 'B' :
156
			case 'C' :
157
			case 'D' :
158
			case 'F' :
159
			case 'I' :
160
			case 'J' :
161
			case 'S' :
162
			case 'Z' :
163
			case 's' :
164
				curOffset += 2;
165
				break;
166
			case 'e' :
167
				curOffset += 4;
168
				break;
169
			case 'c' :
170
				curOffset += 2;
171
				break;
172
			case '@' :
173
				// none of the supported standard annotation are in the nested level.				
174
				curOffset = scanAnnotation(curOffset, false, false);
175
				break;
176
			case '[' :
177
				int numberOfValues = u2At(curOffset);
178
				curOffset += 2;
179
				for (int i = 0; i < numberOfValues; i++) {					
180
					curOffset = scanElementValue(curOffset);
181
				}
182
				break;
183
			default:
184
				throw new IllegalStateException();
185
		}
186
		return curOffset;
187
	}
188
	
189
	private int readRetentionPolicy(int offset) {
190
		int curOffset = offset;
191
		int tag = u1At(curOffset);
192
		curOffset++;
193
		switch(tag) {			
194
			case 'e' :
195
				int utf8Offset = this.constantPoolOffsets[u2At(curOffset)] - structOffset;		
196
				char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
197
				curOffset += 2;
198
				utf8Offset = this.constantPoolOffsets[u2At(curOffset)]- structOffset;	
199
				char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
200
				curOffset += 2;
201
				if (typeName.length == 38 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTIONPOLICY)) 
202
					this.annoTagBits |= Annotation.getRetentionPolicy(constName);				
203
				break;
204
			case 'B' :
205
			case 'C' :
206
			case 'D' :
207
			case 'F' :
208
			case 'I' :
209
			case 'J' :
210
			case 'S' :
211
			case 'Z' :
212
			case 's' :
213
				curOffset += 2;
214
				break;			
215
			case 'c' :
216
				curOffset += 2;
217
				break;
218
			case '@' :
219
				// none of the supported standard annotation are in the nested level.
220
				curOffset = scanAnnotation(curOffset, false, false);
221
				break;
222
			case '[' :
223
				int numberOfValues = u2At(curOffset);
224
				curOffset += 2;
225
				for (int i = 0; i < numberOfValues; i++) {					
226
					curOffset = scanElementValue(curOffset);
227
				}
228
				break;
229
			default:
230
				throw new IllegalStateException();
231
		}	
232
		return curOffset;
233
	}
234
	
235
	private int readTargetValue(int offset)
236
	{
237
		int curOffset = offset;
238
		int tag = u1At(curOffset);
239
		curOffset++;
240
		switch(tag) {			
241
			case 'e' :
242
				int utf8Offset = this.constantPoolOffsets[u2At(curOffset)] - structOffset;	
243
				char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
244
				curOffset += 2;
245
				utf8Offset = this.constantPoolOffsets[u2At(curOffset)] - structOffset;	
246
				char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
247
				curOffset += 2;				
248
				if (typeName.length == 34 && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_ELEMENTTYPE)) {
249
					this.annoTagBits |= Annotation.getTargetElementType(constName);
250
				}
251
				break;				
252
				
253
			case 'B' :
254
			case 'C' :
255
			case 'D' :
256
			case 'F' :
257
			case 'I' :
258
			case 'J' :
259
			case 'S' :
260
			case 'Z' :
261
			case 's' :
262
				curOffset += 2;
263
				break;			
264
			case 'c' :
265
				curOffset += 2;
266
				break;
267
			case '@' :
268
				// none of the supported standard annotation are in the nested level.
269
				curOffset = scanAnnotation(curOffset, false, false);
270
				break;
271
			case '[' :
272
				int numberOfValues = u2At(curOffset);
273
				curOffset += 2;
274
				if (numberOfValues == 0) {
275
					this.annoTagBits |= TagBits.AnnotationTarget;
276
				} 
277
				else {
278
					for (int i = 0; i < numberOfValues; i++) {
279
						curOffset = readTargetValue(curOffset);
280
					}
281
				}
282
				break;
283
			default:
284
				throw new IllegalStateException();
285
		}		
286
		return curOffset;
287
	}
288
	
289
	/**
290
	 * Flush out the annotation data structure.
291
	 */
292
	private void decodeAnnotation()
293
	{
294
		int utf8Offset = this.constantPoolOffsets[u2At(0)] - structOffset;
295
		this.typename = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
296
		int numberOfPairs = u2At(2);
297
		// u2 type_index + u2 num_member_value_pair
298
		this.readOffset += 4;
299
		if( numberOfPairs == 0 )
300
			this.pairs = ElementValuePairInfo.NoMember;
301
		else
302
			this.pairs = new ElementValuePairInfo[numberOfPairs];	
303
		
304
		for (int i = 0; i < numberOfPairs; i++) {			
305
			this.pairs[i] = decodePair();		
306
		}
307
	}
308
309
	private ElementValuePairInfo decodePair()
310
	{
311
		// u2    member_name_index;
312
		int utf8Offset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
313
		char[] membername = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
314
		this.readOffset += 2;
315
		final ElementValueInfo elementValue = new ElementValueInfo(this.reference, this.constantPoolOffsets, 
316
														   this.readOffset + this.structOffset);
317
		final Object value = elementValue.decodeValue();
318
		this.readOffset += elementValue.getLength();
319
		return new ElementValuePairInfo(membername, value);		
320
	}
321
	
322
	protected void reset() {
323
		this.constantPoolOffsets = null;
324
		super.reset();
325
	}
326
	
327
	public String toString()
328
	{
329
		StringBuilder buffer = new StringBuilder();
330
		buffer.append('@');
331
		buffer.append(this.typename);
332
		if(this.pairs != null){			
333
			buffer.append('(');
334
			buffer.append("\n\t"); //$NON-NLS-1$
335
			for( int i=0, len = this.pairs.length; i<len; i++ ){
336
				if( i > 0 )
337
					buffer.append(",\n\t"); //$NON-NLS-1$
338
				buffer.append(this.pairs[i]);
339
			}
340
			buffer.append(')');
341
		}
342
		
343
		return buffer.toString();
344
	}
345
}
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/AnnotationMethodInfo.java (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
15
public class AnnotationMethodInfo extends MethodInfo 
16
{	
17
	private Object defaultValue = null; 
18
	AnnotationMethodInfo(byte classFileBytes[], int constantPoolOffsets[], int offset)
19
	{	
20
		super(classFileBytes, constantPoolOffsets, offset);
21
		readAttributes();
22
	}
23
	
24
	private void readAttributes()
25
	{
26
		int attributesCount = u2At(6);
27
		int readOffset = 8;		
28
		for (int i = 0; i < attributesCount; i++) {
29
			// check the name of each attribute
30
			int utf8Offset = constantPoolOffsets[u2At(readOffset)] - structOffset;
31
			char[] attributeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
32
			if (attributeName.length > 0) {
33
				switch(attributeName[0]) {
34
					case 'A' :
35
						if(CharOperation.equals(attributeName, AnnotationDefaultName)){		
36
							decodeDefaultValue(readOffset);
37
						}
38
						break;
39
				}
40
			}
41
			readOffset += (6 + u4At(readOffset + 2));
42
		}		
43
	}
44
	
45
	private void decodeDefaultValue( int offset )
46
	{
47
		// offset + 6 so the offset is at the start of the 'member_value' entry
48
		// u2 attribute_name_index + u4 attribute_length = + 6
49
		final ElementValueInfo defaultValueInfo = 
50
			new ElementValueInfo(this.reference, this.constantPoolOffsets, offset + 6 + this.structOffset );
51
		this.defaultValue = defaultValueInfo.decodeValue();
52
	}
53
	
54
	public Object getDefaultValue(){ return this.defaultValue; }
55
	
56
	public String toString()
57
	{
58
		final StringBuilder buffer = new StringBuilder();
59
		toString(buffer);
60
		if( this.defaultValue != null )
61
		{
62
			buffer.append(" default "); //$NON-NLS-1$
63
			if( this.defaultValue instanceof Object[] )
64
			{
65
				buffer.append('{');
66
				final Object[] elements = (Object[])this.defaultValue;
67
				for( int i=0, len = elements.length; i<len; i++ ){
68
					if( i > 0 )
69
						buffer.append(", "); //$NON-NLS-1$
70
					buffer.append(elements[i]);
71
				}
72
				buffer.append('}');
73
			}
74
			else
75
				buffer.append(this.defaultValue);
76
		}
77
		return buffer.toString();
78
	}
79
}
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassReference.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
import org.eclipse.jdt.internal.compiler.env.IClassReference;
14
15
public class ClassReference implements IClassReference
16
{
17
	private final char[] className;
18
	ClassReference(final char[] className)
19
	{	
20
		this.className = className;
21
	}
22
	
23
	public char[] getTypeName(){ return this.className; }
24
	public String toString()
25
	{
26
		StringBuilder buffer = new StringBuilder();
27
		buffer.append(this.className);
28
		buffer.append(".class"); //$NON-NLS-1$
29
		return buffer.toString();
30
	}
31
}
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/ElementValueInfo.java (+146 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
import org.eclipse.jdt.internal.compiler.impl.BooleanConstant;
14
import org.eclipse.jdt.internal.compiler.impl.ByteConstant;
15
import org.eclipse.jdt.internal.compiler.impl.CharConstant;
16
import org.eclipse.jdt.internal.compiler.impl.DoubleConstant;
17
import org.eclipse.jdt.internal.compiler.impl.FloatConstant;
18
import org.eclipse.jdt.internal.compiler.impl.IntConstant;
19
import org.eclipse.jdt.internal.compiler.impl.LongConstant;
20
import org.eclipse.jdt.internal.compiler.impl.ShortConstant;
21
import org.eclipse.jdt.internal.compiler.impl.StringConstant;
22
23
/**
24
 * This is a transitional object for decoding a element value of an annotation 
25
 * and default value of a annotation method. 
26
 */
27
public class ElementValueInfo extends ClassFileStruct 
28
{
29
	private int readOffset = 0;		
30
	private int[] constantPoolOffsets;
31
	private Object value = null;
32
	
33
	ElementValueInfo(final byte[] classFileBytes, 
34
						final int[] constantPoolOffsets, 
35
						final int absoluteOffset)
36
	{
37
		super(classFileBytes, absoluteOffset);			
38
		this.constantPoolOffsets = constantPoolOffsets;
39
	}
40
	
41
	/**
42
	 * @return the length of this annotation.
43
	 */
44
	int getLength(){ return this.readOffset; }
45
	
46
	Object decodeValue()
47
	{
48
		// u1 tag;
49
		int tag = u1At(this.readOffset);		
50
		this.readOffset++;
51
		int constValueOffset = -1;
52
		switch(tag) {
53
			case 'Z' : // boolean constant
54
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
55
				this.value = new BooleanConstant(i4At(constValueOffset+1) == 1);
56
				this.readOffset += 2;				
57
				break;
58
			case 'I' : // integer constant
59
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
60
				this.value = new IntConstant(i4At(constValueOffset+1));
61
				this.readOffset += 2;
62
				break;
63
			case 'C' : // char constant
64
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
65
				this.value = new CharConstant((char)i4At(constValueOffset+1));
66
				this.readOffset += 2;
67
				break;
68
			case 'B' : // byte constant
69
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
70
				this.value = new ByteConstant((byte) i4At(constValueOffset+1));
71
				this.readOffset += 2;
72
				break;
73
			case 'S' : // short constant
74
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
75
				this.value = new ShortConstant((short) i4At(constValueOffset+1));
76
				this.readOffset += 2;
77
				break;			
78
			case 'D' : // double constant
79
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
80
				this.value = new DoubleConstant(doubleAt(constValueOffset+1));
81
				this.readOffset += 2;
82
				break;
83
			case 'F' :	// float constant
84
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
85
				this.value = new FloatConstant(floatAt(constValueOffset+1));
86
				this.readOffset += 2;
87
				break;
88
			case 'J' :  // long constant
89
				constValueOffset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
90
				this.value = new LongConstant(i8At(constValueOffset+1));
91
				this.readOffset += 2;
92
				break;
93
			case 's' : // String	
94
			{
95
				int utf8Offset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
96
				this.value = new StringConstant(
97
							 	 String.valueOf(utf8At(utf8Offset + 3, u2At(utf8Offset + 1))));
98
				this.readOffset += 2;
99
				break;	
100
			}
101
			case 'e' :
102
			{
103
				int utf8Offset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
104
				char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
105
				this.readOffset += 2;
106
				utf8Offset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
107
				char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
108
				this.readOffset += 2;				
109
				this.value = new EnumReference(typeName, constName);
110
				break;
111
			}
112
			case 'c' :
113
			{
114
				int utf8Offset = this.constantPoolOffsets[u2At(this.readOffset)] - structOffset;
115
				char[] className = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
116
				this.value = new ClassReference(className);
117
				this.readOffset += 2;
118
				break;
119
			}
120
			case '@' :
121
				this.value = new AnnotationInfo(reference, this.readOffset + structOffset, this.constantPoolOffsets, false, true);
122
				this.readOffset += ((AnnotationInfo)value).getLength();
123
				break;
124
			case '[' :	
125
				int numberOfValues = u2At(this.readOffset);				
126
				this.readOffset += 2;
127
				if( numberOfValues == 0 )
128
					this.value = ElementValuePairInfo.ZeroLengthArray;
129
				else{	
130
					Object[] arrayElements = new Object[numberOfValues];
131
					this.value = arrayElements;	
132
					for (int i = 0; i < numberOfValues; i++) {
133
						final ElementValueInfo elementValue = new ElementValueInfo(this.reference, this.constantPoolOffsets, 
134
								   this.readOffset + this.structOffset);
135
						arrayElements[i] = elementValue.decodeValue();
136
						this.readOffset += elementValue.getLength();
137
					}			
138
				}		
139
				break;
140
			default:
141
				throw new IllegalStateException("Unrecognized tag " + (char)tag); //$NON-NLS-1$	
142
			
143
		}
144
		return this.value;
145
	}
146
}
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/ElementValuePairInfo.java (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
import org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair;
14
15
public class ElementValuePairInfo implements IBinaryElementValuePair 
16
{	
17
	static final ElementValuePairInfo[] NoMember = new ElementValuePairInfo[0];
18
	static final Object[] ZeroLengthArray = new Object[0];
19
	private final char[] _membername;
20
	private final Object _value;
21
	
22
	ElementValuePairInfo(char[] membername, Object value)
23
	{
24
		_membername = membername;
25
		_value = value;
26
	}
27
		
28
	public char[] getMemberName() { return _membername; }
29
30
	public Object getMemberValue() { return _value; }	
31
	
32
	public String toString()
33
	{
34
		StringBuilder buffer = new StringBuilder();
35
		buffer.append(_membername);
36
		buffer.append('=');
37
		if( _value instanceof Object[] ){
38
			final Object[] values = (Object[])_value;
39
			buffer.append('{');
40
			for( int i=0, len=values.length; i<len; i++ ){
41
				if( i > 0 )
42
					buffer.append(", ");
43
				buffer.append(values[i]);
44
			}	
45
			buffer.append('}');
46
		}
47
		else
48
			buffer.append(_value);		
49
		return buffer.toString();
50
	}
51
52
53
	
54
}
(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/EnumReference.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
import org.eclipse.jdt.internal.compiler.env.IEnumConstantReference;
14
15
/**
16
 * Represents a reference to the enum constant in a class file. 
17
 */
18
public class EnumReference implements IEnumConstantReference
19
{
20
	/** type name of the enum type */
21
	private final char[] typeName;
22
	/** name of the enum constant */
23
	private final char[] constName;
24
	
25
	EnumReference(final char[] typeName, char[] constName)
26
	{
27
		this.typeName = typeName;
28
		this.constName = constName;
29
	}
30
	
31
	public char[] getTypeName(){ return this.typeName; }
32
	public char[] getEnumConstantName(){ return this.constName; }
33
	
34
	public String toString()
35
	{
36
		StringBuilder buffer = new StringBuilder();
37
		buffer.append(this.typeName);
38
		buffer.append('.');
39
		buffer.append(this.constName);
40
		return buffer.toString();
41
	}
42
}
(-)compiler/org/eclipse/jdt/internal/compiler/env/IBinaryAnnotation.java (+21 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler.env;
2
3
4
/**
5
 * This represents class file information about an annotation instance.
6
 */
7
public interface IBinaryAnnotation	
8
{
9
	public static final IBinaryAnnotation[] NoAnnotation = new IBinaryAnnotation[0];
10
	public static final IBinaryElementValuePair[] NoMemberValuePair = new IBinaryElementValuePair[0];
11
	
12
	/**
13
	 * @return the fully qualified name of the annotation type.
14
	 */
15
	char[] getTypeName();
16
	
17
	/**
18
	 * @return the list of member value pairs of the annotation
19
	 */
20
	IBinaryElementValuePair[] getMemberValuePairs();
21
}
(-)compiler/org/eclipse/jdt/internal/compiler/env/IBinaryAnnotationMethod.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.env;
12
13
/**
14
 * Method of an annotation type; 
15
 */
16
public interface IBinaryAnnotationMethod 
17
{
18
	/**
19
	 * Return {@link org.eclipse.jdt.internal.compiler.impl.Constant} for compile-time
20
	 * constant of primitive type, as well as String literals.
21
	 * Return {@link IEnumConstantReference} if value is an enum constant
22
	 * Return {@link IBinaryAnnotation} for annotation type.
23
	 * Return {@link IClassReference} for member of type {@link java.lang.Class}.
24
	 * Return {@link Object}[] for array type.
25
	 * @return default value of this annotation method
26
	 */
27
	Object getDefaultValue();
28
}
(-)compiler/org/eclipse/jdt/internal/compiler/env/IBinaryElementValuePair.java (+23 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler.env;
2
3
4
/**
5
 * This represents the class file information about a member value pair of an annotaiton. 
6
 */
7
public interface IBinaryElementValuePair
8
{	
9
	/** @return the name of the member */
10
	char[] getMemberName();
11
	
12
	/**
13
	 * Return {@link org.eclipse.jdt.internal.compiler.impl.Constant} for compile-time
14
	 * constant of primitive type, as well as String literals.
15
	 * Return {@link IEnumConstantReference} if value is an enum constant
16
	 * Return {@link IBinaryAnnotation} for annotation type.
17
	 * Return {@link IClassReference} for member of type {@link java.lang.Class}.
18
	 * Return {@link Object}[] for array type.
19
	 * @return the value of this member value pair
20
	 */
21
	Object getMemberValue();
22
	
23
}
(-)compiler/org/eclipse/jdt/internal/compiler/env/IClassReference.java (+10 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler.env;
2
3
/**
4
 * Represents a class reference in the class file.
5
 */
6
public interface IClassReference 
7
{
8
	/** @return the name of the type reference */
9
	char[] getTypeName();
10
}
(-)compiler/org/eclipse/jdt/internal/compiler/env/IEnumConstantReference.java (+17 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler.env;
2
3
/**
4
 * Represents a reference to a enum constant in the class file 
5
 */
6
public interface IEnumConstantReference 
7
{
8
	/**
9
	 * @return name of the enum type in the class file format
10
	 */
11
	char[] getTypeName();
12
	
13
	/**
14
	 * @return the name of the enum constant reference.
15
	 */
16
	char[] getEnumConstantName();
17
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotationInstance.java (+27 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
/**
14
 * Represents JSR 175 Annotation instances in the type-system.
15
 */ 
16
public interface AnnotationInstance{
17
	
18
	/**
19
	 * @return the annotation type of this instance.
20
	 */
21
	ReferenceBinding getAnnotationType();
22
23
	/**
24
	 * @return the declared element value pairs of this instance.
25
	 */
26
	ElementValuePair[] getElementValuePairs();
27
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotationMethodBinding.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
/**
14
 * Annotation method that came from binary.
15
 * @author tyeung
16
 *
17
 */
18
public class AnnotationMethodBinding extends BinaryMethodBinding 
19
{
20
	private Object defaultValue;
21
	public AnnotationMethodBinding(int modifiers,
22
								   char[] selector, 
23
								   TypeBinding returnType, 
24
								   ReferenceBinding declaringClass,
25
								   AnnotationInstance[] methodAnnotation,
26
								   AnnotationInstance[][] parameterAnnotations,
27
								   Object defaultValue)
28
	{
29
		super(modifiers, selector, 
30
			 returnType, NoParameters, 
31
			 NoExceptions, declaringClass,
32
			 methodAnnotation, parameterAnnotations );
33
		
34
		this.defaultValue = defaultValue;
35
	}
36
	
37
	public Object getDefaultValue()
38
	{
39
		return this.defaultValue;
40
	}	
41
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryAnnotation.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
/**
14
 * JSR 175 Annotation instances that came from binary
15
 */
16
public class BinaryAnnotation implements AnnotationInstance 
17
{
18
    // At creation the type may not be fully resolved.
19
	// The type will become fully resolved when this annotation is requested.
20
	ReferenceBinding typeBinding;
21
	ElementValuePair[] pairs;	
22
	private final LookupEnvironment env;
23
	
24
	BinaryAnnotation(ReferenceBinding binding, LookupEnvironment env)
25
	{ 
26
		this.typeBinding = binding;
27
		this.pairs = null;
28
		this.env = env;		
29
	}
30
	
31
	public ReferenceBinding getAnnotationType()
32
	{
33
		// annotation type are never parameterized
34
		return BinaryTypeBinding.resolveType(this.typeBinding, this.env, false);
35
	}
36
	
37
	public ElementValuePair[] getElementValuePairs(){ return this.pairs; }
38
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryElementValuePair.java (+61 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler.lookup;
2
3
public class BinaryElementValuePair implements ElementValuePair
4
{
5
	 //The annotation that directly contains this value pair.	 
6
	private final BinaryAnnotation anno;
7
	private final char[] membername;
8
	private final Object value;
9
	
10
	BinaryElementValuePair(final BinaryAnnotation anno, final char[] membername, final Object value)
11
	{
12
		this.anno = anno;
13
		this.membername = membername;
14
		this.value = value;
15
	}
16
	
17
	public char[] getMemberName()
18
	{ return membername; }
19
	
20
	/**
21
	 * @return the method binding that defined this member value pair or null
22
	 *  	   if no such binding exists.
23
	 */
24
	public MethodBinding getMethodBinding()
25
	{
26
		final ReferenceBinding typeBinding = anno.getAnnotationType();
27
		if( typeBinding != null ){
28
			final MethodBinding[] methods = typeBinding.getMethods(this.membername);
29
			// there should be exactly one since the type is an annotation type.
30
			if( methods != null && methods.length == 1)
31
				return methods[0];
32
		}
33
		return null;
34
	}
35
	
36
	/**
37
	 * Convinence method. 
38
	 * The type will determine the type of objects returned from {@link #getValue()}
39
	 * @return the type of the member value or null if it cannot be determined
40
	 * @see #getMethodBinding()
41
	 * @see #getValue()
42
	 * 
43
	 */
44
	public TypeBinding getType()
45
	{
46
		final MethodBinding method = getMethodBinding();
47
		return method == null ? null : method.returnType;
48
	}
49
	
50
	/**
51
	 * <br><li>Return {@link TypeBinding} for member value of type {@link java.lang.Class}</li></br>
52
	 * <br><li>Return {@link org.eclipse.jdt.internal.compiler.impl.Constant} 
53
	 * for member of primitive type or String</li></br>
54
	 * <br><li>Return {@link FieldBinding} for enum constant</li></br>
55
	 * <br><li>Return {@link AnnotationInstance} for annotation instance</li></br>
56
	 * <br><li>Return <code>Object[]</code> for member value of array type.
57
	 * @return the value of this member value pair or null if the value is missing or
58
	 *         is not a compile-time constant.
59
	 */
60
	public Object getValue(){ return this.value; }
61
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryFieldBinding.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
14
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
16
public class BinaryFieldBinding extends FieldBinding
17
{
18
	private AnnotationInstance[] annotations = NoAnnotations;
19
	public BinaryFieldBinding(char[] name, 
20
							  TypeBinding type, 
21
							  int modifiers, 
22
							  ReferenceBinding declaringClass,
23
							  Constant constant,
24
							  AnnotationInstance[] annos) {
25
		super(name, type, modifiers, declaringClass, constant);		
26
		if( annos != null )
27
			this.annotations = annos;
28
	}
29
	
30
	public BinaryFieldBinding(BinaryFieldBinding initialFieldBinding, ReferenceBinding declaringClass)
31
	{
32
		super(initialFieldBinding, declaringClass);
33
		this.annotations = initialFieldBinding.annotations;
34
	}
35
	
36
	public AnnotationInstance[] getAnnotations()
37
	{
38
		return annotations;
39
	}
40
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryMethodBinding.java (+108 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
public class BinaryMethodBinding extends MethodBinding 
14
{
15
	private static final AnnotationInstance[][] NoMethodAnnotation = new AnnotationInstance[][]{ NoAnnotations };	
16
	private static final AnnotationInstance[][] NoExtendedModifiers = new AnnotationInstance[0][];
17
	
18
	/**
19
	 * In the majority of the time, there will no annotations at all.
20
	 * We will try to optimized the storage by packing both
21
	 * method and parameter annotation into one field. 
22
	 * 
23
	 * If there are no annotations and no parameter annotations, 
24
	 * this will be a zero-length array. 
25
	 * If this is an array of size 1, then method annotations are intialized and there 
26
	 * may or may not be parameter annotations. 
27
	 * If there are ever any parameter annotations, this will be an array of size > 1. 
28
	 * </code>null</code> in the array means not initialized.
29
	 * If the field is <code>null</code> this means it is not initalized at all.	 
30
	 */
31
	private AnnotationInstance[][] extendedModifiers = null;	
32
	
33
	public BinaryMethodBinding(int modifiers,
34
							   char[] selector, 
35
							   TypeBinding returnType, 
36
							   TypeBinding[] parameters, 
37
							   ReferenceBinding[] thrownExceptions, 
38
							   ReferenceBinding declaringClass,
39
							   AnnotationInstance[] methodAnnotations,
40
							   AnnotationInstance[][] parameterAnnotations)
41
	{
42
		super( modifiers, selector, returnType, parameters, thrownExceptions, declaringClass);
43
	}
44
	
45
	//constructor for creating binding representing constructor
46
	public BinaryMethodBinding(int modifiers,
47
					  		   TypeBinding[] parameters,
48
					  		   ReferenceBinding[] thrownExceptions,
49
					  		   ReferenceBinding declaringClass,
50
							   AnnotationInstance[] methodAnnotations,
51
							   AnnotationInstance[][] parameterAnnotations)
52
	{
53
		this(modifiers, TypeConstants.INIT, VoidBinding, 
54
			 parameters, thrownExceptions, declaringClass,
55
			 methodAnnotations, parameterAnnotations);
56
	}
57
	
58
	
59
	//special API used to change method declaring class for runtime visibility check
60
	public BinaryMethodBinding(BinaryMethodBinding initialMethodBinding, ReferenceBinding declaringClass) 
61
	{
62
		super(initialMethodBinding, declaringClass );
63
		this.extendedModifiers = initialMethodBinding.extendedModifiers;
64
	}
65
	
66
	void initExtendedModifiers(final AnnotationInstance[] methodAnnotations,
67
							   final AnnotationInstance[][] parameterAnnotations)
68
	{
69
		final int numMethodAnnos = methodAnnotations.length;
70
		final int numParams  = parameterAnnotations.length;		
71
		if( numMethodAnnos == 0 && numParams == 0 )
72
			this.extendedModifiers = NoExtendedModifiers;
73
		else{
74
			// not even going to create the slot if there are no parameters
75
			if( numParams == 0 )
76
				this.extendedModifiers = new AnnotationInstance[][]{methodAnnotations};
77
			else{
78
				this.extendedModifiers = new AnnotationInstance[numParams + 1][];
79
				this.extendedModifiers[0] = methodAnnotations;
80
				System.arraycopy(parameterAnnotations, 0, this.extendedModifiers, 1, numParams);
81
			}
82
		}
83
	}
84
	
85
	public AnnotationInstance[] getAnnotations()
86
	{
87
		final int len = this.extendedModifiers.length;
88
		if( len == 0 ) return NoAnnotations;
89
		else
90
			return this.extendedModifiers[0];
91
	}
92
	
93
	public AnnotationInstance[] getParameterAnnotations(final int index)
94
	{		
95
		final int numberOfParameters = this.parameters == null ? 0 : this.parameters.length;
96
		if( numberOfParameters == 0 || index < 0 || index >= numberOfParameters )
97
			throw new IllegalArgumentException("number of parameters = " + numberOfParameters + //$NON-NLS-1$ 
98
											   " index = " + index ); //$NON-NLS-1$	
99
		final int numberOfExtendedMods = this.extendedModifiers.length;
100
		// no annotations what so ever.		
101
		if( numberOfExtendedMods == 0 )
102
			return NoAnnotations;		
103
		else
104
			return this.extendedModifiers[index + 1];	
105
	}
106
	
107
	public Object getDefaultValue(){ return null; }
108
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
public interface ElementValuePair 
14
{	
15
	/**
16
	 * @return the name of the member.
17
	 */
18
	
19
	char[] getMemberName();
20
	/**
21
	 * @return the method binding that defined this member value pair or null
22
	 *  	   if no such binding exists.
23
	 */
24
	MethodBinding getMethodBinding();	
25
	
26
	/**
27
	 * Convinence method. 
28
	 * The type will determine the type of objects returned from {@link #getValue()}
29
	 * @return the type of the member value or null if it cannot be determined
30
	 * @see #getMethodBinding()
31
	 * @see #getValue()
32
	 * 
33
	 */
34
	TypeBinding getType();
35
36
	/**
37
	 * <br><li>Return {@link TypeBinding} for member value of type {@link java.lang.Class}</li></br>
38
	 * <br><li>Return {@link org.eclipse.jdt.internal.compiler.impl.Constant} 
39
	 * for member of primitive type or String</li></br>
40
	 * <br><li>Return {@link FieldBinding} for enum constant</li></br>
41
	 * <br><li>Return {@link AnnotationInstance} for annotation instance</li></br>
42
	 * <br><li>Return <code>Object[]</code> for member value of array type.
43
	 * @return the value of this member value pair or null if the value is missing or
44
	 *         is not a compile-time constant.
45
	 */
46
	Object getValue();
47
	
48
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceAnnotation.java (+36 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler.lookup;
2
3
import org.eclipse.jdt.internal.compiler.ast.Annotation;
4
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
5
6
/**
7
 * Annotation that came from source.
8
 * @author tyeung
9
 *
10
 */
11
public class SourceAnnotation implements AnnotationInstance, TypeConstants
12
{
13
	private final Annotation astAnnotation;
14
	private final ElementValuePair[] pairs;
15
	
16
	public SourceAnnotation(Annotation astAnnotation)
17
	{
18
		this.astAnnotation = astAnnotation;
19
		final MemberValuePair[] astPairs = astAnnotation.memberValuePairs();
20
		int numberOfPairs = astPairs == null ? 0 : astPairs.length;
21
		if( numberOfPairs == 0 )
22
			this.pairs = NoElementValuePairs;
23
		else{
24
			this.pairs = new SourceElementValuePair[numberOfPairs];
25
			for( int i=0; i<numberOfPairs; i++ ){
26
				this.pairs[i] = new SourceElementValuePair(astPairs[i]);
27
			}
28
		}	
29
	}
30
	
31
	public ReferenceBinding getAnnotationType() {	
32
		return (ReferenceBinding)this.astAnnotation.resolvedType;
33
	}
34
	
35
	public ElementValuePair[] getElementValuePairs() { return this.pairs; }
36
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceElementValuePair.java (+68 lines)
Added Link Here
1
package org.eclipse.jdt.internal.compiler.lookup;
2
3
import org.eclipse.jdt.internal.compiler.ast.Annotation;
4
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
5
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
6
import org.eclipse.jdt.internal.compiler.ast.Expression;
7
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
8
import org.eclipse.jdt.internal.compiler.impl.Constant;
9
10
public class SourceElementValuePair implements ElementValuePair 
11
{
12
	private final MemberValuePair astPair;
13
	private Object value = null;
14
	
15
	SourceElementValuePair(final MemberValuePair pair)
16
	{
17
		this.astPair = pair;
18
	}
19
	
20
	public char[] getMemberName()
21
	{ return this.astPair.name; }
22
	
23
	public MethodBinding getMethodBinding() {
24
		return this.astPair.binding;
25
	}
26
	
27
	public TypeBinding getType() {
28
		if(this.astPair.binding == null) return null;
29
		return this.astPair.binding.returnType;
30
	}
31
	
32
	public Object getValue() {
33
		if( this.value != null ) return this.value;
34
		
35
		final Expression expression = this.astPair.value;
36
		this.value = getValue(expression);
37
		return this.value;
38
	}
39
	
40
	static Object getValue(Expression expression)
41
	{
42
		if( expression == null ) return null;
43
		Constant constant = expression.constant;
44
		// literals would hit this case.
45
		if( constant != null ) return constant;
46
			
47
		if( expression instanceof Annotation )
48
			return new SourceAnnotation( (Annotation)expression );            
49
50
        else if( expression instanceof ArrayInitializer )
51
        {
52
            final Expression[] exprs = ((ArrayInitializer)expression).expressions;
53
			int len = exprs == null ? 0 : exprs.length;
54
			final Object[] values = new Object[len];
55
			for( int i=0; i<len; i++ )
56
				values[i] = getValue(exprs[i]);
57
			return values;
58
        }
59
        else if( expression instanceof ClassLiteralAccess )
60
        {
61
            final ClassLiteralAccess classLiteral = (ClassLiteralAccess)expression;
62
			return classLiteral.targetType;            
63
        }        
64
        // something that isn't a compile time constant.
65
        else
66
            return null;
67
	}
68
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceFieldBinding.java (+64 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
import org.eclipse.jdt.internal.compiler.ast.Annotation;
14
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16
import org.eclipse.jdt.internal.compiler.impl.Constant;
17
18
public class SourceFieldBinding extends FieldBinding 
19
{
20
	public SourceFieldBinding(char[] name, 
21
							  TypeBinding type, 
22
							  int modifiers, 
23
							  ReferenceBinding declaringClass,
24
							  Constant constant){
25
		super(name, type, modifiers, declaringClass, constant);
26
	}
27
	
28
	public SourceFieldBinding(FieldDeclaration field, 
29
							  TypeBinding type, 
30
							  int modifiers, 
31
							  ReferenceBinding declaringClass) {
32
		this(field.name, type, modifiers, declaringClass, null);
33
		field.binding = this; // record binding in declaration
34
	}
35
	
36
	public SourceFieldBinding(SourceFieldBinding initialFieldBinding, ReferenceBinding declaringClass)
37
	{
38
		super(initialFieldBinding, declaringClass);
39
	}
40
	
41
	public AnnotationInstance[] getAnnotations() { 	
42
		// make sure we check the annotations for problems
43
		getAnnotationTagBits();				
44
		AnnotationInstance[] result = NoAnnotations;
45
		// length field of an array don't have a declaring class.
46
		if( this.declaringClass != null ){				
47
			TypeDeclaration typeDecl = ((SourceTypeBinding)this.declaringClass).scope.referenceContext;
48
			FieldDeclaration fieldDecl = typeDecl.declarationOf(this);
49
			
50
			if (fieldDecl != null){
51
				final Annotation[] fieldAnnos = fieldDecl.annotations;
52
				final int len = fieldAnnos == null ? 0 : fieldAnnos.length;
53
				if( len > 0 )
54
				{
55
					result = new AnnotationInstance[len];
56
					for( int i = 0; i < len; i++ ){
57
						result[i] = fieldAnnos[i].compilerAnnotation;
58
					}
59
				}
60
			}
61
		}
62
		return result;
63
	}
64
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceMethodBinding.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
13
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
14
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.Annotation;
16
import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.Argument;
18
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
19
20
public class SourceMethodBinding extends MethodBinding 
21
{
22
	public SourceMethodBinding(int modifiers,
23
							   char[] selector, 
24
							   TypeBinding returnType, 
25
							   TypeBinding[] parameters, 
26
							   ReferenceBinding[] thrownExceptions, 
27
							   ReferenceBinding declaringClass)
28
	{
29
		super( modifiers, selector, returnType, parameters, thrownExceptions, declaringClass);
30
	}
31
32
	//constructor for creating binding representing constructor
33
	public SourceMethodBinding(int modifiers,
34
					  		   TypeBinding[] parameters,
35
					  		   ReferenceBinding[] thrownExceptions,
36
					  		   ReferenceBinding declaringClass)
37
	{
38
		this(modifiers, TypeConstants.INIT, VoidBinding, parameters, thrownExceptions, declaringClass);
39
	}
40
41
42
	//special API used to change method declaring class for runtime visibility check
43
	public SourceMethodBinding(SourceMethodBinding initialMethodBinding, ReferenceBinding declaringClass) 
44
	{
45
		super(initialMethodBinding, declaringClass );
46
	}
47
	
48
	public AnnotationInstance[] getAnnotations() 
49
	{	
50
		// make sure they are checked for problems/
51
		// this call will also initialize the 'compilerAnnotation' field.
52
		getAnnotationTagBits();
53
		TypeDeclaration typeDecl = ((SourceTypeBinding)declaringClass).scope.referenceContext;		
54
		AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(this);
55
		AnnotationInstance[] methodAnno = NoAnnotations;				
56
		if (methodDecl != null){
57
			final int len = methodDecl.annotations == null ? 0 : methodDecl.annotations.length;
58
			if( len > 0 ){
59
				methodAnno = new AnnotationInstance[len];
60
				for( int i=0; i<len; i++ ){
61
					methodAnno[i] = methodDecl.annotations[i].compilerAnnotation;
62
				}
63
			}			
64
		}		
65
		return methodAnno;
66
	}
67
	
68
	public AnnotationInstance[] getParameterAnnotations(final int index)
69
	{	
70
		TypeDeclaration typeDecl = ((SourceTypeBinding)this.declaringClass).scope.referenceContext;
71
		AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(this);
72
		if(methodDecl != null ){
73
			final Argument[] args = methodDecl.arguments;
74
			final int numArgs = args == null ? 0 : args.length;
75
			if( numArgs == 0 || index < 0 || index >= numArgs )
76
				throw new IllegalArgumentException("number of parameters = " + numArgs + //$NON-NLS-1$ 
77
						   						   " index = " + index ); //$NON-NLS-1$	
78
			final Argument arg = args[index];
79
			final Annotation[] argAnnos = arg.annotations;
80
			final int numAnnotations = argAnnos == null ? 0 : argAnnos.length;
81
			AnnotationInstance[] result = NoAnnotations;
82
			if( numAnnotations > 0 ){
83
				result = new SourceAnnotation[numAnnotations];
84
				// check for errors
85
				ASTNode.resolveAnnotations(methodDecl.scope, argAnnos, this);
86
				for( int j=0; j<numAnnotations; j++ ){
87
					result[j] = argAnnos[j].compilerAnnotation;
88
				}
89
			}	
90
		
91
			return result;
92
		}
93
		
94
		return NoAnnotations;
95
	}
96
	
97
	public Object getDefaultValue()
98
	{
99
		TypeDeclaration typeDecl = ((SourceTypeBinding)this.declaringClass).scope.referenceContext;
100
		final AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(this);
101
		if( methodDecl instanceof AnnotationMethodDeclaration){
102
			return SourceElementValuePair.getValue(((AnnotationMethodDeclaration)methodDecl).defaultValue);
103
		}
104
		return null;
105
	}
106
}
(-)dom/org/eclipse/jdt/core/dom/AnnotationInstance.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
public class AnnotationInstance implements IAnnotationInstance 
14
{	
15
	static final AnnotationInstance[] NoAnnotations = new AnnotationInstance[0];
16
	private final org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance internalAnnotation;
17
	private final BindingResolver bindingResolver;
18
	
19
	AnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance anno, 
20
	  				   BindingResolver resolver )
21
	{
22
		internalAnnotation = anno;
23
		bindingResolver = resolver;
24
	}
25
	
26
	public ITypeBinding getAnnotationType() {
27
		final ITypeBinding binding = 
28
			this.bindingResolver.getTypeBinding(this.internalAnnotation.getAnnotationType());
29
		return binding.isAnnotation() ? binding : null;
30
	}
31
	
32
	public IElementValuePair[] getDeclaredElementValuePairs() {
33
		final org.eclipse.jdt.internal.compiler.lookup.ElementValuePair[] internalPair =
34
			this.internalAnnotation.getElementValuePairs();
35
		final int len = internalPair.length;
36
		IElementValuePair[] pairs = ElementValuePair.NoPair;
37
		for( int i=0; i<len; i++ ){
38
			pairs[i] = new ElementValuePair(internalPair[i],this.bindingResolver);
39
		}
40
		return pairs;
41
	}
42
}
(-)dom/org/eclipse/jdt/core/dom/ElementValuePair.java (+113 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
import org.eclipse.jdt.internal.compiler.impl.Constant;
14
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
15
16
public class ElementValuePair implements IElementValuePair
17
{	
18
	static final ElementValuePair[] NoPair = new ElementValuePair[0]; 
19
	private static final Object NoValue = new Object();
20
	private final org.eclipse.jdt.internal.compiler.lookup.ElementValuePair internalPair;
21
	private Object value = null; 
22
	private final BindingResolver bindingResolver;
23
	
24
	ElementValuePair(final org.eclipse.jdt.internal.compiler.lookup.ElementValuePair pair, 
25
					 BindingResolver resolver)
26
	{	
27
		this.internalPair = pair;
28
		this.bindingResolver = resolver;		
29
	}
30
	
31
	private void init()
32
	{
33
		final org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = this.internalPair.getType();
34
		this.value =  buildDOMValue(this.internalPair.getValue(), type, this.bindingResolver);
35
		if( this.value == null )
36
			this.value = NoValue;
37
	}
38
	
39
	static Object buildDOMValue(final Object internalObject, 
40
			  				    org.eclipse.jdt.internal.compiler.lookup.TypeBinding type,
41
			  				    BindingResolver resolver)
42
	{
43
		if( internalObject == null || type == null ) return null;
44
		switch(type.id)
45
		{
46
		case TypeIds.T_boolean:
47
			return new Boolean( ((Constant)internalObject).booleanValue() );			
48
		case TypeIds.T_byte:
49
			return new Byte( ((Constant)internalObject).byteValue() );			
50
		case TypeIds.T_char:
51
			return new Character( ((Constant)internalObject).charValue() );
52
		case TypeIds.T_double:
53
			return new Double( ((Constant)internalObject).doubleValue() );			
54
		case TypeIds.T_float:
55
			return new Float( ((Constant)internalObject).floatValue() );
56
		case TypeIds.T_int:
57
			return new Integer( ((Constant)internalObject).intValue() );			
58
		case TypeIds.T_long:
59
			return new Long( ((Constant)internalObject).longValue() );			
60
		case TypeIds.T_short:
61
			return new Short( ((Constant)internalObject).shortValue() );
62
		case TypeIds.T_JavaLangString:
63
			return internalObject;
64
		case TypeIds.T_JavaLangClass:
65
			return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)internalObject);
66
		}	
67
		
68
		if( type.isAnnotationType() ){
69
			return new AnnotationInstance(
70
					(org.eclipse.jdt.internal.compiler.lookup.AnnotationInstance)internalObject, 
71
					resolver);
72
		}
73
		else if( type.isEnum() ){
74
			return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)internalObject);
75
		}
76
		else if( type.isArrayType() ){
77
			final Object[] iElements = (Object[])internalObject;
78
			final int len = iElements.length;
79
			Object[] values = null;
80
			if( len > 0){
81
				final org.eclipse.jdt.internal.compiler.lookup.TypeBinding elementType =
82
					((org.eclipse.jdt.internal.compiler.lookup.ArrayBinding)type).leafComponentType;
83
				values = new Object[len];
84
				for( int i=0; i<len; i++ ){
85
					values[i] = buildDOMValue(iElements[i], elementType, resolver);
86
				}
87
			}
88
		}
89
		throw new IllegalStateException(); // should never get here.		
90
	}
91
	
92
	public String getName() {
93
		final char[] membername = this.internalPair.getMemberName();
94
		return membername == null ? null : new String(membername);
95
	}
96
	
97
	public IMethodBinding getMethodBinding() {
98
		return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding());
99
	}
100
	
101
	public ITypeBinding getElementType() {
102
		final IMethodBinding methodBinding = getMethodBinding();
103
		if( methodBinding != null )
104
			return methodBinding.getReturnType();
105
		return null;
106
	}
107
	
108
	public Object getElementValue() {
109
		if( value == null )
110
			init();
111
		return value == NoValue ? null : this.value;
112
	}	
113
}
(-)dom/org/eclipse/jdt/core/dom/IAnnotationInstance.java (+29 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
/**
14
 * Represents an instance of JSR 175 Annotation.
15
 */
16
public interface IAnnotationInstance 
17
{
18
	/**
19
	 * Type of the annotation, which will always
20
	 * return <code>true</code>	to <code>ITypeBinding.isAnnotation()</code>
21
	 * @return the type of the annotation.
22
	 */
23
	ITypeBinding getAnnotationType();
24
	
25
	/**
26
	 * @return the array of declared element value pair of the annotation.
27
	 */
28
	IElementValuePair[] getDeclaredElementValuePairs();
29
}
(-)dom/org/eclipse/jdt/core/dom/IElementValuePair.java (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
/**
14
 * Represents an element value pair of an 175 Annotation instance.
15
 */
16
public interface IElementValuePair 
17
{
18
	/**
19
	 * @return the name of the member
20
	 */
21
	public String getName();
22
	
23
	/**
24
	 * @return the method binding that defines this element value pair.
25
	 */
26
	public IMethodBinding getMethodBinding();
27
	
28
	/**
29
	 * This will determine the type of object returned in the {@link #getElementValue()}
30
	 * @return the type of the element value.
31
	 * 
32
	 */
33
	public ITypeBinding getElementType();
34
	
35
	/**
36
	 * If {@link #getElementType()} returns a primitive type, the result is the box 
37
	 * equivalent. (i.e. <code>Integer</code> for type "int").
38
	 * Return <code>String</code> if {@link #getElementType()} returns type <code>String</code>
39
	 * Return {@link ITypeBinding} if {@link #getElementType()} returns type <code>Class</code>
40
	 * Return {@link IVariableBinding} if {@link #getElementType()} returns an enum type.
41
	 * Return {@link IAnnotationInstance} if {@link #getElementType()} returns an annotation type.
42
	 * Return an <code>Object</code> array if {@link #getElementType()} returns an array type. 
43
	 * 	
44
	 * @return the compile-time constant of this element or null if none exists.
45
	 *         Return null if bindings are not requested when the DOM/AST is built.
46
	 */
47
	public Object getElementValue();
48
	
49
}
(-)model/org/eclipse/jdt/core/compiler/CompilationParticipantEvent.java (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.jdt.core.IJavaProject;
17
18
/**
19
 * Generic base class for an event passed into ICompilationParticipant's notify() method.  
20
 * This is subclassed to provide event-specific return information.
21
 * 
22
 * @see ICompilationParticipant#notify(CompilationParticipantEvent)
23
 * @since 3.2
24
 */
25
public  class CompilationParticipantEvent {
26
27
	/** 
28
	 * Construct a new CompilationParticipantEvent for the specified IJavaProject
29
	 * @param jp The IJavaProject that this compilation event is occurring on
30
	 */
31
	public CompilationParticipantEvent( IJavaProject jp)
32
	{
33
		_javaProject = jp;
34
	}
35
36
	/**
37
	 * @return an integer flag indicating the kind of event.  One of the *_EVENT 
38
	 * constants in ICompilationParticipant
39
	 * @see ICompilationParticipant#GENERIC_EVENT
40
	 */
41
	public int           getKind()              { return ICompilationParticipant.GENERIC_EVENT; }
42
	
43
	/**
44
	 * @return the IProject for this event
45
	 */
46
	public IProject      getProject()           { return _javaProject.getProject(); }
47
48
	/**
49
	 * @return the IJavaProject for this event
50
	 */
51
	public IJavaProject  getJavaProject()       { return _javaProject; }
52
	
53
	private IJavaProject _javaProject;
54
}
(-)model/org/eclipse/jdt/core/compiler/CompilationParticipantResult.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
/**
16
 * A generic result object returned from ICompilationParticipant#notify.  This is subclassed
17
 * to provide event-specific return information.
18
 * 
19
 * @see ICompilationParticipant#notify(CompilationParticipantEvent)
20
 * @since 3.2
21
 */
22
public class CompilationParticipantResult {
23
24
	/**
25
	 * @return an integer flag indicating the kind of event this is a result for.  
26
	 * One of the *_EVENT constants in ICompilationParticipant.
27
	 * @see ICompilationParticipant#GENERIC_EVENT
28
	 */
29
	public int getKind() { return ICompilationParticipant.GENERIC_EVENT; }
30
	
31
}
(-)model/org/eclipse/jdt/core/compiler/ICompilationParticipant.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
/**
16
 * Interface to extend when for a client that wants to participate in the compilation process
17
 */
18
public interface ICompilationParticipant {
19
	
20
	public CompilationParticipantResult notify( CompilationParticipantEvent e );
21
22
	
23
	/** a flag indicating a generic event */
24
	public static final int GENERIC_EVENT        = 1;
25
	/** a flag indicating an event fired after reconcile */
26
	public static final int POST_RECONCILE_EVENT = 2;
27
	/** a flag indicating an event fired before a build */
28
	public static final int PRE_BUILD_EVENT      = 4;
29
	/** a flag indicating an event fired after a build */
30
	public static final int POST_BUILD_EVENT     = 8;
31
}
(-)model/org/eclipse/jdt/core/compiler/PostBuildCompilationEvent.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
import org.eclipse.jdt.core.IJavaProject;
16
17
/**
18
 * An event class passed into ICompilationParticipant's notify() method after a build
19
 * has completed.
20
 * 
21
 * @see ICompilationParticipant#notify(CompilationParticipantEvent)
22
 * @since 3.2
23
 */
24
public class PostBuildCompilationEvent extends CompilationParticipantEvent {
25
26
	PostBuildCompilationEvent( IJavaProject jp )
27
	{
28
		super( jp );
29
	}
30
	
31
	/**
32
	 * @return an integer flag indicating that this is a post-build event.
33
	 * @see ICompilationParticipant#POST_BUILD_EVENT
34
	 * @see CompilationParticipantEvent#getKind()
35
	 */
36
	public final int getKind() { return ICompilationParticipant.POST_BUILD_EVENT; }
37
}
(-)model/org/eclipse/jdt/core/compiler/PostBuildCompilationResult.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
/**
16
 * An result class used as a return value from ICompilationParticipant's notify() method 
17
 * when responding to a post-build event.
18
 * 
19
 * @see ICompilationParticipant#notify(CompilationParticipantEvent)
20
 * @since 3.2
21
 */
22
public class PostBuildCompilationResult extends CompilationParticipantResult {
23
24
	/**
25
	 * @return an integer flag indicating that this is result for a post-build event.
26
	 * @see ICompilationParticipant#POST_BUILD_EVENT
27
	 * @see CompilationParticipantEvent#getKind()
28
	 */
29
	public final int getKind() { return ICompilationParticipant.POST_BUILD_EVENT; }
30
}
(-)model/org/eclipse/jdt/core/compiler/PostReconcileCompilationEvent.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
import org.eclipse.jdt.core.ICompilationUnit;
16
import org.eclipse.jdt.core.IJavaProject;
17
import org.eclipse.jdt.core.dom.CompilationUnit;
18
19
/**
20
 * An event class passed into ICompilationParticipant's notify() method after a reconcile
21
 * has completed.
22
 * 
23
 *  @see ICompilationParticipant#notify(CompilationParticipantEvent)
24
 *  @since 3.2
25
 */
26
public class PostReconcileCompilationEvent extends CompilationParticipantEvent {
27
28
	/**
29
	 * constructs a new PostReconcileCompilationEvent
30
	 * 
31
	 * @param cu - the ICompilationUnit that was just reconciled
32
	 * @param ast - the AST for for ICompilationUnit that was just reconciled
33
	 * @param jp - the java project for the ICompilationUnit that was reconciled
34
	 */
35
	public PostReconcileCompilationEvent( ICompilationUnit cu, CompilationUnit ast, IJavaProject jp )
36
	{
37
		super( jp );
38
		_compilationUnit = cu;
39
		_ast = ast;
40
	}
41
	
42
	/** @return the AST for the ICompilationUnit that was just reconciled */
43
	public CompilationUnit getAst() { return _ast; }
44
	
45
	/** @return the ICompilationUnit that was just reconciled */
46
	public ICompilationUnit getCompilationUnit() { return _compilationUnit; }
47
	
48
	/**
49
	 * @return an integer flag indicating that this is a post-reconcile event.
50
	 * @see ICompilationParticipant#POST_RECONCILE_EVENT
51
	 * @see CompilationParticipantEvent#getKind()
52
	 */
53
	public final int getKind() { return ICompilationParticipant.POST_RECONCILE_EVENT; }
54
55
	private ICompilationUnit _compilationUnit;
56
	private CompilationUnit _ast;
57
	
58
}
(-)model/org/eclipse/jdt/core/compiler/PostReconcileCompilationResult.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
/**
16
 * An result class used as a return value from ICompilationParticipant's notify() method 
17
 * when responding to a post-reconcile event.
18
 * 
19
 * @see ICompilationParticipant#notify(CompilationParticipantEvent)
20
 * @since 3.2
21
 */
22
public class PostReconcileCompilationResult extends CompilationParticipantResult {
23
24
	/**
25
	 * @return an integer flag indicating that this is result for a post-reconcile event.
26
	 * @see ICompilationParticipant#POST_RECONCILE_EVENT
27
	 * @see CompilationParticipantEvent#getKind()
28
	 */
29
	public final int getKind() { return ICompilationParticipant.POST_RECONCILE_EVENT; }
30
31
}
(-)model/org/eclipse/jdt/core/compiler/PreBuildCompilationEvent.java (+50 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.jdt.core.IJavaProject;
17
18
/**
19
 * An event class passed into ICompilationParticipant's notify() method before a build
20
 * has completed.
21
 * 
22
 * @see ICompilationParticipant#notify(CompilationParticipantEvent)
23
 * @since 3.2
24
 */
25
public class PreBuildCompilationEvent extends CompilationParticipantEvent {
26
	
27
	/**
28
	 * @param files - IFile[] of the files about to be compiled
29
	 * @param jp - the IJavaProject for the IFiles[] being compiled
30
	 */
31
	public PreBuildCompilationEvent( IFile[] files, IJavaProject jp ) 
32
	{ 
33
		super( jp );
34
		_files = files;
35
	}
36
	
37
	/**
38
	 * @return -  IFile[] containing the files about to be compiled
39
	 */
40
	public IFile[] getFiles()  { return _files; }
41
	
42
	/**
43
	 * @return an integer flag indicating that this is a pre-build event.
44
	 * @see ICompilationParticipant#PRE_BUILD_EVENT
45
	 * @see CompilationParticipantEvent#getKind()
46
	 */
47
	public final int getKind() { return ICompilationParticipant.PRE_BUILD_EVENT; }
48
49
	private IFile[] _files;
50
}
(-)model/org/eclipse/jdt/core/compiler/PreBuildCompilationResult.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc. 
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
 *    mkaufman@bea.com - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.core.compiler;
14
15
import java.util.Map;
16
17
import org.eclipse.core.resources.IFile;
18
19
/**
20
 * An result class used as a return value from ICompilationParticipant's notify() method 
21
 * when responding to a pre-build event.
22
 * 
23
 * @see ICompilationParticipant#notify(CompilationParticipantEvent)
24
 * @since 3.2
25
 */
26
public class PreBuildCompilationResult extends CompilationParticipantResult {
27
28
	/**
29
	 * Construct a new PreBuildCompilationResult.  
30
	 * 
31
	 * @param files  - array of newly generated files that need to be inserted into
32
	 *                 the compilation loop
33
	 * @param newDependencyInfo - Map<IFile, Set<String>> where each entry in the map
34
	 *        is the set of fully-qualified type names which are new dependencies 
35
	 *        for the IFile.  The JDT will record these new dependencies in its depdency
36
	 *        matrix. 
37
	 */
38
	public PreBuildCompilationResult( IFile[] files, Map newDependencyInfo )
39
	{
40
		_files = files;
41
		_newDependencyInfo = newDependencyInfo;
42
	}
43
	
44
	/** 
45
	 * 
46
	 * @return IFile[] that is the set of new files to be added into the compilation
47
	 * set.
48
	 */
49
	public IFile[] getNewFiles() { return _files; }
50
	
51
	/**
52
	 * 
53
	 * @return Map<IFile, Set<String>> that maps IFile to the fully-qualified type
54
	 * names of any new dependencies that need to be added into the JDT's dependency
55
	 * matrix.
56
	 */
57
	public Map     getNewDependencies() { return _newDependencyInfo; }
58
	
59
	/**
60
	 * @return an integer flag indicating that this is result for a pre-build event.
61
	 * @see ICompilationParticipant#PRE_BUILD_EVENT
62
	 * @see CompilationParticipantEvent#getKind()
63
	 */
64
	public final int getKind() { return ICompilationParticipant.PRE_BUILD_EVENT; }
65
	
66
	private IFile[] _files;
67
	private Map     _newDependencyInfo;
68
69
}

Return to bug 90344