| Summary: | [1.7] Fix breakages caused by changes in TryStatement node | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Deepak Azad <deepakazad> | ||||||||||||
| Component: | UI | Assignee: | Deepak Azad <deepakazad> | ||||||||||||
| Status: | VERIFIED FIXED | QA Contact: | |||||||||||||
| Severity: | normal | ||||||||||||||
| Priority: | P3 | CC: | daniel_megert, deepakazad, markus.kell.r, Michael_Rennie | ||||||||||||
| Version: | 3.7 | ||||||||||||||
| Target Milestone: | 3.7.1 | ||||||||||||||
| Hardware: | All | ||||||||||||||
| OS: | All | ||||||||||||||
| Whiteboard: | |||||||||||||||
| Attachments: |
|
||||||||||||||
|
Description
Deepak Azad
Created attachment 197774 [details]
fix + tests - I
MethodExitsFinder and ExceptionOccurrencesFinder now handle try with resources. Note that in both cases the closing } will be marked if close() throws an exception which is not caught.
When try with resources is on more than one resource, it is easy to know which resource's close call will throw an exception. Hence we can probably mark the resource variable name along with the closing brace of the try block. Though I am not sure if it will be confusing to the user to see a variable name highlighted in case of Method exits or Throwing Exceptions.. (In reply to comment #2) > When try with resources is on more than one resource, it is easy to know which > resource's close call will throw an exception. Hence we can probably mark the > resource variable name along with the closing brace of the try block. Though I > am not sure if it will be confusing to the user to see a variable name > highlighted in case of Method exits or Throwing Exceptions.. It could be that more than one is causing it, right? I still lean towards my first opinion i.e. that it might be too confusing to highlight the variable(s) in this case. It could also be confused with for/switch highlighting. (In reply to comment #3) > It could be that more than one is causing it, right? Yes. However if out of say 5 resources an exception is thrown only on close call of 2 resources, then I can highlight only those 2. Created attachment 197999 [details]
fix + tests - II
Fix for extract method refactoring.
See also Bug 348708. Created attachment 198171 [details]
fix + tests - III
Disable 'Split variable declaraiton' quick assist for resources declared in a try statement.
Created attachment 198516 [details]
fix + tests - IV
- Disable the removal of try with resources block when when the last catch block is removed.
- Do not offer 'Remove surrounding 'try' block' in case of try with resources.
(In reply to comment #1) > Created attachment 197774 [details] [diff] > fix + tests - I > > MethodExitsFinder and ExceptionOccurrencesFinder now handle try with resources. > Note that in both cases the closing } will be marked if close() throws an > exception which is not caught. Last things that remains is 1. improve tooltip message for the closing } of try block 2. decide whether we also highlight the name of the resource whose close() method can throw an exception 3. tooltip for resource name if we do 2. I don't think we can do this, as currently the Javadoc hover is shown in the editor. I think we should simply do 1 and change the tooltip to - "'Exception' is thrown from the implicit close() method of 'resource1', 'resource2'. In my opinion too many things are highlighted if resource name is also highlighted, also we cannot explain the highlighting in this case via a tooltip. Markus, what do you think ? > 1. improve tooltip message for the closing } of try block Sounds good. But the } is still hard to hit with the mouse, so I don't think many people will discover the additional info in the hover. > 2. decide whether we also highlight the name of the resource I found the closing } of the TryStatement block not informative enough, so I added highlighting of the resource names to see how it looks. Here's an example: package tryresources; import java.io.FileNotFoundException; import java.io.FileReader; class A { void foo() throws Throwable { try ( ACloseable closeable = new ACloseable(); FileReader reader = new FileReader("file1"); ) { int ch; while ((ch = reader.read()) != -1) { System.out.println(ch); } } catch (IllegalArgumentException e) { throw new Exception(e); } catch (FileNotFoundException e) { throw new Exception(e); } } } class ACloseable implements AutoCloseable { @Override public void close() throws IllegalArgumentException { } } I see your point about too many highlights, but I still think the names are valuable, since they make the hidden exit points obvious. Exit behavior is complicated in these situations, and the user should be pestered with the details. > 3. tooltip for resource name Would be nice, but that would need a special case in BestMatchHover#getHoverInfo2(ITextViewer, IRegion) to compute and boost this AnnotationHover, but not all annotation hovers -- e.g. the Debug Current Instruction Pointer is not that interesting. I guess it is better to err on the side of providing too much information than to provide less information, so I am OK with highlighting the variable name. (In reply to comment #10) > > 3. tooltip for resource name > > Would be nice, but that would need a special case in > BestMatchHover#getHoverInfo2(ITextViewer, IRegion) to compute and boost this > AnnotationHover, but not all annotation hovers -- e.g. the Debug Current > Instruction Pointer is not that interesting. The hover needs a boost only for resource names, in case of method calls it is good to show the Javadoc hover as it contains info on the exact exception thrown. e.g. if you are looking for thrown occurrences of IOException it is sometimes useful to know that a method actually throws FileNotFoundException. If this is too complicated I OK with letting it be as is. Created attachment 198629 [details] fix - V > 1. improve tooltip message for the closing } of try block Done. I am done here, hence marking this bug as fixed. Any issues found in future can be handled in separate bugs. verified |