ImmutableExceptionHandler exceptionHandler = new ImmutableExceptionHandler(exceptionType, codeAddress);
public ImmutableTryBlock(int startCodeAddress, int codeUnitCount, @Nullable List<? extends ExceptionHandler> exceptionHandlers) { this.startCodeAddress = startCodeAddress; this.codeUnitCount = codeUnitCount; this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers); }
@Nonnull @Override protected ImmutableExceptionHandler makeImmutable(@Nonnull ExceptionHandler item) { return ImmutableExceptionHandler.of(item); } };
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) { if (exceptionHandler instanceof ImmutableExceptionHandler) { return (ImmutableExceptionHandler)exceptionHandler; } return new ImmutableExceptionHandler( exceptionHandler.getExceptionType(), exceptionHandler.getHandlerCodeAddress()); }
@Nonnull @Override protected ImmutableExceptionHandler makeImmutable(@Nonnull ExceptionHandler item) { return ImmutableExceptionHandler.of(item); } };
public ImmutableTryBlock(int startCodeAddress, int codeUnitCount, @Nullable List<? extends ExceptionHandler> exceptionHandlers) { this.startCodeAddress = startCodeAddress; this.codeUnitCount = codeUnitCount; this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers); }
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) { if (exceptionHandler instanceof ImmutableExceptionHandler) { return (ImmutableExceptionHandler)exceptionHandler; } return new ImmutableExceptionHandler( exceptionHandler.getExceptionType(), exceptionHandler.getHandlerCodeAddress()); }
@Nonnull @Override protected ImmutableExceptionHandler makeImmutable(@Nonnull ExceptionHandler item) { return ImmutableExceptionHandler.of(item); } };
public ImmutableTryBlock(int startCodeAddress, int codeUnitCount, @Nullable List<? extends ExceptionHandler> exceptionHandlers) { this.startCodeAddress = startCodeAddress; this.codeUnitCount = codeUnitCount; this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers); }
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) { if (exceptionHandler instanceof ImmutableExceptionHandler) { return (ImmutableExceptionHandler)exceptionHandler; } return new ImmutableExceptionHandler( exceptionHandler.getExceptionType(), exceptionHandler.getHandlerCodeAddress()); }
@Test public void testOverlap_Start_End() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 10, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Before_End() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_After_After() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(15, 20, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 10, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5))), new ImmutableTryBlock(15, 5, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Beginning_After() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 10, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(10, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Before_After() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(10, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testHandlerMerge_Exception_Catchall() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler(null, 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of( new ImmutableExceptionHandler(null, 6))), new ImmutableTryBlock(5, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler(null, 6))), new ImmutableTryBlock(10, 5, ImmutableList.of( new ImmutableExceptionHandler(null, 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Before_Before() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 3, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 3, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Before_Start() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 5, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testHandlerMerge_DifferentType() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(10, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Start_Middle() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 5, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5)))); Assert.assertEquals(expected, tryBlocks); }