peichhorn/lombok-pg — Issue #50: Spice up @Cleanup
Author: peichhorn
Created: 2011-11-15 18:20:45+00:00
State: open

Since yield iterators are Closeable now, it only makes sense to use @Cleanup with them, simple example:

```
@Cleanup final Iterable lines = Lines.in(file); // implemented with yield, closes Stream if exception occurs
for (String line : lines) {
// something
}
```

For now this wouldn't work since Iterable itself has no "close" method, but what if we spice up the generated code. If the cleanup method name is "close" and the type of the annotated local declaration has not method "close" add this logic:

```
if (lines instanceof Closeable) {
((Closeable)lines).close();
}
```