### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java,v retrieving revision 1.16 diff -u -r1.16 InternalCompletionProposal.java --- codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java 7 Jul 2010 13:39:03 -0000 1.16 +++ codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java 14 Sep 2010 16:20:59 -0000 @@ -215,17 +215,17 @@ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937 // BinaryType#getMethod() creates a new instance of BinaryMethod, which is a dummy. // Instead we have to use IType#findMethods() to get a handle to the method of our interest. - IMethod method = findMethod(type, selector, paramTypeNames); - - if (this.hasNoParameterNamesFromIndex) { - IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - if (packageFragmentRoot.isArchive() || - this.completionEngine.openedBinaryTypes < getOpenedBinaryTypesThreshold()) { - SourceMapper mapper = ((JavaElement)method).getSourceMapper(); - if (mapper != null) { - try { + try { + IMethod method = findMethod(type, selector, paramTypeNames); + if (this.hasNoParameterNamesFromIndex) { + + IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); + if (packageFragmentRoot.isArchive() || + this.completionEngine.openedBinaryTypes < getOpenedBinaryTypesThreshold()) { + SourceMapper mapper = ((JavaElement)method).getSourceMapper(); + if (mapper != null) { char[][] paramNames = mapper.getMethodParameterNames(method); - + // map source and try to find parameter names if(paramNames == null) { if (!packageFragmentRoot.isArchive()) this.completionEngine.openedBinaryTypes++; @@ -236,36 +236,28 @@ } paramNames = mapper.getMethodParameterNames(method); } - + if(paramNames != null) { parameters = paramNames; } - } catch(JavaModelException e){ - //parameters == null; } } - } - } else { - try{ + } else { IBinaryMethod info = (IBinaryMethod) ((JavaElement)method).getElementInfo(); char[][] argumentNames = info.getArgumentNames(); if (argumentNames != null && argumentNames.length == length) { parameters = argumentNames; return parameters; } - } catch(JavaModelException e){ - //parameters == null; - } - - try{ + parameters = new char[length][]; String[] params = method.getParameterNames(); for(int i = 0; i< length ; i++){ parameters[i] = params[i].toCharArray(); } - } catch(JavaModelException e){ - parameters = null; } + } catch(JavaModelException e){ + parameters = null; } } @@ -313,8 +305,8 @@ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937 // BinaryType#getMethod() creates a new instance of BinaryMethod, which is a dummy. // Instead we have to use IType#findMethods() to get a handle to the method of our interest. - IMethod method = findMethod(type, selector, paramTypeNames); try{ + IMethod method = findMethod(type, selector, paramTypeNames); parameters = new char[length][]; String[] params = method.getParameterNames(); for(int i = 0; i< length ; i++){ @@ -333,19 +325,20 @@ return parameters; } - private IMethod findMethod(IType type, char[] selector, char[][] paramTypeNames) { + private IMethod findMethod(IType type, char[] selector, char[][] paramTypeNames) throws JavaModelException { IMethod method = null; int startingIndex = 0; String[] args; IType enclosingType = type.getDeclaringType(); - // If the method is a constructor of an inner type, add the enclosing type as an - // additional parameter to the constructor. - if (enclosingType != null && CharOperation.equals(type.getElementName().toCharArray(), selector)) { + // If the method is a constructor of a non-static inner type, add the enclosing type as an + // additional parameter to the constructor + if (enclosingType != null + && CharOperation.equals(type.getElementName().toCharArray(), selector) + && !Flags.isStatic(type.getFlags())) { args = new String[paramTypeNames.length+1]; startingIndex = 1; args[0] = Signature.createTypeSignature(enclosingType.getFullyQualifiedName(), true); - } - else { + } else { args = new String[paramTypeNames.length]; } int length = args.length; #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.223 diff -u -r1.223 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 18 Aug 2010 14:13:45 -0000 1.223 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 14 Sep 2010 16:21:02 -0000 @@ -20,10 +20,12 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.CompletionContext; import org.eclipse.jdt.core.CompletionProposal; import org.eclipse.jdt.core.CompletionRequestor; import org.eclipse.jdt.core.IClassFile; +import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; @@ -37,7 +39,7 @@ public class CompletionTests extends AbstractJavaModelCompletionTests { static { -// TESTS_NAMES = new String[] { "testDeprecationCheck17"}; +// TESTS_NAMES = new String[] { "testCompletionMethodDeclaration17"}; } public static Test suite() { return buildModelTestSuite(CompletionTests.class); @@ -12605,6 +12607,41 @@ "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) + "}", requestor.getResults()); } +public void testCompletionMethodDeclaration17() throws JavaModelException { + // add the needed jar on the classpath + // replace JCL_LIB with JCL15_LIB, and JCL_SRC with JCL15_SRC + IClasspathEntry[] classpath = this.currentProject.getRawClasspath(); + try { + final int length = classpath.length; + IClasspathEntry[] newClasspath = new IClasspathEntry[length + 1]; + System.arraycopy(classpath, 0, newClasspath, 1, length); + newClasspath[0] = JavaCore.newLibraryEntry(new Path("/Completion/bug325270.jar"), null, null); + this.currentProject.setRawClasspath(newClasspath, null); + + this.wc = getWorkingCopy( + "/Completion/src/CompletionMethodDeclaration17.java", + "class CompletionMethodDeclaration17 {\n" + + " void test() {\n" + + " new pkg.Foo1.Bar1(\n" + + " }\n" + + "}" + + "}"); + + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.wc.getSource(); + String completeBehind = "new pkg.Foo1.Bar1("; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length(); + this.wc.codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "Bar1[METHOD_REF]{, Lpkg.Foo1$Bar1;, (II)V, Bar1, (a, b), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED)+ "}\n" + + "Foo1.Bar1[ANONYMOUS_CLASS_DECLARATION]{, Lpkg.Foo1$Bar1;, (II)V, null, (a, b), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED)+"}", + requestor.getResults()); + } finally { + this.currentProject.setRawClasspath(classpath, null); + } +} public void testCompletionMethodDeclaration2() throws JavaModelException { ICompilationUnit superClass = null; try {