View | Details | Raw Unified | Return to bug 82712
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java (+60 lines)
Lines 11629-11634 Link Here
11629
			"ZTest3[TYPE_REF]{ZTest3, test, Ltest.ZTest3;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_INTERFACE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
11629
			"ZTest3[TYPE_REF]{ZTest3, test, Ltest.ZTest3;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_INTERFACE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
11630
			requestor.getResults());
11630
			requestor.getResults());
11631
}
11631
}
11632
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=82712
11633
public void test0362() throws JavaModelException {
11634
	this.workingCopies = new ICompilationUnit[2];
11635
	this.workingCopies[0] = getWorkingCopy(
11636
		"/Completion/src/test/Test.java",
11637
		"package test;\n"+
11638
		"import static test.util.Math.*;\n"+
11639
		"public class Test {\n"+
11640
		"	void foo() {\n"+
11641
		"	  abs();\n"+
11642
		"	}\n"+
11643
		"}\n");
11644
	
11645
	this.workingCopies[1] = getWorkingCopy(
11646
		"/Completion/src/test/util/Math.java",
11647
		"package test.util;\n"+
11648
		"public class Math {\n"+
11649
		"	public static int abs(int i) {return null;}\n"+
11650
		"}n");
11651
11652
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
11653
	String str = this.workingCopies[0].getSource();
11654
	String completeBehind = "abs(";
11655
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
11656
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
11657
11658
	assertResults(
11659
			"abs[METHOD_REF]{, Ltest.util.Math;, (I)I, abs, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
11660
			requestor.getResults());
11661
}
11662
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=82712
11663
public void test0363() throws JavaModelException {
11664
	this.workingCopies = new ICompilationUnit[2];
11665
	this.workingCopies[0] = getWorkingCopy(
11666
		"/Completion/src/test/Test.java",
11667
		"package test;\n"+
11668
		"import static test.util.Math.abs;\n"+
11669
		"public class Test {\n"+
11670
		"	void foo() {\n"+
11671
		"	  abs();\n"+
11672
		"	}\n"+
11673
		"}\n");
11674
	
11675
	this.workingCopies[1] = getWorkingCopy(
11676
		"/Completion/src/test/util/Math.java",
11677
		"package test.util;\n"+
11678
		"public class Math {\n"+
11679
		"	public static int abs(int i) {return null;}\n"+
11680
		"}n");
11681
11682
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
11683
	String str = this.workingCopies[0].getSource();
11684
	String completeBehind = "abs(";
11685
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
11686
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
11687
11688
	assertResults(
11689
			"abs[METHOD_REF]{, Ltest.util.Math;, (I)I, abs, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
11690
			requestor.getResults());
11691
}
11632
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=153130
11692
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=153130
11633
public void testEC001() throws JavaModelException {
11693
public void testEC001() throws JavaModelException {
11634
	this.workingCopies = new ICompilationUnit[1];
11694
	this.workingCopies = new ICompilationUnit[1];
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-104 / +171 lines)
Lines 1468-1474 Link Here
1468
			this.completionToken = messageSend.selector;
1468
			this.completionToken = messageSend.selector;
1469
			if (qualifiedBinding == null) {
1469
			if (qualifiedBinding == null) {
1470
				if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1470
				if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1471
					findImplicitMessageSends(this.completionToken, argTypes, scope, messageSend, scope);
1471
					ObjectVector methodsFound = new ObjectVector();
1472
					
1473
					findImplicitMessageSends(this.completionToken, argTypes, scope, messageSend, scope, methodsFound);
1474
					
1475
					findLocalMethodsFromStaticImports(
1476
							this.completionToken,
1477
							scope,
1478
							messageSend,
1479
							scope,
1480
							true,
1481
							methodsFound,
1482
							true);
1472
				}
1483
				}
1473
			} else  if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1484
			} else  if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1474
				findMethods(
1485
				findMethods(
Lines 1952-1958 Link Here
1952
1963
1953
				if (qualifiedBinding == null) {
1964
				if (qualifiedBinding == null) {
1954
					if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1965
					if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1955
						findImplicitMessageSends(this.completionToken, argTypes, scope, messageSend, scope);
1966
						findImplicitMessageSends(this.completionToken, argTypes, scope, messageSend, scope, new ObjectVector());
1956
					}
1967
					}
1957
				} else if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1968
				} else if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
1958
					findMethods(
1969
					findMethods(
Lines 5698-5711 Link Here
5698
		TypeBinding[] argTypes,
5709
		TypeBinding[] argTypes,
5699
		Scope scope,
5710
		Scope scope,
5700
		InvocationSite invocationSite,
5711
		InvocationSite invocationSite,
5701
		Scope invocationScope) {
5712
		Scope invocationScope,
5713
		ObjectVector methodsFound) {
5702
5714
5703
		if (token == null)
5715
		if (token == null)
5704
			return;
5716
			return;
5705
5717
5706
		boolean staticsOnly = false;
5718
		boolean staticsOnly = false;
5707
		// need to know if we're in a static context (or inside a constructor)
5719
		// need to know if we're in a static context (or inside a constructor)
5708
		ObjectVector methodsFound = new ObjectVector();
5709
5720
5710
		done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
5721
		done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
5711
5722
Lines 6427-6436 Link Here
6427
	}
6438
	}
6428
6439
6429
	// Helper method for findMethods(char[], TypeBinding[], ReferenceBinding, Scope, ObjectVector, boolean, boolean, boolean)
6440
	// Helper method for findMethods(char[], TypeBinding[], ReferenceBinding, Scope, ObjectVector, boolean, boolean, boolean)
6430
	private void findLocalMethodsOfStaticImports(
6441
	private void findLocalMethodsFromStaticImports(
6431
		char[] methodName,
6442
		char[] methodName,
6432
		MethodBinding[] methods,
6443
		MethodBinding[] methods,
6433
		Scope scope,
6444
		Scope scope,
6445
		boolean exactMatch,
6434
		ObjectVector methodsFound,
6446
		ObjectVector methodsFound,
6435
		ReferenceBinding receiverType,
6447
		ReferenceBinding receiverType,
6436
		InvocationSite invocationSite) {
6448
		InvocationSite invocationSite) {
Lines 6492-6504 Link Here
6492
			int previousStartPosition = this.startPosition;
6504
			int previousStartPosition = this.startPosition;
6493
			int previousTokenStart = this.tokenStart;
6505
			int previousTokenStart = this.tokenStart;
6494
			
6506
			
6495
			// nothing to insert - do not want to replace the existing selector & arguments
6507
			if (!exactMatch) {
6496
			if (this.source != null
6508
				if (this.source != null
6497
				&& this.source.length > this.endPosition
6509
					&& this.source.length > this.endPosition
6498
				&& this.source[this.endPosition] == '(') {
6510
					&& this.source[this.endPosition] == '(') {
6499
				completion = method.selector;
6511
					completion = method.selector;
6512
				} else {
6513
					completion = CharOperation.concat(method.selector, new char[] { '(', ')' });
6514
				}
6500
			} else {
6515
			} else {
6501
				completion = CharOperation.concat(method.selector, new char[] { '(', ')' });
6516
				this.startPosition = this.endPosition;
6517
				this.tokenStart = this.tokenEnd;
6502
			}
6518
			}
6503
			
6519
			
6504
			int relevance = computeBaseRelevance();
6520
			int relevance = computeBaseRelevance();
Lines 8280-8371 Link Here
8280
				currentScope = currentScope.parent;
8296
				currentScope = currentScope.parent;
8281
			}
8297
			}
8282
			
8298
			
8283
			// search in static import
8299
			findFieldsAndMethodsFromStaticImports(
8284
			ImportBinding[] importBindings = scope.compilationUnitScope().imports;
8300
					token,
8285
			for (int i = 0; i < importBindings.length; i++) {
8301
					scope,
8286
				ImportBinding importBinding = importBindings[i];
8302
					invocationSite,
8287
				if(importBinding.isValidBinding() && importBinding.isStatic()) {
8303
					invocationScope,
8288
					Binding binding = importBinding.resolvedImport;
8304
					false,
8289
					if(binding != null && binding.isValidBinding()) {
8305
					insideAnnotationAttribute,
8290
						if(importBinding.onDemand) {
8306
					localsFound,
8291
							if((binding.kind() & Binding.TYPE) != 0) {
8307
					fieldsFound,
8292
								if(proposeField) {
8308
					methodsFound,
8309
					proposeField,
8310
					proposeMethod);
8311
			
8312
			if (this.assistNodeInJavadoc == 0) {
8313
				// search in favorites import
8314
				findFieldsAndMethodsFromFavorites(
8315
						token,
8316
						scope,
8317
						invocationSite,
8318
						invocationScope,
8319
						localsFound,
8320
						fieldsFound,
8321
						methodsFound);
8322
			}
8323
		}
8324
	}
8325
8326
	private void findLocalMethodsFromStaticImports(
8327
			char[] token,
8328
			Scope scope,
8329
			InvocationSite invocationSite,
8330
			Scope invocationScope,
8331
			boolean exactMatch,
8332
			ObjectVector methodsFound,
8333
			boolean proposeMethod) {
8334
		this.findFieldsAndMethodsFromStaticImports(
8335
				token,
8336
				scope, 
8337
				invocationSite,
8338
				invocationScope,
8339
				exactMatch,
8340
				false,
8341
				new ObjectVector(),
8342
				new ObjectVector(),
8343
				methodsFound,
8344
				false,
8345
				proposeMethod);
8346
	}
8347
	
8348
	private void findFieldsAndMethodsFromStaticImports(
8349
			char[] token,
8350
			Scope scope,
8351
			InvocationSite invocationSite,
8352
			Scope invocationScope,
8353
			boolean exactMatch,
8354
			boolean insideAnnotationAttribute,
8355
			ObjectVector localsFound,
8356
			ObjectVector fieldsFound,
8357
			ObjectVector methodsFound,
8358
			boolean proposeField,
8359
			boolean proposeMethod) {
8360
		// search in static import
8361
		ImportBinding[] importBindings = scope.compilationUnitScope().imports;
8362
		for (int i = 0; i < importBindings.length; i++) {
8363
			ImportBinding importBinding = importBindings[i];
8364
			if(importBinding.isValidBinding() && importBinding.isStatic()) {
8365
				Binding binding = importBinding.resolvedImport;
8366
				if(binding != null && binding.isValidBinding()) {
8367
					if(importBinding.onDemand) {
8368
						if((binding.kind() & Binding.TYPE) != 0) {
8369
							if(proposeField) {
8370
								findFields(
8371
									token,
8372
									(ReferenceBinding)binding,
8373
									scope,
8374
									fieldsFound,
8375
									localsFound,
8376
									true,
8377
									invocationSite,
8378
									invocationScope,
8379
									true,
8380
									false,
8381
									null,
8382
									null,
8383
									null,
8384
									false,
8385
									null,
8386
									-1,
8387
									-1);
8388
							}
8389
							if(proposeMethod && !insideAnnotationAttribute) {
8390
								findMethods(
8391
									token,
8392
									null,
8393
									null,
8394
									(ReferenceBinding)binding,
8395
									scope,
8396
									methodsFound,
8397
									true,
8398
									exactMatch,
8399
									false,
8400
									invocationSite,
8401
									invocationScope,
8402
									true,
8403
									false,
8404
									false,
8405
									null,
8406
									null,
8407
									null,
8408
									false,
8409
									null,
8410
									-1,
8411
									-1);
8412
							}
8413
						}
8414
					} else {
8415
						if ((binding.kind() & Binding.FIELD) != 0) {
8416
							if(proposeField) {
8293
									findFields(
8417
									findFields(
8294
										token,
8418
											token,
8295
										(ReferenceBinding)binding,
8419
											new FieldBinding[]{(FieldBinding)binding},
8296
										scope,
8420
											scope,
8297
										fieldsFound,
8421
											fieldsFound,
8298
										localsFound,
8422
											localsFound,
8299
										true,
8423
											true,
8300
										invocationSite,
8424
											((FieldBinding)binding).declaringClass,
8301
										invocationScope,
8425
											invocationSite,
8302
										true,
8426
											invocationScope,
8303
										false,
8427
											true,
8304
										null,
8428
											false,
8305
										null,
8429
											null,
8306
										null,
8430
											null,
8307
										false,
8431
											null,
8308
										null,
8432
											false,
8309
										-1,
8433
											null,
8310
										-1);
8434
											-1,
8311
								}
8435
											-1);
8312
								if(proposeMethod && !insideAnnotationAttribute) {
8313
									findMethods(
8314
										token,
8315
										null,
8316
										null,
8317
										(ReferenceBinding)binding,
8318
										scope,
8319
										methodsFound,
8320
										true,
8321
										false,
8322
										false,
8323
										invocationSite,
8324
										invocationScope,
8325
										true,
8326
										false,
8327
										false,
8328
										null,
8329
										null,
8330
										null,
8331
										false,
8332
										null,
8333
										-1,
8334
										-1);
8335
								}
8336
							}
8436
							}
8337
						} else {
8437
						} else if ((binding.kind() & Binding.METHOD) != 0) {
8338
							if ((binding.kind() & Binding.FIELD) != 0) {
8438
							if(proposeMethod && !insideAnnotationAttribute) {
8339
								if(proposeField) {
8439
								MethodBinding methodBinding = (MethodBinding)binding;
8340
										findFields(
8440
								if ((exactMatch && CharOperation.equals(token, methodBinding.selector)) ||
8341
												token,
8441
										!exactMatch && CharOperation.prefixEquals(token, methodBinding.selector)) {
8342
												new FieldBinding[]{(FieldBinding)binding},
8442
									
8343
												scope,
8443
									findLocalMethodsFromStaticImports(
8344
												fieldsFound,
8345
												localsFound,
8346
												true,
8347
												((FieldBinding)binding).declaringClass,
8348
												invocationSite,
8349
												invocationScope,
8350
												true,
8351
												false,
8352
												null,
8353
												null,
8354
												null,
8355
												false,
8356
												null,
8357
												-1,
8358
												-1);
8359
								}
8360
							} else if ((binding.kind() & Binding.METHOD) != 0) {
8361
								if(proposeMethod && !insideAnnotationAttribute) {
8362
									MethodBinding methodBinding = (MethodBinding)binding;
8363
									if(CharOperation.prefixEquals(token, methodBinding.selector))
8364
										
8365
									findLocalMethodsOfStaticImports(
8366
											methodBinding.selector,
8444
											methodBinding.selector,
8367
											methodBinding.declaringClass.methods(),
8445
											methodBinding.declaringClass.methods(),
8368
											scope,
8446
											scope,
8447
											exactMatch,
8369
											methodsFound,
8448
											methodsFound,
8370
											methodBinding.declaringClass,
8449
											methodBinding.declaringClass,
8371
											invocationSite);
8450
											invocationSite);
Lines 8375-8392 Link Here
8375
					}
8454
					}
8376
				}
8455
				}
8377
			}
8456
			}
8378
			
8379
			if (this.assistNodeInJavadoc == 0) {
8380
				// search in favorites import
8381
				findFieldsAndMethodsFromFavorites(
8382
						token,
8383
						scope,
8384
						invocationSite,
8385
						invocationScope,
8386
						localsFound,
8387
						fieldsFound,
8388
						methodsFound);
8389
			}
8390
		}
8457
		}
8391
	}
8458
	}
8392
	private char[][] findVariableFromUnresolvedReference(LocalDeclaration variable, BlockScope scope, final char[][] discouragedNames) {
8459
	private char[][] findVariableFromUnresolvedReference(LocalDeclaration variable, BlockScope scope, final char[][] discouragedNames) {

Return to bug 82712