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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java (+45 lines)
Lines 13576-13580 Link Here
13576
			"ThisClassIsNotFinal[TYPE_REF]{ThisClassIsNotFinal, test, Ltest.ThisClassIsNotFinal;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
13576
			"ThisClassIsNotFinal[TYPE_REF]{ThisClassIsNotFinal, test, Ltest.ThisClassIsNotFinal;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
13577
			requestor.getResults());
13577
			requestor.getResults());
13578
}
13578
}
13579
/*
13580
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=246832
13581
 * To test whether camel case completion works for imported static methods 
13582
 */
13583
public void testCamelCaseStaticMethodImport() throws JavaModelException {
13584
	this.oldOptions = JavaCore.getOptions();
13585
	ICompilationUnit imported = null;
13586
	try {
13587
		Hashtable options = new Hashtable(this.oldOptions);
13588
		options.put(JavaCore.CODEASSIST_CAMEL_CASE_MATCH, JavaCore.ENABLED);
13589
		JavaCore.setOptions(options);
13590
13591
		imported = getWorkingCopy(
13592
				"/Completion/src/a/A.java",
13593
				"package a;\n" +
13594
				"public class A{\n" +
13595
				"public static void testMethodWithLongName(){}\n" +
13596
				"}}");
13597
13598
		this.wc = getWorkingCopy(
13599
				"/Completion/src/b/B.java",
13600
				"import static a.A.testMethodWithLongName;\n" +
13601
				"public class B {\n" +
13602
				"public void b() {\n" +
13603
			    "tMWLN \n" +
13604
				"}}");
13605
				
13606
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(
13607
				true);
13608
		String str = this.wc.getSource();
13609
		String completeBehind = "tMWLN";
13610
		int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
13611
		this.wc.codeComplete(cursorLocation, requestor, this.wcOwner);
13612
	
13613
		assertResults(
13614
				"testMethodWithLongName[METHOD_REF]{testMethodWithLongName(), La.A;, ()V, testMethodWithLongName, null, "
13615
				+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM_CONSTANT + R_QUALIFIED + R_NON_RESTRICTED)
13616
				+ "}", requestor.getResults());
13617
		} finally {
13618
			if (imported != null) {
13619
				imported.discardWorkingCopy();
13620
			}
13621
			JavaCore.setOptions(this.oldOptions);
13622
		}
13623
}
13579
13624
13580
}
13625
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-25 / +48 lines)
Lines 390-395 Link Here
390
		return result;
390
		return result;
391
	}
391
	}
392
	
392
	
393
	private static char[] getTypeName(TypeReference typeReference) {
394
		char[] typeName = CharOperation.concatWith(typeReference.getTypeName(), '.');
395
		int dims = typeReference.dimensions();
396
		if (dims > 0) {
397
			int length = typeName.length;
398
			int newLength = length + (dims*2);
399
			System.arraycopy(typeName, 0, typeName = new char[newLength], 0, length);
400
			for (int k = length; k < newLength; k += 2) {
401
				typeName[k] = '[';
402
				typeName[k+1] = ']';
403
			}
404
		}
405
		
406
		return typeName;
407
	}
408
	
393
	private static boolean hasStaticMemberTypes(ReferenceBinding typeBinding, SourceTypeBinding invocationType, CompilationUnitScope unitScope) {
409
	private static boolean hasStaticMemberTypes(ReferenceBinding typeBinding, SourceTypeBinding invocationType, CompilationUnitScope unitScope) {
394
		ReferenceBinding[] memberTypes = typeBinding.memberTypes();
410
		ReferenceBinding[] memberTypes = typeBinding.memberTypes();
395
		int length = memberTypes == null ? 0 : memberTypes.length;
411
		int length = memberTypes == null ? 0 : memberTypes.length;
Lines 5244-5284 Link Here
5244
					guessedType = ref.resolveType((ClassScope)scope);
5260
					guessedType = ref.resolveType((ClassScope)scope);
5245
					break;
5261
					break;
5246
			}
5262
			}
5247
		} finally {
5263
		
5248
			this.lookupEnvironment.nameEnvironment = oldNameEnvironment;
5249
		}
5250
5264
5251
		if (guessedType != null && guessedType.isValidBinding()) {
5265
			if (guessedType != null && guessedType.isValidBinding()) {
5252
			if (guessedType instanceof SourceTypeBinding) {
5266
				if (guessedType instanceof SourceTypeBinding) {
5253
				SourceTypeBinding refBinding = (SourceTypeBinding) guessedType;
5267
					SourceTypeBinding refBinding = (SourceTypeBinding) guessedType;
5254
				
5255
				refBinding.methods(); // force resolution
5256
				if (refBinding.scope == null || refBinding.scope.referenceContext == null) return null;
5257
				TypeDeclaration typeDeclaration = refBinding.scope.referenceContext;
5258
				AbstractMethodDeclaration[] methods = typeDeclaration.methods;
5259
				next : for (int i = 0; i < methods.length; i++) {
5260
					AbstractMethodDeclaration method = methods[i];
5261
					
5268
					
5262
					if (method.binding == null || !method.isConstructor()) continue next;
5269
					if (refBinding.scope == null || refBinding.scope.referenceContext == null) return null;
5263
					
5270
					
5264
					Argument[] arguments = method.arguments;
5271
					TypeDeclaration typeDeclaration = refBinding.scope.referenceContext;
5265
					int argumentsLength = arguments == null ? 0 : arguments.length;
5272
					AbstractMethodDeclaration[] methods = typeDeclaration.methods;
5266
					if (parameterCount != argumentsLength) continue next;
5267
					
5273
					
5268
					for (int j = 0; j < argumentsLength; j++) {
5274
					next : for (int i = 0; i < methods.length; i++) {
5269
						if (!CharOperation.equals(CharOperation.concatWith(arguments[j].type.getTypeName(), '.'), parameterTypes[j])) {
5275
						AbstractMethodDeclaration method = methods[i];
5270
							continue next;
5276
						
5277
						if (!method.isConstructor()) continue next;
5278
						
5279
						Argument[] arguments = method.arguments;
5280
						int argumentsLength = arguments == null ? 0 : arguments.length;
5281
						
5282
						if (parameterCount != argumentsLength) continue next;
5283
						
5284
						for (int j = 0; j < argumentsLength; j++) {
5285
							char[] argumentTypeName = getTypeName(arguments[j].type);
5286
	
5287
							if (!CharOperation.equals(argumentTypeName, parameterTypes[j])) {
5288
								continue next;
5289
							}
5271
						}
5290
						}
5291
						
5292
						refBinding.resolveTypesFor(method.binding); // force resolution
5293
						if (method.binding == null) continue next;
5294
						return getSignature(method.binding);
5272
					}
5295
					}
5273
					
5274
					return getSignature(method.binding);
5275
				}
5296
				}
5276
			}
5297
			}
5298
		} finally {
5299
			this.lookupEnvironment.nameEnvironment = oldNameEnvironment;
5277
		}
5300
		}
5278
		
5301
		
5279
		return null;
5302
		return null;
5280
	}
5303
	}
5281
5304
	
5282
	private void findConstructorsOrAnonymousTypes(
5305
	private void findConstructorsOrAnonymousTypes(
5283
			ReferenceBinding currentType,
5306
			ReferenceBinding currentType,
5284
			Scope scope,
5307
			Scope scope,
Lines 7066-7073 Link Here
7066
							if(proposeMethod && !insideAnnotationAttribute) {
7089
							if(proposeMethod && !insideAnnotationAttribute) {
7067
								MethodBinding methodBinding = (MethodBinding)binding;
7090
								MethodBinding methodBinding = (MethodBinding)binding;
7068
								if ((exactMatch && CharOperation.equals(token, methodBinding.selector)) ||
7091
								if ((exactMatch && CharOperation.equals(token, methodBinding.selector)) ||
7069
										!exactMatch && CharOperation.prefixEquals(token, methodBinding.selector)) {
7092
										!exactMatch && CharOperation.prefixEquals(token, methodBinding.selector) ||
7070
7093
										(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, methodBinding.selector))) {
7071
									findLocalMethodsFromStaticImports(
7094
									findLocalMethodsFromStaticImports(
7072
											methodBinding.selector,
7095
											methodBinding.selector,
7073
											methodBinding.declaringClass.methods(),
7096
											methodBinding.declaringClass.methods(),

Return to bug 246832