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

(-).classpath (-1 / +1 lines)
Lines 9-15 Link Here
9
	<classpathentry kind="src" path="formatter"/>
9
	<classpathentry kind="src" path="formatter"/>
10
	<classpathentry kind="src" path="model"/>
10
	<classpathentry kind="src" path="model"/>
11
	<classpathentry kind="src" path="search"/>
11
	<classpathentry kind="src" path="search"/>
12
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins" nonaccessible="**/internal/"/>
12
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
13
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
13
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
14
	<classpathentry kind="output" path="bin"/>
14
	<classpathentry kind="output" path="bin"/>
15
</classpath>
15
</classpath>
(-)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/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(StringBuffer 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 StringBuffer buffer = new StringBuffer();
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/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 IAnnotationInstance[] 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 IAnnotationInstance[] 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 IAnnotationInstance[] createAnnotations(IBinaryAnnotation[] annotationInfos ){
282
	
283
	IAnnotationInstance[] 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 IElementValuePair[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
				IAnnotationInstance[] 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
	IAnnotationInstance[][] 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 IAnnotationInstance[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 IAnnotationInstance[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 IAnnotationInstance[] 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/FieldBinding.java (-2 / +28 lines)
Lines 12-23 Link Here
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.internal.compiler.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 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
Lines 279-282 Link Here
279
	}
281
	}
280
	return null;		
282
	return null;		
281
}
283
}
284
285
public IAnnotationInstance[] getAnnotations() { 	
286
	// make sure we check the annotations for problems
287
	getAnnotationTagBits();				
288
	IAnnotationInstance[] result = NoAnnotations;
289
	// length field of an array don't have a declaring class.
290
	if( this.declaringClass != null && !this.declaringClass.isBinaryBinding() ){				
291
		TypeDeclaration typeDecl = ((SourceTypeBinding)this.declaringClass).scope.referenceContext;
292
		FieldDeclaration fieldDecl = typeDecl.declarationOf(this);
293
		
294
		if (fieldDecl != null){
295
			final Annotation[] fieldAnnos = fieldDecl.annotations;
296
			final int len = fieldAnnos == null ? 0 : fieldAnnos.length;
297
			if( len > 0 )
298
			{
299
				result = new IAnnotationInstance[len];
300
				for( int i = 0; i < len; i++ ){
301
					result[i] = fieldAnnos[i].compilerAnnotation;
302
				}
303
			}
304
		}
305
	}
306
	return result;
307
}
282
}
308
}
(-)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 IAnnotationInstance[] 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
			IAnnotationInstance[] 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 (+85 lines)
Lines 13-18 Link Here
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.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.Annotation;
17
import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration;
18
import org.eclipse.jdt.internal.compiler.ast.Argument;
16
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
19
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
20
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
18
21
Lines 380-385 Link Here
380
	return originalMethod.tagBits;
383
	return originalMethod.tagBits;
381
}
384
}
382
385
386
/**
387
 * @return the annotations annotating this method.
388
 *         Return a zero-length array if none is found.
389
 */
390
public IAnnotationInstance[] getAnnotations() 
391
{	
392
	// make sure they are checked for problems/
393
	// this call will also initialize the 'compilerAnnotation' field.
394
	getAnnotationTagBits();
395
	IAnnotationInstance[] methodAnno = NoAnnotations;	
396
	if(this.declaringClass != null && this.declaringClass instanceof SourceTypeBinding )
397
	{
398
		TypeDeclaration typeDecl = ((SourceTypeBinding)declaringClass).scope.referenceContext;		
399
		AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(this);
400
					
401
		if (methodDecl != null){
402
			final int len = methodDecl.annotations == null ? 0 : methodDecl.annotations.length;
403
			if( len > 0 ){
404
				methodAnno = new IAnnotationInstance[len];
405
				for( int i=0; i<len; i++ ){
406
					methodAnno[i] = methodDecl.annotations[i].compilerAnnotation;
407
				}
408
			}			
409
		}		
410
	}
411
	return methodAnno;
412
}
413
414
/**
415
 * @param index the index of the parameter of interest
416
 * @return the annotations on the <code>index</code>th parameter
417
 * @throws ArrayIndexOutOfBoundsException when <code>index</code> is not valid 
418
 */
419
public IAnnotationInstance[] getParameterAnnotations(final int index)
420
{	
421
	IAnnotationInstance[] result = NoAnnotations;
422
	if(this.declaringClass != null && this.declaringClass instanceof SourceTypeBinding )
423
	{
424
		TypeDeclaration typeDecl = ((SourceTypeBinding)this.declaringClass).scope.referenceContext;
425
		AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(this);
426
		if(methodDecl != null ){
427
			final Argument[] args = methodDecl.arguments;
428
			final int numArgs = args == null ? 0 : args.length;
429
			if( numArgs == 0 || index < 0 || index >= numArgs )
430
				throw new IllegalArgumentException("number of parameters = " + numArgs + //$NON-NLS-1$ 
431
						   						   " index = " + index ); //$NON-NLS-1$	
432
			final Argument arg = args[index];
433
			final Annotation[] argAnnos = arg.annotations;
434
			final int numAnnotations = argAnnos == null ? 0 : argAnnos.length;
435
			
436
			if( numAnnotations > 0 ){
437
				result = new SourceAnnotation[numAnnotations];
438
				// check for errors
439
				ASTNode.resolveAnnotations(methodDecl.scope, argAnnos, this);
440
				for( int j=0; j<numAnnotations; j++ ){
441
					result[j] = argAnnos[j].compilerAnnotation;
442
				}
443
			}	
444
		}
445
	}
446
	
447
	return result;
448
}
449
450
/**
451
 * @return the default value iff this is an annotation method.
452
 *         Return <code>null</code> if there is no default value or 
453
 *         if this is not an annotaion method. 
454
 */
455
public Object getDefaultValue()
456
{
457
	if(this.declaringClass != null && this.declaringClass instanceof SourceTypeBinding )
458
	{
459
		TypeDeclaration typeDecl = ((SourceTypeBinding)this.declaringClass).scope.referenceContext;
460
		final AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(this);
461
		if( methodDecl instanceof AnnotationMethodDeclaration){
462
			return SourceElementValuePair.getValue(((AnnotationMethodDeclaration)methodDecl).defaultValue);
463
		}
464
	}
465
	return null;
466
}
467
383
public TypeVariableBinding getTypeVariable(char[] variableName) {
468
public TypeVariableBinding getTypeVariable(char[] variableName) {
384
	for (int i = this.typeVariables.length; --i >= 0;)
469
	for (int i = this.typeVariables.length; --i >= 0;)
385
		if (CharOperation.equals(this.typeVariables[i].sourceName, variableName))
470
		if (CharOperation.equals(this.typeVariables[i].sourceName, variableName))
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java (-3 / +8 lines)
Lines 291-299 Link Here
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 MethodBinding(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 IAnnotationInstance[] 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 IAnnotationInstance[] getAnnotations()
149
	{
150
		return original().getAnnotations();
151
	}
152
	
153
	public IAnnotationInstance[] 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 IAnnotationInstance[] 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 IAnnotationInstance[] getAnnotations(){ return NoAnnotations; }
44
public IAnnotationInstance[] 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 IAnnotationInstance[] getAnnotations()
863
{
864
	return NoAnnotations;
865
}
860
}
866
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-2 / +27 lines)
Lines 633-638 Link Here
633
	}
633
	}
634
	return this.tagBits;
634
	return this.tagBits;
635
}
635
}
636
637
public IAnnotationInstance[] 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 IAnnotationInstance[] instances = new IAnnotationInstance[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 BinaryFieldBinding )
915
			updatedField = new BinaryFieldBinding((BinaryFieldBinding)targetField, newDeclaringClass);
916
		else
917
			updatedField = new FieldBinding(targetField, newDeclaringClass);
918
			
898
		fieldMap.put(newDeclaringClass, updatedField);
919
		fieldMap.put(newDeclaringClass, updatedField);
899
	}
920
	}
900
	return updatedField;
921
	return updatedField;
Lines 912-918 Link Here
912
	}
933
	}
913
	MethodBinding updatedMethod = (MethodBinding) methodMap.get(newDeclaringClass);
934
	MethodBinding updatedMethod = (MethodBinding) methodMap.get(newDeclaringClass);
914
	if (updatedMethod == null){
935
	if (updatedMethod == null){
915
		updatedMethod = new MethodBinding(targetMethod, newDeclaringClass);
936
		if( targetMethod instanceof BinaryMethodBinding )
937
			updatedMethod = new BinaryMethodBinding((BinaryMethodBinding)targetMethod, newDeclaringClass);
938
		else
939
			updatedMethod = new MethodBinding(targetMethod, newDeclaringClass);	
940
			
916
		methodMap.put(newDeclaringClass, updatedMethod);
941
		methodMap.put(newDeclaringClass, updatedMethod);
917
	}
942
	}
918
	return updatedMethod;
943
	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 IAnnotationInstance[] 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 IAnnotationInstance[] 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 IAnnotationInstance[] getAnnotations(){ return NoAnnotations; }
340
	public IAnnotationInstance[] 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
	IAnnotationInstance[] NoAnnotations = new IAnnotationInstance[0];
137
	IElementValuePair[] NoElementValuePairs = new IElementValuePair[0];
138
	IAnnotationInstance[][] NoParamAnnotations = new IAnnotationInstance[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 IAnnotationInstance[] getAnnotations(){ return NoAnnotations; }
26
	public IAnnotationInstance[] 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 IAnnotationInstance[] 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.IAnnotationInstance 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.IAnnotationInstance 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.IAnnotationInstance[] 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.IAnnotationInstance[] 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.IAnnotationInstance[] 
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.IAnnotationInstance[] 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/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/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
}
(-)schema/codeFormatter.exsd (-6 / +6 lines)
Lines 68-78 Link Here
68
         <meta.section type="examples"/>
68
         <meta.section type="examples"/>
69
      </appInfo>
69
      </appInfo>
70
      <documentation>
70
      <documentation>
71
         Example of an implementation of &lt;code&gt;ICodeFormatter&lt;/code&gt;:  &lt;pre&gt;                                                                       
71
         Example of an implementation of &lt;code&gt;ICodeFormatter&lt;/code&gt;:  &lt;pre&gt;                                                                       
72
&lt;extension point=&quot;org.eclipse.jdt.core.codeFormatter&quot;&gt;            
72
&lt;extension point=&quot;org.eclipse.jdt.core.codeFormatter&quot;&gt;            
73
   &lt;codeFormatter                                                                                              
73
   &lt;codeFormatter                                                                                              
74
      class=&quot;com.example.MyCodeFormatter&quot;/&gt;                           
74
      class=&quot;com.example.MyCodeFormatter&quot;/&gt;                           
75
&lt;/extension&gt;
75
&lt;/extension&gt;
76
&lt;/pre&gt;
76
&lt;/pre&gt;
77
      </documentation>
77
      </documentation>
78
   </annotation>
78
   </annotation>
Lines 100-106 Link Here
100
         <meta.section type="copyright"/>
100
         <meta.section type="copyright"/>
101
      </appInfo>
101
      </appInfo>
102
      <documentation>
102
      <documentation>
103
         Copyright (c) 2000, 2004 IBM Corporation and others.&lt;br&gt;
103
         Copyright (c) 2000, 2004 IBM Corporation and others.&lt;br&gt;
104
All rights reserved. This program and the accompanying materials are made 
104
All rights reserved. This program and the accompanying materials are made 
105
available under the terms of the Eclipse Public License v1.0 which accompanies 
105
available under the terms of the Eclipse Public License v1.0 which accompanies 
106
this distribution, and is available at &lt;a
106
this distribution, and is available at &lt;a
(-)scripts/build.xml (-59 / +59 lines)
Lines 1-60 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project name="export-executable" default="build" basedir=".">
2
<project name="export-executable" default="build" basedir=".">
3
3
4
	<property name="version" value="3.1.0" />
4
	<property name="version" value="3.1.0" />
5
	<property name="gcc-path" value="C:/java_tools/thisiscool-gcc/gcc-4.0" />
5
	<property name="gcc-path" value="C:/java_tools/thisiscool-gcc/gcc-4.0" />
6
	<property name="binaryname" value="ejavac${version}" />
6
	<property name="binaryname" value="ejavac${version}" />
7
	<property name="dest" value="c:/temp/bingcj" />
7
	<property name="dest" value="c:/temp/bingcj" />
8
	<property name="extract_folder" value="${dest}/src/" />
8
	<property name="extract_folder" value="${dest}/src/" />
9
	<property name="work" value="${dest}/tmp/" />
9
	<property name="work" value="${dest}/tmp/" />
10
	<property name="source" value="C:/eclipse/I1111/eclipse/plugins/org.eclipse.jdt.source_3.1.0/src/org.eclipse.jdt.core_3.1.0/jdtcoresrc.zip" />
10
	<property name="source" value="C:/eclipse/I1111/eclipse/plugins/org.eclipse.jdt.source_3.1.0/src/org.eclipse.jdt.core_3.1.0/jdtcoresrc.zip" />
11
	<property name="binaries" value="C:/eclipse/I1111/eclipse/plugins/org.eclipse.jdt.core_3.1.0/jdtcore.jar" />
11
	<property name="binaries" value="C:/eclipse/I1111/eclipse/plugins/org.eclipse.jdt.core_3.1.0/jdtcore.jar" />
12
	<property name="gcj_script_name" value="export-executable.xml" />
12
	<property name="gcj_script_name" value="export-executable.xml" />
13
13
14
	<target name="build">
14
	<target name="build">
15
		<echo message="target: ${dest}" />
15
		<echo message="target: ${dest}" />
16
		<delete dir="${dest}" failonerror="no" />
16
		<delete dir="${dest}" failonerror="no" />
17
		<mkdir dir="${dest}" />
17
		<mkdir dir="${dest}" />
18
18
19
		<unzip overwrite="yes" dest="${work}" src="${source}">
19
		<unzip overwrite="yes" dest="${work}" src="${source}">
20
			<patternset>
20
			<patternset>
21
				<include name="**/compiler/**" />
21
				<include name="**/compiler/**" />
22
				<exclude name="**/compiler/**/*.html" />
22
				<exclude name="**/compiler/**/*.html" />
23
				<exclude name="**/IScanner.java" />
23
				<exclude name="**/IScanner.java" />
24
				<exclude name="**/ITerminalSymbols.java" />
24
				<exclude name="**/ITerminalSymbols.java" />
25
				<exclude name="**/DocumentElementParser.java" />
25
				<exclude name="**/DocumentElementParser.java" />
26
				<exclude name="**/IDocumentElementRequestor.java" />
26
				<exclude name="**/IDocumentElementRequestor.java" />
27
				<exclude name="**/ISourceElementRequestor.java" />
27
				<exclude name="**/ISourceElementRequestor.java" />
28
				<exclude name="**/SourceElementParser.java" />
28
				<exclude name="**/SourceElementParser.java" />
29
				<exclude name="**/SourceElementRequestorAdapter.java" />
29
				<exclude name="**/SourceElementRequestorAdapter.java" />
30
				<exclude name="**/SourceConstructorDeclaration.java" />
30
				<exclude name="**/SourceConstructorDeclaration.java" />
31
				<exclude name="**/SourceFieldDeclaration.java" />
31
				<exclude name="**/SourceFieldDeclaration.java" />
32
				<exclude name="**/SourceMethodDeclaration.java" />
32
				<exclude name="**/SourceMethodDeclaration.java" />
33
				<exclude name="**/SourceTypeConverter.java" />
33
				<exclude name="**/SourceTypeConverter.java" />
34
			</patternset>
34
			</patternset>
35
		</unzip>
35
		</unzip>
36
36
37
		<unzip overwrite="yes" dest="${work}" src="${binaries}">
37
		<unzip overwrite="yes" dest="${work}" src="${binaries}">
38
			<patternset>
38
			<patternset>
39
				<include name="**/compiler/**/*.properties" />
39
				<include name="**/compiler/**/*.properties" />
40
				<include name="**/*.rsc" />
40
				<include name="**/*.rsc" />
41
				<exclude name="**/*.class" />
41
				<exclude name="**/*.class" />
42
				<exclude name="**/*.mf" />
42
				<exclude name="**/*.mf" />
43
			</patternset>
43
			</patternset>
44
		</unzip>
44
		</unzip>
45
45
46
		<!-- echo message="generate build script" />
46
		<!-- echo message="generate build script" />
47
		<java classname="GenerateBuildScript">
47
		<java classname="GenerateBuildScript">
48
			<sysproperty key="user.dir" value="${basedir}/scripts"/>
48
			<sysproperty key="user.dir" value="${basedir}/scripts"/>
49
			<arg value="${gcj_script_name}"/>
49
			<arg value="${gcj_script_name}"/>
50
			<arg value="${basedir}/${work}"/>
50
			<arg value="${basedir}/${work}"/>
51
			<classpath>
51
			<classpath>
52
				<pathelement path="${basedir}/scripts"/>
52
				<pathelement path="${basedir}/scripts"/>
53
			</classpath>
53
			</classpath>
54
		</java>
54
		</java>
55
		
55
		
56
		<echo message="run the new build script" />
56
		<echo message="run the new build script" />
57
		<ant antfile="${basedir}/scripts/export-executable.xml"/>
57
		<ant antfile="${basedir}/scripts/export-executable.xml"/>
58
		<delete file="${basedir}/scripts/export-executable.xml"/ -->
58
		<delete file="${basedir}/scripts/export-executable.xml"/ -->
59
	</target>
59
	</target>
60
</project>
60
</project>
(-)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
		StringBuffer buffer = new StringBuffer();
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 StringBuffer buffer = new StringBuffer();
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
		StringBuffer buffer = new StringBuffer();
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
		StringBuffer buffer = new StringBuffer();
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(", "); //$NON-NLS-1$
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
		StringBuffer buffer = new StringBuffer();
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
								   IAnnotationInstance[] methodAnnotation,
26
								   IAnnotationInstance[][] 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 IAnnotationInstance 
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
	IElementValuePair[] 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 IElementValuePair[] 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 IElementValuePair
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 IAnnotationInstance} 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 (+39 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.impl.Constant;
14
15
public class BinaryFieldBinding extends FieldBinding
16
{
17
	private IAnnotationInstance[] annotations = NoAnnotations;
18
	public BinaryFieldBinding(char[] name, 
19
							  TypeBinding type, 
20
							  int modifiers, 
21
							  ReferenceBinding declaringClass,
22
							  Constant constant,
23
							  IAnnotationInstance[] annos) {
24
		super(name, type, modifiers, declaringClass, constant);		
25
		if( annos != null )
26
			this.annotations = annos;
27
	}
28
	
29
	public BinaryFieldBinding(BinaryFieldBinding initialFieldBinding, ReferenceBinding declaringClass)
30
	{
31
		super(initialFieldBinding, declaringClass);
32
		this.annotations = initialFieldBinding.annotations;
33
	}
34
	
35
	public IAnnotationInstance[] getAnnotations()
36
	{
37
		return annotations;
38
	}
39
}
(-)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 IAnnotationInstance[][] NoMethodAnnotation = new IAnnotationInstance[][]{ NoAnnotations };	
16
	private static final IAnnotationInstance[][] NoExtendedModifiers = new IAnnotationInstance[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 IAnnotationInstance[][] extendedModifiers = null;	
32
	
33
	public BinaryMethodBinding(int modifiers,
34
							   char[] selector, 
35
							   TypeBinding returnType, 
36
							   TypeBinding[] parameters, 
37
							   ReferenceBinding[] thrownExceptions, 
38
							   ReferenceBinding declaringClass,
39
							   IAnnotationInstance[] methodAnnotations,
40
							   IAnnotationInstance[][] 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
							   IAnnotationInstance[] methodAnnotations,
51
							   IAnnotationInstance[][] 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 IAnnotationInstance[] methodAnnotations,
67
							   final IAnnotationInstance[][] 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 IAnnotationInstance[][]{methodAnnotations};
77
			else{
78
				this.extendedModifiers = new IAnnotationInstance[numParams + 1][];
79
				this.extendedModifiers[0] = methodAnnotations;
80
				System.arraycopy(parameterAnnotations, 0, this.extendedModifiers, 1, numParams);
81
			}
82
		}
83
	}
84
	
85
	public IAnnotationInstance[] 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 IAnnotationInstance[] 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/IAnnotationInstance.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 IAnnotationInstance{
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
	IElementValuePair[] getElementValuePairs();
27
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/IElementValuePair.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 IElementValuePair 
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 IAnnotationInstance} 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 IAnnotationInstance, TypeConstants
12
{
13
	private final Annotation astAnnotation;
14
	private final IElementValuePair[] 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 IElementValuePair[] 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 IElementValuePair 
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
}
(-)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.IAnnotationInstance internalAnnotation;
17
	private final BindingResolver bindingResolver;
18
	
19
	AnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance 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.IElementValuePair[] 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.IElementValuePair internalPair;
21
	private Object value = null; 
22
	private final BindingResolver bindingResolver;
23
	
24
	ElementValuePair(final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair 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.IAnnotationInstance)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
}

Return to bug 90344