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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ClassFile.java (-47 / +76 lines)
Lines 71-76 Link Here
71
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
71
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
72
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
72
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
73
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
73
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
74
import org.eclipse.jdt.internal.compiler.problem.ShouldNotImplement;
74
import org.eclipse.jdt.internal.compiler.util.Messages;
75
import org.eclipse.jdt.internal.compiler.util.Messages;
75
import org.eclipse.jdt.internal.compiler.util.Util;
76
import org.eclipse.jdt.internal.compiler.util.Util;
76
77
Lines 568-574 Link Here
568
			contents[contentsOffset++] = methodIndexByte2;
569
			contents[contentsOffset++] = methodIndexByte2;
569
			attributeNumber++;
570
			attributeNumber++;
570
		}
571
		}
571
		if (this.targetJDK >= ClassFileConstants.JDK1_5 && !this.creatingProblemType) {
572
		if (this.targetJDK >= ClassFileConstants.JDK1_5) {
572
			TypeDeclaration typeDeclaration = referenceBinding.scope.referenceContext;
573
			TypeDeclaration typeDeclaration = referenceBinding.scope.referenceContext;
573
			if (typeDeclaration != null) {
574
			if (typeDeclaration != null) {
574
				final Annotation[] annotations = typeDeclaration.annotations;
575
				final Annotation[] annotations = typeDeclaration.annotations;
Lines 828-834 Link Here
828
			contents[contentsOffset++] = (byte) signatureIndex;
829
			contents[contentsOffset++] = (byte) signatureIndex;
829
			attributesNumber++;
830
			attributesNumber++;
830
		}
831
		}
831
		if (this.targetJDK >= ClassFileConstants.JDK1_5 && !this.creatingProblemType) {
832
		if (this.targetJDK >= ClassFileConstants.JDK1_5) {
832
			FieldDeclaration fieldDeclaration = fieldBinding.sourceField();
833
			FieldDeclaration fieldDeclaration = fieldBinding.sourceField();
833
			if (fieldDeclaration != null) {
834
			if (fieldDeclaration != null) {
834
				Annotation[] annotations = fieldDeclaration.annotations;
835
				Annotation[] annotations = fieldDeclaration.annotations;
Lines 1024-1030 Link Here
1024
		// always clear the strictfp/native/abstract bit for a problem method
1025
		// always clear the strictfp/native/abstract bit for a problem method
1025
		generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
1026
		generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
1026
		int methodAttributeOffset = contentsOffset;
1027
		int methodAttributeOffset = contentsOffset;
1027
		int attributeNumber = generateMethodInfoAttribute(methodBinding, true);
1028
		int attributeNumber = generateMethodInfoAttribute(methodBinding);
1028
1029
1029
		// Code attribute
1030
		// Code attribute
1030
		attributeNumber++;
1031
		attributeNumber++;
Lines 1109-1115 Link Here
1109
		// always clear the strictfp/native/abstract bit for a problem method
1110
		// always clear the strictfp/native/abstract bit for a problem method
1110
		generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
1111
		generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
1111
		int methodAttributeOffset = contentsOffset;
1112
		int methodAttributeOffset = contentsOffset;
1112
		int attributeNumber = generateMethodInfoAttribute(methodBinding, true);
1113
		int attributeNumber = generateMethodInfoAttribute(methodBinding);
1113
1114
1114
		// Code attribute
1115
		// Code attribute
1115
		attributeNumber++;
1116
		attributeNumber++;
Lines 6033-6045 Link Here
6033
		return constantPool.UTF8Cache.returnKeyFor(2);
6034
		return constantPool.UTF8Cache.returnKeyFor(2);
6034
	}
6035
	}
6035
6036
6036
	private void generateAnnotation(Annotation annotation, int attributeOffset) {
6037
	private void generateAnnotation(Annotation annotation, int currentOffset) {
6038
		int startingContentsOffset = currentOffset;
6037
		if (contentsOffset + 4 >= this.contents.length) {
6039
		if (contentsOffset + 4 >= this.contents.length) {
6038
			resizeContents(4);
6040
			resizeContents(4);
6039
		}
6041
		}
6040
		TypeBinding annotationTypeBinding = annotation.resolvedType;
6042
		TypeBinding annotationTypeBinding = annotation.resolvedType;
6041
		if (annotationTypeBinding == null) {
6043
		if (annotationTypeBinding == null) {
6042
			this.contentsOffset = attributeOffset;
6044
			this.contentsOffset = startingContentsOffset;
6043
			return;
6045
			return;
6044
		}
6046
		}
6045
		final int typeIndex = constantPool.literalIndex(annotationTypeBinding.signature());
6047
		final int typeIndex = constantPool.literalIndex(annotationTypeBinding.signature());
Lines 6062-6070 Link Here
6062
					contents[contentsOffset++] = (byte) elementNameIndex;
6064
					contents[contentsOffset++] = (byte) elementNameIndex;
6063
					MethodBinding methodBinding = memberValuePair.binding;
6065
					MethodBinding methodBinding = memberValuePair.binding;
6064
					if (methodBinding == null) {
6066
					if (methodBinding == null) {
6065
						contentsOffset = attributeOffset;
6067
						contentsOffset = startingContentsOffset;
6066
					} else {
6068
					} else {
6067
						generateElementValue(memberValuePair.value, methodBinding.returnType, attributeOffset);
6069
						try {
6070
							generateElementValue(memberValuePair.value, methodBinding.returnType, startingContentsOffset);
6071
						} catch(ClassCastException e) {
6072
							contentsOffset = startingContentsOffset;
6073
						} catch(ShouldNotImplement e) {
6074
							contentsOffset = startingContentsOffset;
6075
						}
6068
					}
6076
					}
6069
				}
6077
				}
6070
			} else {
6078
			} else {
Lines 6084-6092 Link Here
6084
			contents[contentsOffset++] = (byte) elementNameIndex;
6092
			contents[contentsOffset++] = (byte) elementNameIndex;
6085
			MethodBinding methodBinding = singleMemberAnnotation.memberValuePairs()[0].binding;
6093
			MethodBinding methodBinding = singleMemberAnnotation.memberValuePairs()[0].binding;
6086
			if (methodBinding == null) {
6094
			if (methodBinding == null) {
6087
				contentsOffset = attributeOffset;
6095
				contentsOffset = startingContentsOffset;
6088
			} else {
6096
			} else {
6089
				generateElementValue(singleMemberAnnotation.memberValue, methodBinding.returnType, attributeOffset);
6097
				try {
6098
					generateElementValue(singleMemberAnnotation.memberValue, methodBinding.returnType, startingContentsOffset);
6099
				} catch(ClassCastException e) {
6100
					contentsOffset = startingContentsOffset;
6101
				} catch(ShouldNotImplement e) {
6102
					contentsOffset = startingContentsOffset;
6103
				}
6090
			}
6104
			}
6091
		} else {
6105
		} else {
6092
			// this is a marker annotation (no member value pairs)
6106
			// this is a marker annotation (no member value pairs)
Lines 6290-6300 Link Here
6290
			contentsOffset = attributeOffset;
6304
			contentsOffset = attributeOffset;
6291
		}
6305
		}
6292
	}
6306
	}
6293
6294
	public int generateMethodInfoAttribute(MethodBinding methodBinding) {
6295
		return generateMethodInfoAttribute(methodBinding, false);
6296
	}
6297
6298
	public int generateMethodInfoAttribute(MethodBinding methodBinding, AnnotationMethodDeclaration declaration) {
6307
	public int generateMethodInfoAttribute(MethodBinding methodBinding, AnnotationMethodDeclaration declaration) {
6299
		int attributesNumber = generateMethodInfoAttribute(methodBinding);
6308
		int attributesNumber = generateMethodInfoAttribute(methodBinding);
6300
		int attributeOffset = contentsOffset;
6309
		int attributeOffset = contentsOffset;
Lines 6334-6340 Link Here
6334
	 * @param methodBinding org.eclipse.jdt.internal.compiler.lookup.MethodBinding
6343
	 * @param methodBinding org.eclipse.jdt.internal.compiler.lookup.MethodBinding
6335
	 * @return <CODE>int</CODE>
6344
	 * @return <CODE>int</CODE>
6336
	 */
6345
	 */
6337
	public int generateMethodInfoAttribute(MethodBinding methodBinding, boolean createProblemMethod) {
6346
	public int generateMethodInfoAttribute(MethodBinding methodBinding) {
6338
		// leave two bytes for the attribute_number
6347
		// leave two bytes for the attribute_number
6339
		contentsOffset += 2;
6348
		contentsOffset += 2;
6340
		if (contentsOffset + 2 >= this.contents.length) {
6349
		if (contentsOffset + 2 >= this.contents.length) {
Lines 6459-6465 Link Here
6459
			contents[contentsOffset++] = (byte) signatureIndex;
6468
			contents[contentsOffset++] = (byte) signatureIndex;
6460
			attributeNumber++;
6469
			attributeNumber++;
6461
		}
6470
		}
6462
		if (this.targetJDK >= ClassFileConstants.JDK1_5 && !this.creatingProblemType && !createProblemMethod) {
6471
		if (this.targetJDK >= ClassFileConstants.JDK1_5) {
6463
			AbstractMethodDeclaration methodDeclaration = methodBinding.sourceMethod();
6472
			AbstractMethodDeclaration methodDeclaration = methodBinding.sourceMethod();
6464
			if (methodDeclaration != null) {
6473
			if (methodDeclaration != null) {
6465
				Annotation[] annotations = methodDeclaration.annotations;
6474
				Annotation[] annotations = methodDeclaration.annotations;
Lines 6607-6614 Link Here
6607
			}
6616
			}
6608
		}
6617
		}
6609
6618
6619
		int annotationAttributeOffset = contentsOffset;
6610
		if (invisibleAnnotationsCounter != 0) {
6620
		if (invisibleAnnotationsCounter != 0) {
6611
			int annotationAttributeOffset = contentsOffset;
6612
			if (contentsOffset + 10 >= contents.length) {
6621
			if (contentsOffset + 10 >= contents.length) {
6613
				resizeContents(10);
6622
				resizeContents(10);
6614
			}
6623
			}
Lines 6622-6642 Link Here
6622
			int annotationsLengthOffset = contentsOffset;
6631
			int annotationsLengthOffset = contentsOffset;
6623
			contentsOffset += 2; // leave space for the annotations length
6632
			contentsOffset += 2; // leave space for the annotations length
6624
6633
6625
			contents[annotationsLengthOffset++] = (byte) (invisibleAnnotationsCounter >> 8);
6634
			int counter = 0;
6626
			contents[annotationsLengthOffset++] = (byte) invisibleAnnotationsCounter;
6627
6628
			loop: for (int i = 0; i < length; i++) {
6635
			loop: for (int i = 0; i < length; i++) {
6629
				if (invisibleAnnotationsCounter == 0) break loop;
6636
				if (invisibleAnnotationsCounter == 0) break loop;
6630
				Annotation annotation = annotations[i];
6637
				Annotation annotation = annotations[i];
6631
				if (isRuntimeInvisible(annotation)) {
6638
				if (isRuntimeInvisible(annotation)) {
6632
					generateAnnotation(annotation, annotationAttributeOffset);
6639
					int currentAnnotationOffset = this.contentsOffset;
6640
					generateAnnotation(annotation, currentAnnotationOffset);
6633
					invisibleAnnotationsCounter--;
6641
					invisibleAnnotationsCounter--;
6634
					if (this.contentsOffset == annotationAttributeOffset) {
6642
					if (this.contentsOffset != currentAnnotationOffset) {
6635
						break loop;
6643
						counter++;
6636
					}
6644
					}
6637
				}
6645
				}
6638
			}
6646
			}
6639
			if (contentsOffset != annotationAttributeOffset) {
6647
			if (counter != 0) {
6648
				contents[annotationsLengthOffset++] = (byte) (counter >> 8);
6649
				contents[annotationsLengthOffset++] = (byte) counter;
6650
6640
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6651
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6641
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6652
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6642
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
6653
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
Lines 6648-6655 Link Here
6648
			}
6659
			}
6649
		}
6660
		}
6650
6661
6662
		annotationAttributeOffset = contentsOffset;
6651
		if (visibleAnnotationsCounter != 0) {
6663
		if (visibleAnnotationsCounter != 0) {
6652
			int annotationAttributeOffset = contentsOffset;
6653
			if (contentsOffset + 10 >= contents.length) {
6664
			if (contentsOffset + 10 >= contents.length) {
6654
				resizeContents(10);
6665
				resizeContents(10);
6655
			}
6666
			}
Lines 6663-6683 Link Here
6663
			int annotationsLengthOffset = contentsOffset;
6674
			int annotationsLengthOffset = contentsOffset;
6664
			contentsOffset += 2; // leave space for the annotations length
6675
			contentsOffset += 2; // leave space for the annotations length
6665
6676
6666
			contents[annotationsLengthOffset++] = (byte) (visibleAnnotationsCounter >> 8);
6677
			int counter = 0;
6667
			contents[annotationsLengthOffset++] = (byte) visibleAnnotationsCounter;
6668
6669
			loop: for (int i = 0; i < length; i++) {
6678
			loop: for (int i = 0; i < length; i++) {
6670
				if (visibleAnnotationsCounter == 0) break loop;
6679
				if (visibleAnnotationsCounter == 0) break loop;
6671
				Annotation annotation = annotations[i];
6680
				Annotation annotation = annotations[i];
6672
				if (isRuntimeVisible(annotation)) {
6681
				if (isRuntimeVisible(annotation)) {
6673
					visibleAnnotationsCounter--;
6682
					visibleAnnotationsCounter--;
6674
					generateAnnotation(annotation, annotationAttributeOffset);
6683
					int currentAnnotationOffset = this.contentsOffset;
6675
					if (this.contentsOffset == annotationAttributeOffset) {
6684
					generateAnnotation(annotation, currentAnnotationOffset);
6676
						break loop;
6685
					if (this.contentsOffset != currentAnnotationOffset) {
6686
						counter++;
6677
					}
6687
					}
6678
				}
6688
				}
6679
			}
6689
			}
6680
			if (contentsOffset != annotationAttributeOffset) {
6690
			if (counter != 0) {
6691
				contents[annotationsLengthOffset++] = (byte) (counter >> 8);
6692
				contents[annotationsLengthOffset++] = (byte) counter;
6693
6681
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6694
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6682
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6695
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6683
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
6696
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
Lines 6717-6722 Link Here
6717
		int attributesNumber = 0;
6730
		int attributesNumber = 0;
6718
		int annotationAttributeOffset = contentsOffset;
6731
		int annotationAttributeOffset = contentsOffset;
6719
		if (invisibleParametersAnnotationsCounter != 0) {
6732
		if (invisibleParametersAnnotationsCounter != 0) {
6733
			int globalCounter = 0;
6720
			if (contentsOffset + 7 >= contents.length) {
6734
			if (contentsOffset + 7 >= contents.length) {
6721
				resizeContents(7);
6735
				resizeContents(7);
6722
			}
6736
			}
Lines 6728-6734 Link Here
6728
			contentsOffset += 4; // leave space for the attribute length
6742
			contentsOffset += 4; // leave space for the attribute length
6729
6743
6730
			contents[contentsOffset++] = (byte) argumentsLength;
6744
			contents[contentsOffset++] = (byte) argumentsLength;
6731
			invisibleLoop: for (int i = 0; i < argumentsLength; i++) {
6745
			for (int i = 0; i < argumentsLength; i++) {
6732
				if (contentsOffset + 2 >= contents.length) {
6746
				if (contentsOffset + 2 >= contents.length) {
6733
					resizeContents(2);
6747
					resizeContents(2);
6734
				}
6748
				}
Lines 6737-6761 Link Here
6737
					contents[contentsOffset++] = (byte) 0;
6751
					contents[contentsOffset++] = (byte) 0;
6738
				} else {
6752
				} else {
6739
					final int numberOfInvisibleAnnotations = annotationsCounters[i][INVISIBLE_INDEX];
6753
					final int numberOfInvisibleAnnotations = annotationsCounters[i][INVISIBLE_INDEX];
6740
					contents[contentsOffset++] = (byte) (numberOfInvisibleAnnotations >> 8);
6754
					int invisibleAnnotationsOffset = this.contentsOffset;
6741
					contents[contentsOffset++] = (byte) numberOfInvisibleAnnotations;
6755
					// leave space for number of annotations
6756
					this.contentsOffset += 2;
6757
					int counter = 0;
6742
					if (numberOfInvisibleAnnotations != 0) {
6758
					if (numberOfInvisibleAnnotations != 0) {
6743
						Argument argument = arguments[i];
6759
						Argument argument = arguments[i];
6744
						Annotation[] annotations = argument.annotations;
6760
						Annotation[] annotations = argument.annotations;
6745
						for (int j = 0, max = annotations.length; j < max; j++) {
6761
						for (int j = 0, max = annotations.length; j < max; j++) {
6746
							Annotation annotation = annotations[j];
6762
							Annotation annotation = annotations[j];
6747
							if (isRuntimeInvisible(annotation)) {
6763
							if (isRuntimeInvisible(annotation)) {
6748
								generateAnnotation(annotation, annotationAttributeOffset);
6764
								int currentAnnotationOffset = this.contentsOffset;
6749
								if (contentsOffset == annotationAttributeOffset) {
6765
								generateAnnotation(annotation, currentAnnotationOffset);
6750
									break invisibleLoop;
6766
								if (contentsOffset != currentAnnotationOffset) {
6767
									counter++;
6768
									globalCounter++;
6751
								}
6769
								}
6752
								invisibleParametersAnnotationsCounter--;
6770
								invisibleParametersAnnotationsCounter--;
6753
							}
6771
							}
6754
						}
6772
						}
6755
					}
6773
					}
6774
					contents[invisibleAnnotationsOffset++] = (byte) (counter >> 8);
6775
					contents[invisibleAnnotationsOffset] = (byte) counter;
6756
				}
6776
				}
6757
			}
6777
			}
6758
			if (contentsOffset != annotationAttributeOffset) {
6778
			if (globalCounter != 0) {
6759
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6779
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6760
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6780
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6761
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
6781
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
Lines 6763-6772 Link Here
6763
				contents[attributeLengthOffset++] = (byte) attributeLength;
6783
				contents[attributeLengthOffset++] = (byte) attributeLength;
6764
				attributesNumber++;
6784
				attributesNumber++;
6765
			} else {
6785
			} else {
6786
				// if globalCounter is 0, this means that the code generation for all visible annotations failed
6766
				contentsOffset = annotationAttributeOffset;
6787
				contentsOffset = annotationAttributeOffset;
6767
			}
6788
			}
6768
		}
6789
		}
6769
		if (visibleParametersAnnotationsCounter != 0) {
6790
		if (visibleParametersAnnotationsCounter != 0) {
6791
			int globalCounter = 0;
6770
			if (contentsOffset + 7 >= contents.length) {
6792
			if (contentsOffset + 7 >= contents.length) {
6771
				resizeContents(7);
6793
				resizeContents(7);
6772
			}
6794
			}
Lines 6778-6784 Link Here
6778
			contentsOffset += 4; // leave space for the attribute length
6800
			contentsOffset += 4; // leave space for the attribute length
6779
6801
6780
			contents[contentsOffset++] = (byte) argumentsLength;
6802
			contents[contentsOffset++] = (byte) argumentsLength;
6781
			visibleLoop: for (int i = 0; i < argumentsLength; i++) {
6803
			for (int i = 0; i < argumentsLength; i++) {
6782
				if (contentsOffset + 2 >= contents.length) {
6804
				if (contentsOffset + 2 >= contents.length) {
6783
					resizeContents(2);
6805
					resizeContents(2);
6784
				}
6806
				}
Lines 6787-6811 Link Here
6787
					contents[contentsOffset++] = (byte) 0;
6809
					contents[contentsOffset++] = (byte) 0;
6788
				} else {
6810
				} else {
6789
					final int numberOfVisibleAnnotations = annotationsCounters[i][VISIBLE_INDEX];
6811
					final int numberOfVisibleAnnotations = annotationsCounters[i][VISIBLE_INDEX];
6790
					contents[contentsOffset++] = (byte) (numberOfVisibleAnnotations >> 8);
6812
					int visibleAnnotationsOffset = this.contentsOffset;
6791
					contents[contentsOffset++] = (byte) numberOfVisibleAnnotations;
6813
					// leave space for number of annotations
6814
					this.contentsOffset += 2;
6815
					int counter = 0;
6792
					if (numberOfVisibleAnnotations != 0) {
6816
					if (numberOfVisibleAnnotations != 0) {
6793
						Argument argument = arguments[i];
6817
						Argument argument = arguments[i];
6794
						Annotation[] annotations = argument.annotations;
6818
						Annotation[] annotations = argument.annotations;
6795
						for (int j = 0, max = annotations.length; j < max; j++) {
6819
						for (int j = 0, max = annotations.length; j < max; j++) {
6796
							Annotation annotation = annotations[j];
6820
							Annotation annotation = annotations[j];
6797
							if (isRuntimeVisible(annotation)) {
6821
							if (isRuntimeVisible(annotation)) {
6798
								generateAnnotation(annotation, annotationAttributeOffset);
6822
								int currentAnnotationOffset = this.contentsOffset;
6799
								if (contentsOffset == annotationAttributeOffset) {
6823
								generateAnnotation(annotation, currentAnnotationOffset);
6800
									break visibleLoop;
6824
								if (contentsOffset != currentAnnotationOffset) {
6825
									counter++;
6826
									globalCounter++;
6801
								}
6827
								}
6802
								visibleParametersAnnotationsCounter--;
6828
								visibleParametersAnnotationsCounter--;
6803
							}
6829
							}
6804
						}
6830
						}
6805
					}
6831
					}
6832
					contents[visibleAnnotationsOffset++] = (byte) (counter >> 8);
6833
					contents[visibleAnnotationsOffset] = (byte) counter;
6806
				}
6834
				}
6807
			}
6835
			}
6808
			if (contentsOffset != annotationAttributeOffset) {
6836
			if (globalCounter != 0) {
6809
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6837
				int attributeLength = contentsOffset - attributeLengthOffset - 4;
6810
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6838
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 24);
6811
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
6839
				contents[attributeLengthOffset++] = (byte) (attributeLength >> 16);
Lines 6813-6818 Link Here
6813
				contents[attributeLengthOffset++] = (byte) attributeLength;
6841
				contents[attributeLengthOffset++] = (byte) attributeLength;
6814
				attributesNumber++;
6842
				attributesNumber++;
6815
			} else {
6843
			} else {
6844
				// if globalCounter is 0, this means that the code generation for all visible annotations failed
6816
				contentsOffset = annotationAttributeOffset;
6845
				contentsOffset = annotationAttributeOffset;
6817
			}
6846
			}
6818
		}
6847
		}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-26 / +308 lines)
Lines 39-46 Link Here
39
	// All specified tests which do not belong to the class are skipped...
39
	// All specified tests which do not belong to the class are skipped...
40
	static {
40
	static {
41
//		TESTS_NAMES = new String[] { "test127" };
41
//		TESTS_NAMES = new String[] { "test127" };
42
//		TESTS_NUMBERS = new int[] { 248 };
42
//		TESTS_NUMBERS = new int[] { 249 };
43
//		TESTS_RANGE = new int[] { 219, -1 };
43
//		TESTS_RANGE = new int[] { 249, -1 };
44
	}
44
	}
45
45
46
	public static Test suite() {
46
	public static Test suite() {
Lines 1685-1703 Link Here
1685
				ClassFileBytesDisassembler.DETAILED); 
1685
				ClassFileBytesDisassembler.DETAILED); 
1686
		
1686
		
1687
		String expectedOutput = 
1687
		String expectedOutput = 
1688
			"  // Method descriptor #6 ()V\n" + 
1689
			"  // Stack: 0, Locals: 1\n" + 
1690
			"  @I(enums={Color.RED},\n" + 
1688
			"  @I(enums={Color.RED},\n" + 
1691
			"      annotations={@Foo},\n" + 
1689
			"    annotations={@Foo},\n" + 
1692
			"      ints={(int) 2},\n" + 
1690
			"    ints={(int) 2},\n" + 
1693
			"      bytes={(byte) 1},\n" + 
1691
			"    bytes={(byte) 1},\n" + 
1694
			"      shorts={(short) 5},\n" + 
1692
			"    shorts={(short) 5},\n" + 
1695
			"      longs={-9223372036854775808L},\n" + 
1693
			"    longs={-9223372036854775808L},\n" + 
1696
			"      strings={\"Hi\"},\n" + 
1694
			"    strings={\"Hi\"},\n" + 
1697
			"      booleans={true},\n" + 
1695
			"    booleans={true},\n" + 
1698
			"      floats={0.0f},\n" + 
1696
			"    floats={0.0f},\n" + 
1699
			"      doubles={-0.0})\n" + 
1697
			"    doubles={-0.0})\n" + 
1700
			"  void foo();"; 
1698
			"  void foo();";
1701
1699
1702
		int index = actualOutput.indexOf(expectedOutput);
1700
		int index = actualOutput.indexOf(expectedOutput);
1703
		if (index == -1 || expectedOutput.length() == 0) {
1701
		if (index == -1 || expectedOutput.length() == 0) {
Lines 1757-1775 Link Here
1757
				ClassFileBytesDisassembler.DETAILED); 
1755
				ClassFileBytesDisassembler.DETAILED); 
1758
		
1756
		
1759
		String expectedOutput = 
1757
		String expectedOutput = 
1760
			"  // Method descriptor #6 ()V\n" + 
1761
			"  // Stack: 0, Locals: 1\n" + 
1762
			"  @I(enums=Color.RED,\n" + 
1758
			"  @I(enums=Color.RED,\n" + 
1763
			"      annotations=@Foo,\n" + 
1759
			"    annotations=@Foo,\n" + 
1764
			"      ints=(int) 2,\n" + 
1760
			"    ints=(int) 2,\n" + 
1765
			"      bytes=(byte) 1,\n" + 
1761
			"    bytes=(byte) 1,\n" + 
1766
			"      shorts=(short) 5,\n" + 
1762
			"    shorts=(short) 5,\n" + 
1767
			"      longs=-9223372036854775808L,\n" + 
1763
			"    longs=-9223372036854775808L,\n" + 
1768
			"      strings=\"Hi\",\n" + 
1764
			"    strings=\"Hi\",\n" + 
1769
			"      booleans=true,\n" + 
1765
			"    booleans=true,\n" + 
1770
			"      floats=0.0f,\n" + 
1766
			"    floats=0.0f,\n" + 
1771
			"      doubles=-0.0)\n" + 
1767
			"    doubles=-0.0)\n" + 
1772
			"  void foo();"; 
1768
			"  void foo();";
1773
			
1769
			
1774
		int index = actualOutput.indexOf(expectedOutput);
1770
		int index = actualOutput.indexOf(expectedOutput);
1775
		if (index == -1 || expectedOutput.length() == 0) {
1771
		if (index == -1 || expectedOutput.length() == 0) {
Lines 7992-7995 Link Here
7992
			"Type mismatch: cannot convert from Class<Void> to String\n" + 
7988
			"Type mismatch: cannot convert from Class<Void> to String\n" + 
7993
			"----------\n");
7989
			"----------\n");
7994
}
7990
}
7991
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
7992
public void test249() throws Exception {
7993
	this.runNegativeTest(
7994
		new String[] {
7995
			"X.java", //-----------------------------------------------------------------------
7996
			"@Zork\n" +
7997
			"public class X {}",
7998
		},
7999
		"----------\n" + 
8000
		"1. ERROR in X.java (at line 1)\n" + 
8001
		"	@Zork\n" + 
8002
		"	 ^^^^\n" + 
8003
		"Zork cannot be resolved to a type\n" + 
8004
		"----------\n",
8005
		null,
8006
		true, // flush output
8007
		null,
8008
		true, // generate output
8009
		false,
8010
		false);
8011
	String expectedOutput = "public class X {";
8012
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
8013
}
8014
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
8015
public void test250() throws Exception {
8016
	this.runNegativeTest(
8017
		new String[] {
8018
			"X.java", //-----------------------------------------------------------------------
8019
			"@Deprecated\n" +
8020
			"@Zork\n" +
8021
			"@Annot(1)\n" +
8022
			"public class X {}",
8023
			"Annot.java",
8024
			"import java.lang.annotation.Retention;\n" +
8025
			"import static java.lang.annotation.RetentionPolicy.*;\n" +
8026
			"@Retention(RUNTIME)\n" +
8027
			"@interface Annot {\n" +
8028
			"	int value() default -1;\n" +
8029
			"}"
8030
		},
8031
		"----------\n" + 
8032
		"1. ERROR in X.java (at line 2)\n" + 
8033
		"	@Zork\n" + 
8034
		"	 ^^^^\n" + 
8035
		"Zork cannot be resolved to a type\n" + 
8036
		"----------\n",
8037
		null,
8038
		true, // flush output
8039
		null,
8040
		true, // generate output
8041
		false,
8042
		false);
8043
	String expectedOutput =
8044
		"@java.lang.Deprecated\n" + 
8045
		"@Annot(value=(int) 1)\n" + 
8046
		"public class X {";
8047
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
8048
}
8049
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
8050
public void test251() throws Exception {
8051
	this.runNegativeTest(
8052
		new String[] {
8053
			"X.java", //-----------------------------------------------------------------------
8054
			"@Deprecated\n" +
8055
			"@Zork\n" +
8056
			"@Annot(1)\n" +
8057
			"public class X {}",
8058
			"Annot.java",
8059
			"import java.lang.annotation.Retention;\n" +
8060
			"import static java.lang.annotation.RetentionPolicy.*;\n" +
8061
			"@Retention(CLASS)\n" +
8062
			"@interface Annot {\n" +
8063
			"	int value() default -1;\n" +
8064
			"}"
8065
		},
8066
		"----------\n" + 
8067
		"1. ERROR in X.java (at line 2)\n" + 
8068
		"	@Zork\n" + 
8069
		"	 ^^^^\n" + 
8070
		"Zork cannot be resolved to a type\n" + 
8071
		"----------\n",
8072
		null,
8073
		true, // flush output
8074
		null,
8075
		true, // generate output
8076
		false,
8077
		false);
8078
	String expectedOutput =
8079
		"@Annot(value=(int) 1)\n" + 
8080
		"@java.lang.Deprecated\n" + 
8081
		"public class X {";
8082
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
8083
}
8084
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
8085
public void test252() throws Exception {
8086
	this.runNegativeTest(
8087
		new String[] {
8088
			"X.java", //-----------------------------------------------------------------------
8089
			"public class X {\n" +
8090
			"	public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" +
8091
			"}",
8092
			"Annot.java",
8093
			"import java.lang.annotation.Retention;\n" +
8094
			"import static java.lang.annotation.RetentionPolicy.*;\n" +
8095
			"@Retention(CLASS)\n" +
8096
			"@interface Annot {\n" +
8097
			"	int value() default -1;\n" +
8098
			"}"
8099
		},
8100
		"----------\n" + 
8101
		"1. ERROR in X.java (at line 2)\n" + 
8102
		"	public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" + 
8103
		"	                             ^^^^\n" + 
8104
		"Zork cannot be resolved to a type\n" + 
8105
		"----------\n",
8106
		null,
8107
		true, // flush output
8108
		null,
8109
		true, // generate output
8110
		false,
8111
		false);
8112
	String expectedOutput =
8113
		"    RuntimeVisibleParameterAnnotations: \n" + 
8114
		"      Number of annotations for parameter 0: 1\n" + 
8115
		"        #21 @java.lang.Deprecated(\n" + 
8116
		"        )\n" + 
8117
		"    RuntimeInvisibleParameterAnnotations: \n" + 
8118
		"      Number of annotations for parameter 0: 1\n" + 
8119
		"        #17 @Annot(\n" + 
8120
		"          #18 value=(int) 2 (constant type)\n" + 
8121
		"        )\n";
8122
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
8123
}
8124
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
8125
public void test253() throws Exception {
8126
	this.runNegativeTest(
8127
		new String[] {
8128
			"X.java", //-----------------------------------------------------------------------
8129
			"public class X {\n" +
8130
			"	public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" +
8131
			"}",
8132
			"Annot.java",
8133
			"import java.lang.annotation.Retention;\n" +
8134
			"import static java.lang.annotation.RetentionPolicy.*;\n" +
8135
			"@Retention(RUNTIME)\n" +
8136
			"@interface Annot {\n" +
8137
			"	int value() default -1;\n" +
8138
			"}"
8139
		},
8140
		"----------\n" + 
8141
		"1. ERROR in X.java (at line 2)\n" + 
8142
		"	public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" + 
8143
		"	                             ^^^^\n" + 
8144
		"Zork cannot be resolved to a type\n" + 
8145
		"----------\n",
8146
		null,
8147
		true, // flush output
8148
		null,
8149
		true, // generate output
8150
		false,
8151
		false);
8152
	String expectedOutput =
8153
		"    RuntimeVisibleParameterAnnotations: \n" + 
8154
		"      Number of annotations for parameter 0: 2\n" + 
8155
		"        #17 @java.lang.Deprecated(\n" + 
8156
		"        )\n" + 
8157
		"        #18 @Annot(\n" + 
8158
		"          #19 value=(int) 2 (constant type)\n" + 
8159
		"        )\n";
8160
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
8161
}
8162
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
8163
public void test254() throws Exception {
8164
	this.runNegativeTest(
8165
		new String[] {
8166
			"X.java", //-----------------------------------------------------------------------
8167
			"public class X {\n" +
8168
			"	public void foo(@Deprecated int j, @Zork @Annot(3) int i) {}\n" +
8169
			"}",
8170
			"Annot.java",
8171
			"import java.lang.annotation.Retention;\n" +
8172
			"import static java.lang.annotation.RetentionPolicy.*;\n" +
8173
			"@Retention(RUNTIME)\n" +
8174
			"@interface Annot {\n" +
8175
			"	int value() default -1;\n" +
8176
			"}"
8177
		},
8178
		"----------\n" + 
8179
		"1. ERROR in X.java (at line 2)\n" + 
8180
		"	public void foo(@Deprecated int j, @Zork @Annot(3) int i) {}\n" + 
8181
		"	                                    ^^^^\n" + 
8182
		"Zork cannot be resolved to a type\n" + 
8183
		"----------\n",
8184
		null,
8185
		true, // flush output
8186
		null,
8187
		true, // generate output
8188
		false,
8189
		false);
8190
	String expectedOutput =
8191
		"    RuntimeVisibleParameterAnnotations: \n" + 
8192
		"      Number of annotations for parameter 0: 1\n" + 
8193
		"        #17 @java.lang.Deprecated(\n" + 
8194
		"        )\n" + 
8195
		"      Number of annotations for parameter 1: 1\n" + 
8196
		"        #18 @Annot(\n" + 
8197
		"          #19 value=(int) 3 (constant type)\n" + 
8198
		"        )\n";
8199
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
8200
}
8201
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
8202
public void test255() throws Exception {
8203
	this.runNegativeTest(
8204
		new String[] {
8205
			"X.java", //-----------------------------------------------------------------------
8206
			"public class X {\n" +
8207
			"	public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" +
8208
			"}",
8209
			"Annot.java",
8210
			"import java.lang.annotation.Retention;\n" +
8211
			"import static java.lang.annotation.RetentionPolicy.*;\n" +
8212
			"@Retention(RUNTIME)\n" +
8213
			"@interface Annot {\n" +
8214
			"	int value() default -1;\n" +
8215
			"}"
8216
		},
8217
		"----------\n" + 
8218
		"1. ERROR in X.java (at line 2)\n" + 
8219
		"	public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" + 
8220
		"	                                          ^^\n" + 
8221
		"Type mismatch: cannot convert from String to int\n" + 
8222
		"----------\n",
8223
		null,
8224
		true, // flush output
8225
		null,
8226
		true, // generate output
8227
		false,
8228
		false);
8229
	String expectedOutput =
8230
		"    RuntimeVisibleParameterAnnotations: \n" + 
8231
		"      Number of annotations for parameter 0: 1\n" + 
8232
		"        #17 @java.lang.Deprecated(\n" + 
8233
		"        )\n" + 
8234
		"      Number of annotations for parameter 1: 1\n" + 
8235
		"        #17 @java.lang.Deprecated(\n" + 
8236
		"        )\n";
8237
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
8238
}
8239
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090
8240
public void test256() throws Exception {
8241
	this.runNegativeTest(
8242
		new String[] {
8243
			"X.java", //-----------------------------------------------------------------------
8244
			"public class X {\n" +
8245
			"	public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" +
8246
			"}",
8247
			"Annot.java",
8248
			"import java.lang.annotation.Retention;\n" +
8249
			"import static java.lang.annotation.RetentionPolicy.*;\n" +
8250
			"@Retention(CLASS)\n" +
8251
			"@interface Annot {\n" +
8252
			"	int value() default -1;\n" +
8253
			"}"
8254
		},
8255
		"----------\n" + 
8256
		"1. ERROR in X.java (at line 2)\n" + 
8257
		"	public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" + 
8258
		"	                                          ^^\n" + 
8259
		"Type mismatch: cannot convert from String to int\n" + 
8260
		"----------\n",
8261
		null,
8262
		true, // flush output
8263
		null,
8264
		true, // generate output
8265
		false,
8266
		false);
8267
	String expectedOutput =
8268
		"    RuntimeVisibleParameterAnnotations: \n" + 
8269
		"      Number of annotations for parameter 0: 1\n" + 
8270
		"        #20 @java.lang.Deprecated(\n" + 
8271
		"        )\n" + 
8272
		"      Number of annotations for parameter 1: 1\n" + 
8273
		"        #20 @java.lang.Deprecated(\n" + 
8274
		"        )";
8275
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
8276
}
7995
}
8277
}

Return to bug 191090