How to turn up off source cleanup in a code section? [message #1818412] |
Sat, 14 December 2019 16:01  |
Eclipse User |
|
|
|
I'd like to enable the Editor Save Action that converts to lambdas where possible. At my first attempts I noticed that the conversion happens even in cases where it's apparently not possible. Examples:
1) Fields in a class that are initialized with a lambda that accesses other fields which are defined later in the class. In my case most often listeners.
2) Calls to methods that take a Runnable argument and have an overloaded sibling method with a Callable argument. I can't easily describe what's going on, so here's a snippet from my code:
public interface Transaction
{
public void syncExec(Runnable runnable);
public <V> V syncExec(Callable<V> callable) throws Exception;
}
public class SomeOtherClass
{
private Transaction transaction;
private boolean showMerges;
public void close()
{
transaction.syncExec(new Runnable()
{
@Override
public void run()
{
transaction.removeTransactionHandler(transactionHandler);
transaction.removeListener(transactionListener);
}
});
}
public final void setShowMerges(final boolean showMerges)
{
transaction.syncExec(new Runnable()
{
@Override
public void run()
{
SomeOtherClass.this.showMerges = showMerges;
}
});
}
}
In the SomeOtherClass.close() method the new Runnable(){...} is converted into a lambda that compiles without errors. But the conversion in the SomeOtherClass.setShowMerges() method leads to the compile error "Unhandled exception type Exception". I have no idea what exactly is the problem with that second case.
I tend to think that these are bugs in the "Use lambdas where possible" conversion because I interpret "where possible" as "if the result compiles without errors and works like before".
I could work around the problem with "accesses other fields which are defined later in the class", but it turned out that it's really not worth the effort. It just clutters my code and its Git history. I don't know how to work around the "Unhandled exception type Exception" problem.
Can you please give me advice on how to deal with these problems? Am I doing something wrong? Are they bugs and should be fixed? Is there a magic comment token to turn the cleanup off for a code region, similar to @formatter:off ?
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.25953 seconds