### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java,v retrieving revision 1.199 diff -u -r1.199 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 6 Apr 2009 10:12:24 -0000 1.199 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 14 Apr 2009 13:50:40 -0000 @@ -15738,6 +15738,36 @@ " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", requestor.getResults()); } +public void testConstructor7() throws JavaModelException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "public class Test {\n" + + " public void foo(Object o) {\n" + + " new TestConstructor\n" + + " }\n" + + "}"); + this.workingCopies[1] = getWorkingCopy( + "/Completion/src/test/TestConstructor1.java", + "package test;"+ + "public class TestConstructor1 {\n" + + " public TestConstructor1(int[] i) {\n" + + " }\n" + + "}"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); + requestor.allowAllRequiredProposals(); + NullProgressMonitor monitor = new NullProgressMonitor(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "TestConstructor"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); + + assertResults( + "TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, ([I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" + + " TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", + requestor.getResults()); +} // https://bugs.eclipse.org/bugs/show_bug.cgi?id=127296 public void testDeprecationCheck1() throws JavaModelException { Hashtable options = JavaCore.getOptions(); #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v retrieving revision 1.392 diff -u -r1.392 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 6 Apr 2009 10:12:04 -0000 1.392 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 14 Apr 2009 13:50:44 -0000 @@ -390,6 +390,22 @@ return result; } + private static char[] getTypeName(TypeReference typeReference) { + char[] typeName = CharOperation.concatWith(typeReference.getTypeName(), '.'); + int dims = typeReference.dimensions(); + if (dims > 0) { + int length = typeName.length; + int newLength = length + (dims*2); + System.arraycopy(typeName, 0, typeName = new char[newLength], 0, length); + for (int k = length; k < newLength; k += 2) { + typeName[k] = '['; + typeName[k+1] = ']'; + } + } + + return typeName; + } + private static boolean hasStaticMemberTypes(ReferenceBinding typeBinding, SourceTypeBinding invocationType, CompilationUnitScope unitScope) { ReferenceBinding[] memberTypes = typeBinding.memberTypes(); int length = memberTypes == null ? 0 : memberTypes.length; @@ -5244,41 +5260,48 @@ guessedType = ref.resolveType((ClassScope)scope); break; } - } finally { - this.lookupEnvironment.nameEnvironment = oldNameEnvironment; - } + - if (guessedType != null && guessedType.isValidBinding()) { - if (guessedType instanceof SourceTypeBinding) { - SourceTypeBinding refBinding = (SourceTypeBinding) guessedType; - - refBinding.methods(); // force resolution - if (refBinding.scope == null || refBinding.scope.referenceContext == null) return null; - TypeDeclaration typeDeclaration = refBinding.scope.referenceContext; - AbstractMethodDeclaration[] methods = typeDeclaration.methods; - next : for (int i = 0; i < methods.length; i++) { - AbstractMethodDeclaration method = methods[i]; + if (guessedType != null && guessedType.isValidBinding()) { + if (guessedType instanceof SourceTypeBinding) { + SourceTypeBinding refBinding = (SourceTypeBinding) guessedType; - if (method.binding == null || !method.isConstructor()) continue next; + if (refBinding.scope == null || refBinding.scope.referenceContext == null) return null; - Argument[] arguments = method.arguments; - int argumentsLength = arguments == null ? 0 : arguments.length; - if (parameterCount != argumentsLength) continue next; + TypeDeclaration typeDeclaration = refBinding.scope.referenceContext; + AbstractMethodDeclaration[] methods = typeDeclaration.methods; - for (int j = 0; j < argumentsLength; j++) { - if (!CharOperation.equals(CharOperation.concatWith(arguments[j].type.getTypeName(), '.'), parameterTypes[j])) { - continue next; + next : for (int i = 0; i < methods.length; i++) { + AbstractMethodDeclaration method = methods[i]; + + if (!method.isConstructor()) continue next; + + Argument[] arguments = method.arguments; + int argumentsLength = arguments == null ? 0 : arguments.length; + + if (parameterCount != argumentsLength) continue next; + + for (int j = 0; j < argumentsLength; j++) { + char[] argumentTypeName = getTypeName(arguments[j].type); + + if (!CharOperation.equals(argumentTypeName, parameterTypes[j])) { + continue next; + } } + + refBinding.resolveTypesFor(method.binding); // force resolution + if (method.binding == null) continue next; + return getSignature(method.binding); } - - return getSignature(method.binding); } } + } finally { + this.lookupEnvironment.nameEnvironment = oldNameEnvironment; } return null; } - + private void findConstructorsOrAnonymousTypes( ReferenceBinding currentType, Scope scope,