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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java (-3 / +16 lines)
Lines 1-15 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 BEA Systems, Inc.
2
 * Copyright (c) 2005, 2011 BEA Systems, Inc.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    tyeung@bea.com - initial API and implementation
9
 *    tyeung@bea.com  - initial API and implementation
10
 *    IBM Corporation - fix for bug 342757
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.classfmt;
12
package org.eclipse.jdt.internal.compiler.classfmt;
12
13
14
import org.eclipse.jdt.core.Signature;
13
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
15
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
14
16
15
class MethodInfoWithParameterAnnotations extends MethodInfoWithAnnotations {
17
class MethodInfoWithParameterAnnotations extends MethodInfoWithAnnotations {
Lines 17-23 Link Here
17
19
18
MethodInfoWithParameterAnnotations(MethodInfo methodInfo, AnnotationInfo[] annotations, AnnotationInfo[][] parameterAnnotations) {
20
MethodInfoWithParameterAnnotations(MethodInfo methodInfo, AnnotationInfo[] annotations, AnnotationInfo[][] parameterAnnotations) {
19
	super(methodInfo, annotations);
21
	super(methodInfo, annotations);
20
	this.parameterAnnotations = parameterAnnotations;
22
	if (methodInfo.isConstructor()) {
23
		int parametersCount = Signature.getParameterCount(methodInfo.getMethodDescriptor());
24
		if (parameterAnnotations.length < parametersCount) {
25
			AnnotationInfo[][] temp = new AnnotationInfo[parametersCount][];
26
			System.arraycopy(parameterAnnotations, 0, temp, 1, parameterAnnotations.length);
27
			this.parameterAnnotations = temp;
28
		} else {
29
			this.parameterAnnotations = parameterAnnotations;
30
		}
31
	} else {
32
		this.parameterAnnotations = parameterAnnotations;
33
	}
21
}
34
}
22
35
23
public IBinaryAnnotation[] getParameterAnnotations(int index) {
36
public IBinaryAnnotation[] getParameterAnnotations(int index) {
(-)model/org/eclipse/jdt/internal/core/util/Disassembler.java (-14 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 546-556 Link Here
546
				IRuntimeInvisibleParameterAnnotationsAttribute attribute = (IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute;
546
				IRuntimeInvisibleParameterAnnotationsAttribute attribute = (IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute;
547
				invisibleParameterAnnotations = attribute.getParameterAnnotations();
547
				invisibleParameterAnnotations = attribute.getParameterAnnotations();
548
				length = invisibleParameterAnnotations.length;
548
				length = invisibleParameterAnnotations.length;
549
				if (length > 0) {
550
					int parameterNamesLength = parameterNames.length;
551
					if (length < parameterNamesLength) {
552
						System.arraycopy(invisibleParameterAnnotations, 0, (invisibleParameterAnnotations = new IParameterAnnotation[parameterNamesLength]), 1, length);
553
						length = parameterNamesLength;
554
					}
555
				}
549
			}
556
			}
550
			if (runtimeVisibleParameterAnnotationsAttribute != null) {
557
			if (runtimeVisibleParameterAnnotationsAttribute != null) {
551
				IRuntimeVisibleParameterAnnotationsAttribute attribute = (IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute;
558
				IRuntimeVisibleParameterAnnotationsAttribute attribute = (IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute;
552
				visibleParameterAnnotations = attribute.getParameterAnnotations();
559
				visibleParameterAnnotations = attribute.getParameterAnnotations();
553
				length = visibleParameterAnnotations.length;
560
				length = visibleParameterAnnotations.length;
561
				if (length > 0) {
562
					int parameterNamesLength = parameterNames.length;
563
					if (length < parameterNamesLength) {
564
						System.arraycopy(visibleParameterAnnotations, 0, (visibleParameterAnnotations = new IParameterAnnotation[parameterNamesLength]), 1, length);
565
						length = parameterNamesLength;
566
					}
567
				}
554
			}
568
			}
555
			int insertionPosition = CharOperation.indexOf('(', methodHeader) + 1;
569
			int insertionPosition = CharOperation.indexOf('(', methodHeader) + 1;
556
			int start = 0;
570
			int start = 0;
Lines 561-575 Link Here
561
					stringBuffer.append(' ');
575
					stringBuffer.append(' ');
562
				}
576
				}
563
				int stringBufferSize = stringBuffer.length();
577
				int stringBufferSize = stringBuffer.length();
564
				if (runtimeVisibleParameterAnnotationsAttribute != null) {
578
				if (visibleParameterAnnotations != null) {
565
					disassembleAsModifier((IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute, stringBuffer, i, lineSeparator, tabNumber, mode);
579
					disassembleAsModifier(visibleParameterAnnotations, stringBuffer, i, lineSeparator, tabNumber, mode);
566
				}
580
				}
567
				if (runtimeInvisibleParameterAnnotationsAttribute != null) {
581
				if (invisibleParameterAnnotations != null) {
568
					if (stringBuffer.length() != stringBufferSize) {
582
					if (stringBuffer.length() != stringBufferSize) {
569
						stringBuffer.append(' ');
583
						stringBuffer.append(' ');
570
						stringBufferSize = stringBuffer.length();
584
						stringBufferSize = stringBuffer.length();
571
					}
585
					}
572
					disassembleAsModifier((IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute, stringBuffer, i, lineSeparator, tabNumber, mode);
586
					disassembleAsModifier(invisibleParameterAnnotations, stringBuffer, i, lineSeparator, tabNumber, mode);
573
				}
587
				}
574
				if (i == 0 && stringBuffer.length() != stringBufferSize) {
588
				if (i == 0 && stringBuffer.length() != stringBufferSize) {
575
					stringBuffer.append(' ');
589
					stringBuffer.append(' ');
Lines 1862-1882 Link Here
1862
		}
1876
		}
1863
	}
1877
	}
1864
1878
1865
	private void disassembleAsModifier(IRuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) {
1879
	private void disassembleAsModifier(IParameterAnnotation[] parameterAnnotations, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) {
1866
		IParameterAnnotation[] parameterAnnotations = runtimeInvisibleParameterAnnotationsAttribute.getParameterAnnotations();
1867
		if (parameterAnnotations.length > index) {
1868
			disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode);
1869
		}
1870
	}
1871
1872
	private void disassembleAsModifier(IRuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) {
1873
		IParameterAnnotation[] parameterAnnotations = runtimeVisibleParameterAnnotationsAttribute.getParameterAnnotations();
1874
		if (parameterAnnotations.length > index) {
1880
		if (parameterAnnotations.length > index) {
1875
			disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode);
1881
			disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode);
1876
		}
1882
		}
1877
	}
1883
	}
1878
1884
1879
	private void disassembleAsModifier(IParameterAnnotation parameterAnnotation, StringBuffer buffer, String lineSeparator, int tabNumber, int mode) {
1885
	private void disassembleAsModifier(IParameterAnnotation parameterAnnotation, StringBuffer buffer, String lineSeparator, int tabNumber, int mode) {
1886
		if (parameterAnnotation == null) return;
1880
		IAnnotation[] annotations = parameterAnnotation.getAnnotations();
1887
		IAnnotation[] annotations = parameterAnnotation.getAnnotations();
1881
		for (int i = 0, max = annotations.length; i < max; i++) {
1888
		for (int i = 0, max = annotations.length; i < max; i++) {
1882
			if (i > 0) {
1889
			if (i > 0) {
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-1 / +1 lines)
Lines 789-795 Link Here
789
		assertEquals("Unexpected annotations", expected, actual);
789
		assertEquals("Unexpected annotations", expected, actual);
790
	}
790
	}
791
791
792
	private void appendAnnotation(StringBuffer buffer, IAnnotation annotation) throws JavaModelException {
792
	protected void appendAnnotation(StringBuffer buffer, IAnnotation annotation) throws JavaModelException {
793
		buffer.append('@');
793
		buffer.append('@');
794
		buffer.append(annotation.getElementName());
794
		buffer.append(annotation.getElementName());
795
		IMemberValuePair[] members = annotation.getMemberValuePairs();
795
		IMemberValuePair[] members = annotation.getMemberValuePairs();
(-)src/org/eclipse/jdt/core/tests/model/ClassFileTests.java (-2 / +35 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 207-213 Link Here
207
		"import java.lang.annotation.Retention;\n" +
207
		"import java.lang.annotation.Retention;\n" +
208
		"import java.lang.annotation.RetentionPolicy;\n" + 
208
		"import java.lang.annotation.RetentionPolicy;\n" + 
209
		"@Retention(value = RetentionPolicy.CLASS)\n" + 
209
		"@Retention(value = RetentionPolicy.CLASS)\n" + 
210
		"public @interface MyAnnotation3 {}"
210
		"public @interface MyAnnotation3 {}",
211
		"test342757/X.java",
212
		"package test342757;\n" +
213
		"public class X {\n" + 
214
		"	class B {\n" + 
215
		"		public B(@Deprecated String s) {}\n" + 
216
		"	}\n" + 
217
		"}",
211
	};
218
	};
212
	addLibrary(javaProject, "lib.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5);
219
	addLibrary(javaProject, "lib.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5);
213
	this.jarRoot = javaProject.getPackageFragmentRoot(getFile("/P/lib.jar"));
220
	this.jarRoot = javaProject.getPackageFragmentRoot(getFile("/P/lib.jar"));
Lines 516-521 Link Here
516
}
523
}
517
524
518
/*
525
/*
526
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=342757
527
 */
528
public void testAnnotations26() throws JavaModelException {
529
	IType type = this.jarRoot.getPackageFragment("test342757").getClassFile("X$B.class").getType();
530
	IMethod[] methods = type.getMethods();
531
	String expected = "@java.lang.Deprecated\n";
532
	StringBuffer buffer = new StringBuffer();
533
	for (int i = 0, max = methods.length; i < max; i++) {
534
		ILocalVariable[] parameters = methods[i].getParameters();
535
		for (int j = 0, max2 = parameters.length; j < max2; j++) {
536
			IAnnotation[] annotations = parameters[j].getAnnotations();
537
			for (int n = 0; n < annotations.length; n++) {
538
				IAnnotation annotation = annotations[n];
539
				appendAnnotation(buffer, annotation);
540
				buffer.append("\n");
541
			}
542
		}
543
	}
544
	String actual = buffer.toString();
545
	if (!expected.equals(actual)) {
546
		System.out.println(displayString(actual, 2) + this.endChar);
547
	}
548
	assertEquals("Unexpected annotations", expected, actual);
549
}
550
551
/*
519
 * Ensures that no exception is thrown for a .class file name with a dot
552
 * Ensures that no exception is thrown for a .class file name with a dot
520
 * (regression test for bug 114140 assertion failed when opening a class file not not the classpath)
553
 * (regression test for bug 114140 assertion failed when opening a class file not not the classpath)
521
 */
554
 */

Return to bug 342757