[Compiler modification] Propagate exception throws from for-each? [message #1451948] |
Fri, 24 October 2014 14:52 |
i AqD Messages: 8 Registered: July 2014 Location: Taipei |
Junior Member |
|
|
Hello JDT devs!
I'm considering adding 'throws' into Iterable and Iterator (hasNext/next), like these:
interface Iterable<E, TException extends Exception> {
Iterator<E, TException> iterator();
}
...
interface Iterator<E, TException extends Exception> {
boolean hasNext() throws TException;
E next() throws TException;
}
I already have overridden interfaces from rt.jar for other purposes (via endorsed dir), and throws generic exceptions is also proved to work flawlessly with Eclipse Luna. So modifying Iterable/Iterator wouldn't be a big deal, and I'm looking at the JDT code of ForeachStatement, as for-each itself doesn't handle throws from next/hasNext by design.
But before I modify it, there is something that I couldn't understand: In ForeachStatement.resolve(), why does it check the length of generic arguments of Iterable below?
TypeBinding[] arguments = null;
switch (iterableType.kind()) {
case Binding.RAW_TYPE : // for(Object o : Iterable)
....
}
// generic or parameterized case
if (arguments.length != 1) break checkIterable; // per construction can only be one
Since by definition Iterable<E> has only one generic argument and it's the item type, why bother checking the total length? What does "per construction can only be one" mean? Is there any use or definition of other arguments already? (I intend to add the 2nd to represent throwable exception type, and call handlingContext.checkExceptionHandlers there)
|
|
|
Powered by
FUDForum. Page generated in 0.02630 seconds