Bug 8651 - Code assist should offer exception instead of any class
Summary: Code assist should offer exception instead of any class
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.0 M6   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 11651 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-01-28 23:07 EST by Greg Adams CLA
Modified: 2002-04-29 06:37 EDT (History)
2 users (show)

See Also:


Attachments
Snapshot of code assist for Collab (80.62 KB, application/octet-stream)
2002-01-29 19:39 EST, Greg Adams CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Adams CLA 2002-01-28 23:07:54 EST
Stable: 20011219

Assume I have the line below & the cursor is at the end of it
  public BusObj execute(String portName, BusObj busObj) throws Collab
If I hit code assist (ctrl+space) it would be preferable that it offers me 
exceptions beginning with Collab rather than all Collab prefixes classes.

(meta: Code assist has been very useful - the above is just an observation for 
possible enhancement).
Comment 1 Erich Gamma CLA 2002-01-29 04:00:28 EST
The proposal are computed by JDT core, given that code assist is already very 
good we should make it even better and try to be smarter.

FYI in javadoc code assist we are doing the right thing with exceptions:
@exception <ctrl space> will show you the list of exceptions thrown by the 
method.
Comment 2 Philipe Mulet CLA 2002-01-29 18:31:08 EST
We have the information that we are looking at an exception, the only problem 
is that we do not compute the hierarchy of all exception types in order to fill 
the exception type, but simply do a type name search.

Resolving hierarchies for all candidate types would be way overkilling, and 
inferring thrown exception types isn't easy, given in codeassist mode, we have 
stripped all the statements already (avoiding thus unnecessary resolutions).
Comment 3 Greg Adams CLA 2002-01-29 19:39:31 EST
Created attachment 283 [details]
Snapshot of code assist for Collab
Comment 4 Greg Adams CLA 2002-01-29 19:43:16 EST
When I did throws Collab
and requested assist I got a reasonablly good number of choices
beginning with Collab and the only plausible one was well down the list.
see my snapshot attached.

I am not sure I 100% follow your argument to pardon my ignorance but it seems as

1) You know the option has to begin with Collab & must be an exception. So I am 
unclear why this is costly to determine. 

2) Even if you can't filter exceptions (not sure I follow why you can't look at 
exception hierarchy) a good safe bet is that you could bump Collab*Exception to 
the top of the list because most people name their exceptions with exception in 
the name so ones matching that pattern could be at the top?

Preapologies for my ignorance in not following your analysis.
Comment 5 Philipe Mulet CLA 2002-01-30 09:25:22 EST
Here is why it isn't as simple as in VAJ. In VAJ, we were collecting possible 
exception completions by looking at all defined classes in the proper context, 
to which we could simply look at their type hierarchy.

In Eclipse, type hierarchies are not persisted, and are computed on demand (for 
UI purpose) against the Java model (sources, i.e. no build state is required).

We use our search infrastructure to find all defined classes, since their 
respective source files got indexed. In order to feed codeassist answers, we do 
not open each defined class to obtain its source, and then resolve its 
hierarchy to see if it is an exception.

Strictly speaking, this is what would be involved to solve this one as we did 
in VAJ. Of course performance would be prohibitive.

The post filtering with *Exception might work though, and is a trick already 
used for breakpoint on Exception types. Given sorting is done in the UI, we 
would need a distinct API callback to feed 'potential' exception types to the 
UI client (we currently only answer types).

An alternative would be to infer the exception types from the code being 
completed. If inside a catch block, then accumulating all thrown exception 
types in the body would give us an indication of likely caught ones. This 
however requires a change in the code assist engine, given we currently flush 
the statements in the try block for avoiding unnecessary type resolutions 
(which can cause to load new units/classfiles in the resolution dynamically).

Now, one could argue that if the exception type to be caught is a member type, 
then you potentially need non exception types.

class X {
  class MEx extends Exception {}
}

how will you use code assist to obtain X.MEx exception type ? You need to be 
able to complete on X first, which isn't an exception type per se.

Member type completions are regular member completions (you need first to get 
the type right, before getting to a member field/type/method).
Comment 6 Greg Adams CLA 2002-02-05 14:05:11 EST
To wrap up
- bumping the "Exception" ones to the top might be a good quick hack
- I would not recommend tossing out all of your current ones for the member 
reason you give below.

In a nutshell, any help here is goodness to the user.
Comment 7 Philipe Mulet CLA 2002-02-08 07:12:01 EST
We would need an API change to indicate the UI sorter that it is an exception 
type completion ?
Comment 8 Philipe Mulet CLA 2002-03-20 05:59:14 EST
*** Bug 11651 has been marked as a duplicate of this bug. ***
Comment 9 Lev Epshteyn CLA 2002-03-20 09:50:47 EST
This may sound stupid, but why not simply iterate through the list of suggested classes, and weed 
out everything where the class does not implement Throwable?
Doing this just before the list is 
shown should be a linear time algorithm, and the delay probably negligible...
Comment 10 Philipe Mulet CLA 2002-04-09 11:20:17 EDT
Relevance might help on this front, by recognizing presence of *Exception* or 
*Error* in type suggestions.
Comment 11 David Audel CLA 2002-04-29 06:37:15 EDT
If the proposal is an exception (type name contain 'exception' or 'error') then 
proposal is more relevant.

Fixed.