Community
Participate
Working Groups
build I20080510-2000 1) open CompletionContextTests.java 2) add the following test // https://bugs.eclipse.org/bugs/show_bug.cgi?id=226673 public void test0165() throws JavaModelException { this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy( "/Completion/src3/test/X.java", "package test;\n" + "public class X {\n" + " class Y {\n" + " }\n" + " class Y {\n" + " int var;\n" + " void foo() {\n" + " var\n" + " }\n" + " }\n" + "}"); String str = this.workingCopies[0].getSource(); int tokenStart = -1; int tokenEnd = -1; int cursorLocation = str.lastIndexOf("var") + "var".length(); CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "I"); assertResults( "completion offset="+(cursorLocation)+"\n" + "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + "completion token=null\n" + "completion token kind=TOKEN_KIND_UNKNOWN\n" + "expectedTypesSignatures=null\n" + "expectedTypesKeys=null\n" + "completion token location=UNKNOWN\n" + "visibleElements={}", result.context); } 3) run this test An UnsupportedOperationException occurs and should not. java.lang.UnsupportedOperationException: Operation only supported in extended context at org.eclipse.jdt.core.CompletionContext.getVisibleElements(CompletionContext.java:324) at org.eclipse.jdt.core.tests.model.CompletionTestsRequestor2.getContext(CompletionTestsRequestor2.java:205) at org.eclipse.jdt.core.tests.model.AbstractJavaModelCompletionTests.contextComplete0(AbstractJavaModelCompletionTests.java:138) at org.eclipse.jdt.core.tests.model.AbstractJavaModelCompletionTests.contextComplete(AbstractJavaModelCompletionTests.java:119) at org.eclipse.jdt.core.tests.model.CompletionContextTests.test0165(CompletionContextTests.java:4889) An extended context is requested by the completion requestor then the call to CompletionContext#getVisibleElements() should not launch the exception.
Created attachment 99899 [details] Proposed fix When there is no proposal or when there is a problem during completion then a minimal completion context is returned. If the completion requestor ask an extended context then this minimal context must be an extended context.
Maxime - Could you review my patch ?
Question: is there any chance, at the semantic level, that a CompletionContext ever needs to revert from extended to non-extended? I would bet not, in which case I'd prefer a no-parameter setExtended() method over the one you propose. It may make sense performance-wise to inline isExtended within CompletionContext (the public method still being part of the API, for use by other callers). Other than that, looks good.
Created attachment 99908 [details] Updated patch This patch include the previous patch with modifications suggested by Maxime. This patch: - Inline isExtended() - Replace setExtended(boolean) by setExtended()
OK for me.
Released for 3.4RC1. Test added CompletionContextTests#test0165()
Verified for 3.4RC1 using org.eclipse.jdt.core v_863