■ ■ ■ ■ ■ ■
jadx-core/src/main/java/jadx/core/dex/visitors/regions/MarkTryCatchRegions.java
jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessTryCatchRegions.java
| skipped 25 lines |
26 | 26 | | /** |
27 | 27 | | * Extract blocks to separate try/catch region |
28 | 28 | | */ |
29 | | - | public class MarkTryCatchRegions extends AbstractRegionVisitor { |
30 | | - | private static final Logger LOG = LoggerFactory.getLogger(MarkTryCatchRegions.class); |
| 29 | + | public class ProcessTryCatchRegions extends AbstractRegionVisitor { |
| 30 | + | private static final Logger LOG = LoggerFactory.getLogger(ProcessTryCatchRegions.class); |
31 | 31 | | private static final boolean DEBUG = false; |
32 | 32 | | |
33 | 33 | | static { |
34 | | - | if (DEBUG) |
35 | | - | LOG.debug("Debug enabled for " + MarkTryCatchRegions.class); |
| 34 | + | if (DEBUG) { |
| 35 | + | LOG.debug("Debug enabled for " + ProcessTryCatchRegions.class); |
| 36 | + | } |
36 | 37 | | } |
37 | 38 | | |
38 | 39 | | private final Map<BlockNode, TryCatchBlock> tryBlocksMap = new HashMap<BlockNode, TryCatchBlock>(2); |
39 | 40 | | |
40 | | - | public MarkTryCatchRegions(MethodNode mth) { |
41 | | - | if (mth.isNoCode() || mth.getExceptionHandlers() == null) |
| 41 | + | public ProcessTryCatchRegions(MethodNode mth) { |
| 42 | + | if (mth.isNoCode() || mth.getExceptionHandlers() == null) { |
42 | 43 | | return; |
| 44 | + | } |
43 | 45 | | |
44 | 46 | | Set<TryCatchBlock> tryBlocks = new HashSet<TryCatchBlock>(); |
45 | 47 | | // collect all try/catch blocks |
46 | 48 | | for (BlockNode block : mth.getBasicBlocks()) { |
47 | 49 | | CatchAttr c = (CatchAttr) block.getAttributes().get(AttributeType.CATCH_BLOCK); |
48 | | - | if (c != null) |
| 50 | + | if (c != null) { |
49 | 51 | | tryBlocks.add(c.getTryBlock()); |
| 52 | + | } |
50 | 53 | | } |
51 | 54 | | |
52 | 55 | | // for each try block search nearest dominator block |
| skipped 18 lines |
71 | 74 | | bs.andNot(block.getDoms()); |
72 | 75 | | } |
73 | 76 | | domBlocks = BlockUtils.bitsetToBlocks(mth, bs); |
74 | | - | if (domBlocks.size() != 1) |
| 77 | + | if (domBlocks.size() != 1) { |
75 | 78 | | throw new JadxRuntimeException( |
76 | 79 | | "Exception block dominator not found, method:" + mth + ". bs: " + bs); |
| 80 | + | } |
77 | 81 | | |
78 | 82 | | BlockNode domBlock = domBlocks.get(0); |
79 | 83 | | |
| skipped 3 lines |
83 | 87 | | } |
84 | 88 | | } |
85 | 89 | | |
86 | | - | if (DEBUG && !tryBlocksMap.isEmpty()) |
87 | | - | LOG.debug("MarkTryCatchRegions: \n {} \n {}", mth, tryBlocksMap); |
| 90 | + | if (DEBUG && !tryBlocksMap.isEmpty()) { |
| 91 | + | LOG.debug("ProcessTryCatchRegions: \n {} \n {}", mth, tryBlocksMap); |
| 92 | + | } |
88 | 93 | | } |
89 | 94 | | |
90 | 95 | | @Override |
91 | 96 | | public void leaveRegion(MethodNode mth, IRegion region) { |
92 | | - | if (tryBlocksMap.isEmpty()) |
| 97 | + | if (tryBlocksMap.isEmpty() || !(region instanceof Region)) { |
93 | 98 | | return; |
94 | | - | |
95 | | - | if (!(region instanceof Region)) |
96 | | - | return; |
97 | | - | |
| 99 | + | } |
98 | 100 | | // search dominator blocks in this region (don't need to go deeper) |
99 | 101 | | for (BlockNode dominator : tryBlocksMap.keySet()) { |
100 | 102 | | if (region.getSubBlocks().contains(dominator)) { |
| skipped 31 lines |
132 | 134 | | } |
133 | 135 | | } |
134 | 136 | | if (newRegion.getSubBlocks().size() != 0) { |
135 | | - | if (DEBUG) |
136 | | - | LOG.debug("MarkTryCatchRegions mark: {}", newRegion); |
| 137 | + | if (DEBUG) { |
| 138 | + | LOG.debug("ProcessTryCatchRegions mark: {}", newRegion); |
| 139 | + | } |
137 | 140 | | // replace first node by region |
138 | 141 | | IContainer firstNode = newRegion.getSubBlocks().get(0); |
139 | 142 | | int i = region.getSubBlocks().indexOf(firstNode); |
| skipped 9 lines |