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

Collapse All | Expand All

(-)model/org/eclipse/jdt/core/IMethod.java (-1 / +12 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 100-105 Link Here
100
 * @return the number of parameters of this method
100
 * @return the number of parameters of this method
101
 */
101
 */
102
int getNumberOfParameters();
102
int getNumberOfParameters();
103
104
/**
105
 * Returns a two-dimensional array of annotations for this method's parameters. If the
106
 * number of parameters is zero, <code>null</code> is returned.
107
 * 
108
 * @return the array of annotations for the specified parameter
109
 * @throws JavaModelException
110
 * @since 3.7
111
 */
112
IAnnotation[][] getParameterAnnotations() throws JavaModelException;
113
103
/**
114
/**
104
 * Returns the binding key for this method only if the given method is {@link #isResolved() resolved}.
115
 * Returns the binding key for this method only if the given method is {@link #isResolved() resolved}.
105
 * A binding key is a key that uniquely identifies this method. It allows access
116
 * A binding key is a key that uniquely identifies this method. It allows access
(-)model/org/eclipse/jdt/internal/core/BinaryMethod.java (-1 / +22 lines)
Lines 11-17 Link Here
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.jdt.core.*;
14
import org.eclipse.jdt.core.Flags;
15
import org.eclipse.jdt.core.IAnnotation;
16
import org.eclipse.jdt.core.IMemberValuePair;
17
import org.eclipse.jdt.core.IMethod;
18
import org.eclipse.jdt.core.IType;
19
import org.eclipse.jdt.core.ITypeParameter;
20
import org.eclipse.jdt.core.JavaCore;
21
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.core.Signature;
15
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
24
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
17
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
25
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
Lines 61-66 Link Here
61
	IBinaryAnnotation[] binaryAnnotations = info.getAnnotations();
69
	IBinaryAnnotation[] binaryAnnotations = info.getAnnotations();
62
	return getAnnotations(binaryAnnotations, info.getTagBits());
70
	return getAnnotations(binaryAnnotations, info.getTagBits());
63
}
71
}
72
/**
73
 * @see IMethod#getParameterAnnotations()
74
 */
75
public IAnnotation[][] getParameterAnnotations() throws JavaModelException {
76
	IBinaryMethod info = (IBinaryMethod) getElementInfo();
77
	if (this.parameterTypes.length == 0) return null;
78
	IAnnotation[][] annotations = new IAnnotation[this.parameterTypes.length][];
79
	for (int i=0; i < this.parameterTypes.length; i++) {
80
		annotations[i] = getAnnotations(info.getParameterAnnotations(i), info.getTagBits());
81
	}
82
	return annotations;
83
}
84
64
public IMemberValuePair getDefaultValue() throws JavaModelException {
85
public IMemberValuePair getDefaultValue() throws JavaModelException {
65
	IBinaryMethod info = (IBinaryMethod) getElementInfo();
86
	IBinaryMethod info = (IBinaryMethod) getElementInfo();
66
	Object defaultValue = info.getDefaultValue();
87
	Object defaultValue = info.getDefaultValue();
(-)model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java (-1 / +49 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 22-27 Link Here
22
import org.eclipse.jdt.core.compiler.CharOperation;
22
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.core.compiler.IProblem;
23
import org.eclipse.jdt.core.compiler.IProblem;
24
import org.eclipse.jdt.internal.compiler.ISourceElementRequestor;
24
import org.eclipse.jdt.internal.compiler.ISourceElementRequestor;
25
import org.eclipse.jdt.internal.compiler.ast.Argument;
25
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
26
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
26
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
27
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
27
import org.eclipse.jdt.internal.compiler.ast.Expression;
28
import org.eclipse.jdt.internal.compiler.ast.Expression;
Lines 427-434 Link Here
427
			acceptAnnotation(annotation, info, handle);
428
			acceptAnnotation(annotation, info, handle);
428
		}
429
		}
429
	}
430
	}
431
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783
432
	// Process the parameter annotations from the arguments
433
	if (methodInfo.node != null && methodInfo.node.arguments != null) {
434
		info.arguments = acceptMethodParameters(methodInfo.node.arguments, handle, methodInfo);
435
	}
430
	return info;
436
	return info;
431
}
437
}
438
private LocalVariable[] acceptMethodParameters(Argument[] arguments, JavaElement methodHandle, MethodInfo methodInfo) {
439
	if (arguments == null) return null;
440
	LocalVariable[] result = new LocalVariable[arguments.length];
441
	Annotation[][] paramAnnotations = new Annotation[arguments.length][];
442
	for(int i = 0; i < arguments.length; i++) {
443
		Argument argument = arguments[i];
444
		LocalVariableInfo argumentInfo = new LocalVariableInfo();
445
		LocalVariableInfo localVarInfo = new LocalVariableInfo();
446
		localVarInfo.sourceRangeStart = argument.declarationSourceStart;
447
		localVarInfo.sourceRangeEnd = argument.declarationSourceStart;
448
		localVarInfo.nameStart = argument.sourceStart;
449
		localVarInfo.nameEnd = argument.sourceEnd;
450
		localVarInfo.isParameter = true;
451
		
452
		String paramTypeSig = JavaModelManager.getJavaModelManager().intern(Signature.createTypeSignature(methodInfo.parameterTypes[i], false));
453
		result[i] = new LocalVariable(
454
				methodHandle,
455
				new String(argument.name),
456
				argument.declarationSourceStart,
457
				argument. declarationSourceEnd,
458
				argument.sourceStart,
459
				argument.sourceEnd,
460
				paramTypeSig,
461
				argument.annotations,
462
				argument.modifiers, 
463
				true);
464
		this.newElements.put(result[i], argumentInfo);
465
		this.infoStack.push(argumentInfo);
466
		this.handleStack.push(result[i]);
467
		if (argument.annotations != null) {
468
			paramAnnotations[i] = new Annotation[argument.annotations.length];
469
			for (int  j = 0; j < argument.annotations.length; j++ ) {
470
				org.eclipse.jdt.internal.compiler.ast.Annotation annotation = argument.annotations[j];
471
				acceptAnnotation(annotation, localVarInfo, result[i]);
472
			}
473
		}
474
		this.infoStack.pop();
475
		this.handleStack.pop();
476
	}
477
	return result;
478
}
479
432
/**
480
/**
433
 * @see ISourceElementRequestor
481
 * @see ISourceElementRequestor
434
 */
482
 */
(-)model/org/eclipse/jdt/internal/core/LocalVariableInfo.java (+9 lines)
Added Link Here
1
package org.eclipse.jdt.internal.core;
2
3
public class LocalVariableInfo extends AnnotatableInfo {
4
5
	/*
6
	 * Mentions whether or not this local variable is a method parameter.
7
	 */
8
	public boolean isParameter;
9
}
(-)model/org/eclipse/jdt/internal/core/SourceMethod.java (-1 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 135-140 Link Here
135
	return info.typeParameters;
135
	return info.typeParameters;
136
}
136
}
137
137
138
public IAnnotation[][] getParameterAnnotations() throws JavaModelException {
139
	ILocalVariable[] arguments = ((SourceMethodElementInfo) getElementInfo()).arguments;
140
	if (arguments == null) return null;
141
	IAnnotation[][] annotations = new IAnnotation[arguments.length][];
142
	for (int i=0; i <arguments.length; i++) {
143
		LocalVariable argument = (LocalVariable) arguments[i];
144
		annotations[i] = new Annotation[argument.annotations.length];
145
		for (int j=0; j < argument.annotations.length; j++) {
146
			annotations[i][j] = argument.annotations[j];
147
		}
148
	}
149
	return annotations;
150
}
151
138
/**
152
/**
139
 * @see IMethod#getTypeParameterSignatures()
153
 * @see IMethod#getTypeParameterSignatures()
140
 * @since 3.0
154
 * @since 3.0
(-)model/org/eclipse/jdt/internal/core/SourceMethodElementInfo.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 38-43 Link Here
38
	 * For example, Hashtable or java.util.Hashtable.
38
	 * For example, Hashtable or java.util.Hashtable.
39
	 */
39
	 */
40
	protected char[][] exceptionTypes;
40
	protected char[][] exceptionTypes;
41
	
42
	protected ILocalVariable[] arguments;
41
43
42
	/*
44
	/*
43
	 * The type parameters of this source type. Empty if none.
45
	 * The type parameters of this source type. Empty if none.
(-)src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java (-2 / +72 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.io.IOException;
14
13
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.jdt.core.*;
16
import org.eclipse.jdt.core.*;
15
import org.eclipse.jdt.core.tests.util.Util;
17
import org.eclipse.jdt.core.tests.util.Util;
18
import org.eclipse.jdt.internal.core.LocalVariable;
16
19
17
import junit.framework.Test;
20
import junit.framework.Test;
18
21
Lines 95-101 Link Here
95
}
98
}
96
	static {
99
	static {
97
//		TESTS_NUMBERS = new int[] { 182, 183 };
100
//		TESTS_NUMBERS = new int[] { 182, 183 };
98
//		TESTS_NAMES = new String[] {"test0177"};
101
//		TESTS_NAMES = new String[] {"testParamAnnotations2"};
99
	}
102
	}
100
	public static Test suite() {
103
	public static Test suite() {
101
		return buildModelTestSuite(TypeResolveTests.class);
104
		return buildModelTestSuite(TypeResolveTests.class);
Lines 299-302 Link Here
299
		"p4.A.Inner",
302
		"p4.A.Inner",
300
		types);
303
		types);
301
}
304
}
305
/**
306
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783"
307
 */
308
public void testParamAnnotations() throws CoreException {
309
	try {
310
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5");
311
		String source = "package p;" +
312
				"public class X<T> {\n" +
313
				"  X<String> field;\n" +
314
				"	@Inject " +
315
				"	public void Test(@Default String processor) {}" +
316
				"}" +
317
				"@interface Inject{\n" +
318
				"}" +
319
				"@interface Default{\n" +
320
				"}";
321
		createFolder("/P/src/p");
322
		createFile(
323
			"/P/src/p/X.java",
324
			source
325
		);
326
		waitForAutoBuild();
327
		
328
		ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); 
329
		IJavaElement[] variable = ((ICodeAssist) unit).codeSelect(source.indexOf("processor"), "processor".length());
330
331
		assertEquals(1, variable.length);
332
		String annotationString = "@Default [in processor [in Test(String) [in X [in X.java [in p [in src [in P]]]]]]]";
333
		assertEquals(annotationString, ((LocalVariable)variable[0]).getAnnotations()[0].toString());
334
		IType type = unit.getType("X");
335
		
336
		IMethod method = type.getMethods()[0];
337
		assertEquals(annotationString, method.getParameterAnnotations()[0][0].toString());
338
	} finally {
339
		deleteProject("P");
340
	}
341
}
342
/**
343
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783"
344
 */
345
public void testParamAnnotations2() throws CoreException, IOException {
346
	try {
347
		IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5");
348
		String[] pathAndContents = new String[]{"p/X.java",
349
				"package p;" +
350
				"public class X<T> {\n" +
351
				"  X<String> field;\n" +
352
				"	@Inject " +
353
				"	public void Test(@Default String processor) {}" +
354
				"}" +
355
				"@interface Inject{\n" +
356
				"}" +
357
				"@interface Default{\n" +
358
				"}"};
359
		addLibrary(project, "lib334783.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5);
360
		
361
		waitForAutoBuild();
362
		IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783.jar"));
363
		IType type = root.getPackageFragment("p").getClassFile("X.class").getType();
364
		String annotationString = "@p.Default (not open) [in Test(java.lang.String) [in X [in X.class [in p [in lib334783.jar [in P]]]]]]";
365
		
366
		IMethod method = type.getMethods()[1];
367
		assertEquals(annotationString, method.getParameterAnnotations()[0][0].toString());
368
	} finally {
369
		deleteProject("P");
370
	}
371
}
302
}
372
}
(-)src/org/eclipse/jdt/jeview/views/JavaElement.java (-2 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
2
 * Copyright (c) 2005, 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 486-492 Link Here
486
		result.add(new JavaElementChildrenProperty(this, "PARAMETER NAMES") {
486
		result.add(new JavaElementChildrenProperty(this, "PARAMETER NAMES") {
487
			@Override
487
			@Override
488
			protected JEAttribute[] computeChildren() throws JavaModelException {
488
			protected JEAttribute[] computeChildren() throws JavaModelException {
489
				return createStrings(this, method.getParameterNames());
489
				String[] strings = method.getParameterNames();
490
				JEAttribute[] children= new JEAttribute[strings.length];
491
				for (int i= 0; i < strings.length; i++) {
492
					final int index= i;
493
					final IAnnotation[][] annotations = method.getParameterAnnotations();
494
					children[i]= new JavaElementProperty(this, null, strings[i]) {
495
						@Override
496
						public JEAttribute[] getChildren() {
497
							try {
498
								return createJavaElements(this, annotations[index]);
499
							} catch (Exception e) {
500
								return new JEAttribute[] {new Error(this, "", e)};
501
							}
502
						}
503
					};
504
				}
505
				return children;
490
			}
506
			}
491
		});
507
		});
492
		result.add(new JavaElementChildrenProperty(this, "PARAMETER TYPES") {
508
		result.add(new JavaElementChildrenProperty(this, "PARAMETER TYPES") {

Return to bug 334783