Give CATCH blocks the right order with finally most outer block.

This commit is contained in:
Volker Berlin 2022-07-26 21:25:09 +02:00
parent 855713a519
commit c6fc938a3d
No known key found for this signature in database
GPG Key ID: 988423EF815BE4CB

View File

@ -1213,7 +1213,7 @@ class BranchManager {
for( idx = 0; idx < parsedOperations.size(); idx++ ) {
ParsedBlock parsedBlock = parsedOperations.get( idx );
if( parsedBlock.op == JavaBlockOperator.TRY ) {
if( parsedBlock.op == JavaBlockOperator.TRY && !tryCatch.isFinally() ) {
TryCatchFinally tryCatch2 = ((TryCatchParsedBlock)parsedBlock).tryCatch;
if( tryCatch.getStart() == tryCatch2.getStart() && tryCatch.getEnd() == tryCatch2.getEnd() ) {
catches.add( tryCatch2 );
@ -1696,6 +1696,30 @@ class BranchManager {
super( JavaBlockOperator.TRY, tryCatch.getStart(), tryCatch.getEnd() - tryCatch.getStart(), tryCatch.getStart(), -1 );
this.tryCatch = tryCatch;
}
/**
* {@inheritDoc}
*/
@Override
public int compareTo( ParsedBlock o ) {
int compare = super.compareTo( o );
if( compare == 0 && o instanceof TryCatchParsedBlock ) {
// sort the finally block first as most outer block
TryCatchParsedBlock ot = (TryCatchParsedBlock)o;
if( tryCatch.isFinally() ) {
if( !ot.tryCatch.isFinally() ) {
return -1;
}
} else {
if( ot.tryCatch.isFinally() ) {
return 1;
}
}
// the other catch blocks in it natural order
return Integer.compare( tryCatch.getHandler(), ot.tryCatch.getHandler() );
}
return compare;
}
}
/**