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

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java (-30 / +23 lines)
Lines 215-231 Link Here
215
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937
215
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937
216
			// BinaryType#getMethod() creates a new instance of BinaryMethod, which is a dummy.
216
			// BinaryType#getMethod() creates a new instance of BinaryMethod, which is a dummy.
217
			// Instead we have to use IType#findMethods() to get a handle to the method of our interest.
217
			// Instead we have to use IType#findMethods() to get a handle to the method of our interest.
218
			IMethod method = findMethod(type, selector, paramTypeNames);
218
			try {
219
			
219
				IMethod method = findMethod(type, selector, paramTypeNames);
220
			if (this.hasNoParameterNamesFromIndex) {
220
				if (this.hasNoParameterNamesFromIndex) {
221
				IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
221
222
				if (packageFragmentRoot.isArchive() ||
222
					IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
223
						this.completionEngine.openedBinaryTypes < getOpenedBinaryTypesThreshold()) {
223
					if (packageFragmentRoot.isArchive() ||
224
					SourceMapper mapper = ((JavaElement)method).getSourceMapper();
224
							this.completionEngine.openedBinaryTypes < getOpenedBinaryTypesThreshold()) {
225
					if (mapper != null) {
225
						SourceMapper mapper = ((JavaElement)method).getSourceMapper();
226
						try {
226
						if (mapper != null) {
227
							char[][] paramNames = mapper.getMethodParameterNames(method);
227
							char[][] paramNames = mapper.getMethodParameterNames(method);
228
					
228
229
							// map source and try to find parameter names
229
							// map source and try to find parameter names
230
							if(paramNames == null) {
230
							if(paramNames == null) {
231
								if (!packageFragmentRoot.isArchive()) this.completionEngine.openedBinaryTypes++;
231
								if (!packageFragmentRoot.isArchive()) this.completionEngine.openedBinaryTypes++;
Lines 236-271 Link Here
236
								}
236
								}
237
								paramNames = mapper.getMethodParameterNames(method);
237
								paramNames = mapper.getMethodParameterNames(method);
238
							}
238
							}
239
							
239
240
							if(paramNames != null) {
240
							if(paramNames != null) {
241
								parameters = paramNames;
241
								parameters = paramNames;
242
							}
242
							}
243
						} catch(JavaModelException e){
244
							//parameters == null;
245
						}
243
						}
246
					}
244
					}
247
				}
245
				} else {
248
			} else {
249
				try{
250
					IBinaryMethod info = (IBinaryMethod) ((JavaElement)method).getElementInfo();
246
					IBinaryMethod info = (IBinaryMethod) ((JavaElement)method).getElementInfo();
251
					char[][] argumentNames = info.getArgumentNames();
247
					char[][] argumentNames = info.getArgumentNames();
252
					if (argumentNames != null && argumentNames.length == length) {
248
					if (argumentNames != null && argumentNames.length == length) {
253
						parameters = argumentNames;
249
						parameters = argumentNames;
254
						return parameters;
250
						return parameters;
255
					}
251
					}
256
				} catch(JavaModelException e){
252
257
					//parameters == null;
258
				}
259
				
260
				try{
261
					parameters = new char[length][];
253
					parameters = new char[length][];
262
					String[] params = method.getParameterNames();
254
					String[] params = method.getParameterNames();
263
					for(int i = 0;	i< length ; i++){
255
					for(int i = 0;	i< length ; i++){
264
						parameters[i] = params[i].toCharArray();
256
						parameters[i] = params[i].toCharArray();
265
					}
257
					}
266
				} catch(JavaModelException e){
267
					parameters = null;
268
				}
258
				}
259
			} catch(JavaModelException e){
260
				parameters = null;
269
			}
261
			}
270
		}
262
		}
271
263
Lines 313-320 Link Here
313
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937
305
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937
314
			// BinaryType#getMethod() creates a new instance of BinaryMethod, which is a dummy.
306
			// BinaryType#getMethod() creates a new instance of BinaryMethod, which is a dummy.
315
			// Instead we have to use IType#findMethods() to get a handle to the method of our interest.
307
			// Instead we have to use IType#findMethods() to get a handle to the method of our interest.
316
			IMethod method = findMethod(type, selector, paramTypeNames);
317
			try{
308
			try{
309
				IMethod method = findMethod(type, selector, paramTypeNames);
318
				parameters = new char[length][];
310
				parameters = new char[length][];
319
				String[] params = method.getParameterNames();
311
				String[] params = method.getParameterNames();
320
				for(int i = 0;	i< length ; i++){
312
				for(int i = 0;	i< length ; i++){
Lines 333-351 Link Here
333
		return parameters;
325
		return parameters;
334
	}
326
	}
335
327
336
	private IMethod findMethod(IType type, char[] selector, char[][] paramTypeNames) {
328
	private IMethod findMethod(IType type, char[] selector, char[][] paramTypeNames) throws JavaModelException {
337
		IMethod method = null;
329
		IMethod method = null;
338
		int startingIndex = 0;
330
		int startingIndex = 0;
339
		String[] args;
331
		String[] args;
340
		IType enclosingType = type.getDeclaringType();
332
		IType enclosingType = type.getDeclaringType();
341
		// If the method is a constructor of an inner type, add the enclosing type as an 
333
		// If the method is a constructor of a non-static inner type, add the enclosing type as an 
342
		// additional parameter to the constructor.
334
		// additional parameter to the constructor
343
		if (enclosingType != null && CharOperation.equals(type.getElementName().toCharArray(), selector)) {
335
		if (enclosingType != null
336
				&& CharOperation.equals(type.getElementName().toCharArray(), selector)
337
				&& !Flags.isStatic(type.getFlags())) {
344
			args = new String[paramTypeNames.length+1];
338
			args = new String[paramTypeNames.length+1];
345
			startingIndex = 1;
339
			startingIndex = 1;
346
			args[0] = Signature.createTypeSignature(enclosingType.getFullyQualifiedName(), true);
340
			args[0] = Signature.createTypeSignature(enclosingType.getFullyQualifiedName(), true);
347
		}
341
		} else {
348
		else {
349
			args = new String[paramTypeNames.length];
342
			args = new String[paramTypeNames.length];
350
		}
343
		}
351
		int length = args.length;
344
		int length = args.length;
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (-1 / +38 lines)
Lines 20-29 Link Here
20
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.core.runtime.OperationCanceledException;
23
import org.eclipse.core.runtime.Path;
23
import org.eclipse.jdt.core.CompletionContext;
24
import org.eclipse.jdt.core.CompletionContext;
24
import org.eclipse.jdt.core.CompletionProposal;
25
import org.eclipse.jdt.core.CompletionProposal;
25
import org.eclipse.jdt.core.CompletionRequestor;
26
import org.eclipse.jdt.core.CompletionRequestor;
26
import org.eclipse.jdt.core.IClassFile;
27
import org.eclipse.jdt.core.IClassFile;
28
import org.eclipse.jdt.core.IClasspathEntry;
27
import org.eclipse.jdt.core.ICompilationUnit;
29
import org.eclipse.jdt.core.ICompilationUnit;
28
import org.eclipse.jdt.core.IJavaProject;
30
import org.eclipse.jdt.core.IJavaProject;
29
import org.eclipse.jdt.core.JavaCore;
31
import org.eclipse.jdt.core.JavaCore;
Lines 37-43 Link Here
37
public class CompletionTests extends AbstractJavaModelCompletionTests {
39
public class CompletionTests extends AbstractJavaModelCompletionTests {
38
40
39
static {
41
static {
40
//	TESTS_NAMES = new String[] { "testDeprecationCheck17"};
42
//	TESTS_NAMES = new String[] { "testCompletionMethodDeclaration17"};
41
}
43
}
42
public static Test suite() {
44
public static Test suite() {
43
	return buildModelTestSuite(CompletionTests.class);
45
	return buildModelTestSuite(CompletionTests.class);
Lines 12605-12610 Link Here
12605
			"doSomething[METHOD_DECLARATION]{protected other.SuperClass2.Sub doSomething(), Lother.SuperClass2;, ()Lother.SuperClass2$Sub;, doSomething, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_METHOD_OVERIDE + R_NON_RESTRICTED) + "}",
12607
			"doSomething[METHOD_DECLARATION]{protected other.SuperClass2.Sub doSomething(), Lother.SuperClass2;, ()Lother.SuperClass2$Sub;, doSomething, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_METHOD_OVERIDE + R_NON_RESTRICTED) + "}",
12606
			requestor.getResults());
12608
			requestor.getResults());
12607
}
12609
}
12610
public void testCompletionMethodDeclaration17() throws JavaModelException {
12611
	// add the needed jar on the classpath
12612
	// replace JCL_LIB with JCL15_LIB, and JCL_SRC with JCL15_SRC
12613
	IClasspathEntry[] classpath = this.currentProject.getRawClasspath();
12614
	try {
12615
		final int length = classpath.length;
12616
		IClasspathEntry[] newClasspath = new IClasspathEntry[length + 1];
12617
		System.arraycopy(classpath, 0, newClasspath, 1, length);
12618
		newClasspath[0] = JavaCore.newLibraryEntry(new Path("/Completion/bug325270.jar"), null, null);
12619
		this.currentProject.setRawClasspath(newClasspath, null);
12620
	
12621
		this.wc = getWorkingCopy(
12622
				"/Completion/src/CompletionMethodDeclaration17.java",
12623
				"class CompletionMethodDeclaration17 {\n" + 
12624
				"	void test() {\n" + 
12625
				"		new pkg.Foo1.Bar1(\n" + 
12626
				"	}\n" + 
12627
				"}" +
12628
		"}");
12629
	
12630
	
12631
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
12632
		String str = this.wc.getSource();
12633
		String completeBehind = "new pkg.Foo1.Bar1(";
12634
		int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
12635
		this.wc.codeComplete(cursorLocation, requestor, this.wcOwner);
12636
	
12637
		assertResults(
12638
				"Bar1[METHOD_REF<CONSTRUCTOR>]{, Lpkg.Foo1$Bar1;, (II)V, Bar1, (a, b), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED)+ "}\n" +
12639
				"Foo1.Bar1[ANONYMOUS_CLASS_DECLARATION]{, Lpkg.Foo1$Bar1;, (II)V, null, (a, b), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED)+"}",
12640
				requestor.getResults());
12641
	} finally {
12642
		this.currentProject.setRawClasspath(classpath, null);
12643
	}
12644
}
12608
public void testCompletionMethodDeclaration2() throws JavaModelException {
12645
public void testCompletionMethodDeclaration2() throws JavaModelException {
12609
	ICompilationUnit superClass = null;
12646
	ICompilationUnit superClass = null;
12610
	try {
12647
	try {

Return to bug 325270