Bug 231747 - [assist] UnsupportedOperationException even when the context is extended
Summary: [assist] UnsupportedOperationException even when the context is extended
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-13 04:09 EDT by David Audel CLA
Modified: 2008-05-14 05:34 EDT (History)
2 users (show)

See Also:
maxime_daniel: review+


Attachments
Proposed fix (5.80 KB, patch)
2008-05-13 04:16 EDT, David Audel CLA
no flags Details | Diff
Updated patch (6.64 KB, patch)
2008-05-13 05:14 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Audel CLA 2008-05-13 04:09:41 EDT
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.
Comment 1 David Audel CLA 2008-05-13 04:16:30 EDT
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.
Comment 2 David Audel CLA 2008-05-13 04:26:29 EDT
Maxime - Could you review my patch ?
Comment 3 Maxime Daniel CLA 2008-05-13 04:58:22 EDT
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.
Comment 4 David Audel CLA 2008-05-13 05:14:48 EDT
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()
Comment 5 Maxime Daniel CLA 2008-05-13 05:40:07 EDT
OK for me.
Comment 6 David Audel CLA 2008-05-13 06:04:28 EDT
Released for 3.4RC1.

Test added
  CompletionContextTests#test0165()
Comment 7 Jerome Lanneluc CLA 2008-05-14 05:34:22 EDT
Verified for 3.4RC1 using org.eclipse.jdt.core v_863