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 / +11 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 an array of annotations for the parameter at the given index.
106
 * 
107
 * @param index the index or order of the method parameter.
108
 * @return the array of annotations for the specified parameter
109
 * @throws JavaModelException
110
 * @since 3.7
111
 */
112
IAnnotation[] getParameterAnnotations(int index) throws JavaModelException;
103
/**
113
/**
104
 * Returns the binding key for this method only if the given method is {@link #isResolved() resolved}.
114
 * 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
115
 * A binding key is a key that uniquely identifies this method. It allows access
(-)model/org/eclipse/jdt/internal/core/BinaryMethod.java (+9 lines)
Lines 61-66 Link Here
61
	IBinaryAnnotation[] binaryAnnotations = info.getAnnotations();
61
	IBinaryAnnotation[] binaryAnnotations = info.getAnnotations();
62
	return getAnnotations(binaryAnnotations, info.getTagBits());
62
	return getAnnotations(binaryAnnotations, info.getTagBits());
63
}
63
}
64
/**
65
 * @see IMethod#getParameterAnnotations(int)
66
 */
67
public IAnnotation[] getParameterAnnotations(int index) throws JavaModelException {
68
	IBinaryMethod info = (IBinaryMethod) getElementInfo();
69
	IBinaryAnnotation[] binaryAnnotations = info.getParameterAnnotations(index);
70
	return getAnnotations(binaryAnnotations, info.getTagBits());
71
}
72
64
public IMemberValuePair getDefaultValue() throws JavaModelException {
73
public IMemberValuePair getDefaultValue() throws JavaModelException {
65
	IBinaryMethod info = (IBinaryMethod) getElementInfo();
74
	IBinaryMethod info = (IBinaryMethod) getElementInfo();
66
	Object defaultValue = info.getDefaultValue();
75
	Object defaultValue = info.getDefaultValue();
(-)model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java (-1 / +38 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.paramAnnotations = acceptParamAnnotations(methodInfo.node.arguments, handle, methodInfo);
435
	}
430
	return info;
436
	return info;
431
}
437
}
438
private Annotation[][] acceptParamAnnotations(Argument[] arguments, JavaElement methodHandle, MethodInfo methodInfo) {
439
	Annotation[][] paramAnnotations = new Annotation[methodInfo.node.arguments.length][];
440
	
441
	for(int i = 0; i < methodInfo.node.arguments.length; i++) {
442
		Argument argument = methodInfo.node.arguments[i];
443
		if (methodInfo.node.arguments[i].annotations != null) {
444
			paramAnnotations[i] = new Annotation[argument.annotations.length];
445
			for (int  j = 0; j < argument.annotations.length; j++ ) {
446
				org.eclipse.jdt.internal.compiler.ast.Annotation annotation = argument.annotations[i];
447
				
448
				String nameString = new String(CharOperation.concatWith(annotation.type.getTypeName(), '.'));
449
				LocalVariable localVar = null;
450
				String paramTypeSig = JavaModelManager.getJavaModelManager().intern(Signature.createTypeSignature(methodInfo.parameterTypes[i], false));
451
				// Create a ILocalVariable on the fly with already given information as this is a pseudo-element anyway.
452
				localVar = new LocalVariable(
453
						methodHandle,
454
						new String(argument.name),
455
						argument.declarationSourceStart,
456
						argument. declarationSourceEnd,
457
						argument.sourceStart,
458
						argument.sourceEnd,
459
						paramTypeSig,
460
						argument.annotations,
461
						argument.modifiers, 
462
						true);
463
				paramAnnotations[i][j] = createAnnotation(localVar, nameString); 
464
			}
465
		}
466
	}
467
	return paramAnnotations;
468
}
432
/**
469
/**
433
 * @see ISourceElementRequestor
470
 * @see ISourceElementRequestor
434
 */
471
 */
(-)model/org/eclipse/jdt/internal/core/SourceMethod.java (-1 / +9 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 316-319 Link Here
316
		buffer.append(this.occurrenceCount);
316
		buffer.append(this.occurrenceCount);
317
	}
317
	}
318
}
318
}
319
/**
320
 * @see IMethod#getParameterAnnotations(int)
321
 */
322
public IAnnotation[] getParameterAnnotations(int index) throws JavaModelException {
323
	Object object = getElementInfo();
324
	IAnnotation[] paramAnnots = ((SourceMethodInfo) object).getParamAnnotations(index);
325
	return paramAnnots;
326
}
319
}
327
}
(-)model/org/eclipse/jdt/internal/core/SourceMethodElementInfo.java (-1 / +9 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-44 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
	/**
43
	 * Array of annotations if any associated with the parameters of this method.
44
	 */
45
	protected Annotation[][] paramAnnotations;
41
46
47
	public IAnnotation[] getParamAnnotations(int index) {
48
		return this.paramAnnotations[index];
49
	}
42
	/*
50
	/*
43
	 * The type parameters of this source type. Empty if none.
51
	 * The type parameters of this source type. Empty if none.
44
	 */
52
	 */
(-)src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java (-1 / +71 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 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 (not open) [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
}

Return to bug 334783