Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 338789 - [1.7][assist] No proposal inside a multi catch statement after '|'
Summary: [1.7][assist] No proposal inside a multi catch statement after '|'
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-03 06:54 EST by Ayushman Jain CLA
Modified: 2011-08-05 02:54 EDT (History)
3 users (show)

See Also:
satyam.kandula: review+


Attachments
patch under test (2.90 KB, patch)
2011-03-28 11:14 EDT, Ayushman Jain CLA
no flags Details | Diff
proposed fix + tests (20.80 KB, patch)
2011-03-29 07:16 EDT, Ayushman Jain CLA
no flags Details | Diff
Another patch (1.43 KB, text/plain)
2011-03-30 00:53 EDT, Satyam Kandula CLA
no flags Details
proposed fix v2.0 + tests (21.40 KB, patch)
2011-03-30 06:40 EDT, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2011-03-03 06:54:52 EST
BETA_JAVA7

Currently, we dont get any proposals from content assist inside the catch expression of a multi catch statement. Eg:

public class Test {
	void foo() {
		try {
		
		   boo(1);
		   boo(2);
		} catch (I[CTRL-SPACE]
	}
	
	int boo(int i) throws IndexOutOfBoundsException, IllegalArgumentException{
		if (i ==1 )
			throw new IndexOutOfBoundsException();
		if (i == 2)
			throw new IllegalArgumentException();
		return 1;
	}
}

Expected proposals: Exception types I*
Comment 1 Ayushman Jain CLA 2011-03-28 11:14:05 EDT
Currently the above reported case works fine in BETA_JAVA7, but following does not:

public class Test {
    void foo() {
        try {

           boo(1);
           boo(2);
        } catch (IndexOutOfBoundsException | I[CTRL-SPACE]
    }

    int boo(int i) throws IndexOutOfBoundsException, IllegalArgumentException{
        if (i ==1 )
            throw new IndexOutOfBoundsException();
        if (i == 2)
            throw new IllegalArgumentException();
        return 1;
    }
}

This is because content assist looks for K_BETWEEN_CATCH_AND_RIGHT_PARENTHESIS to be able to deal with the completion node (which is correctly calculated here), but instead finds K_BINARY_OPERATOR.
Comment 2 Ayushman Jain CLA 2011-03-28 11:14:46 EDT
Created attachment 192011 [details]
patch under test
Comment 3 Ayushman Jain CLA 2011-03-29 07:16:19 EDT
Created attachment 192077 [details]
proposed fix + tests

This patch introduces a new constant to be pushed on the stack when an '|' is encountered inside the catch clause. This will help the CompletionParser to figure out that the current assistNode occured inside a catch clause and corresponds to a completion of an exception type.

The patch checks for both single type ref and qualified type ref.
Comment 4 Ayushman Jain CLA 2011-03-29 07:18:36 EDT
Satyam, please review. Thanks!
Comment 5 Satyam Kandula CLA 2011-03-30 00:53:08 EDT
Created attachment 192156 [details]
Another patch

Ayush, I don't think a new constant is required to be pushed onto the stack when we see the OR. Your patch does work and I don't see any side impacts because of it, but I want you to have a look at my proposal here and choose which ever you think is good. 

I have couple of comments with your patch though: 
1. Is it necessary to push K_OR_OPERATOR_FOR_DISJUNCTIVE_TYPE even though the stack in the top is K_OR_OPERATOR_FOR_DISJUNCTIVE_TYPE? Just an FYI, if you didn't want to have many if's there, you could just use a switch.

2. With both the patches, I don't see any proposal for the variable names. That probably can be addressed in a separate bug.
Comment 6 Ayushman Jain CLA 2011-03-30 03:30:00 EDT
(In reply to comment #5)
> Created attachment 192156 [details] [diff]
> Another patch

This patch is better. Let me see what it'll take to fix the missing argument name proposal as well.
Comment 7 Ayushman Jain CLA 2011-03-30 04:41:11 EDT
(In reply to comment #6)
> Let me see what it'll take to fix the missing argument
> name proposal as well.

This happens because the resolvedType of a DisjunctiveTypeReference is null.
Comment 8 Ayushman Jain CLA 2011-03-30 06:20:08 EDT
(In reply to comment #7)
> (In reply to comment #6)
> > Let me see what it'll take to fix the missing argument
> > name proposal as well.
> 
> This happens because the resolvedType of a DisjunctiveTypeReference is null.

This is a bug in DisjunctiveTypeRef#resolveType(..). Raised bug 341333. With the patch attached there, we now get proposals for variable names as well.
Comment 9 Ayushman Jain CLA 2011-03-30 06:40:45 EDT
Created attachment 192174 [details]
proposed fix v2.0 + tests

Above patch along with the tests and also the new test to verify that we get the variable name suggestions - CompletionTest#testBug338789e(). This test will only pass with the patch from bug 341333.

Satyam, let me know if you have any concerns. I'll release patches for both bugs together.
Comment 10 Satyam Kandula CLA 2011-03-30 07:35:25 EDT
+1. 
Even the patch you had submitted in bug 341333 seems to be good.
Comment 11 Ayushman Jain CLA 2011-03-30 12:41:30 EDT
Released for 3.7M7 in BETA_JAVA7 branch.
Comment 12 Srikanth Sankaran CLA 2011-06-29 01:56:43 EDT
Verified using "Eclipse Java Development Tools Patch for Java 7 Support (BETA)	1.0.0.v20110623-0900	org.eclipse.jdt.patch.feature.group	Eclipse.org"