diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java index 1f8012521a910baf9698011127154bc4839c91e2..262acbbdcdbd82a29deab5ee8125cbccf8a44560 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java @@ -80,7 +80,7 @@ public class ConstInlinerVisitor extends AbstractVisitor { } /** - * This is method similar to PostTypeInference.visit method, + * This is method similar to PostTypeInference.process method, * but contains some expensive operations needed only after constant inline */ private static void fixTypes(MethodNode mth, InsnNode insn, LiteralArg litArg) { diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ReturnVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ReturnVisitor.java index 8249211bff0979082853976d5b3b52bbb3539e01..039161839acf0edef810bf15db72a985024dce5d 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ReturnVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ReturnVisitor.java @@ -12,13 +12,11 @@ import jadx.core.dex.regions.IfRegion; import jadx.core.dex.regions.LoopRegion; import jadx.core.dex.regions.SwitchRegion; import jadx.core.dex.visitors.AbstractVisitor; -import jadx.core.utils.RegionUtils; import jadx.core.utils.exceptions.JadxException; +import jadx.core.utils.exceptions.JadxRuntimeException; -import java.util.HashSet; import java.util.List; import java.util.ListIterator; -import java.util.Set; /** * Remove unnecessary return instructions for void methods @@ -85,7 +83,7 @@ public class ReturnVisitor extends AbstractVisitor { IContainer subBlock = itSubBlock.previous(); if (subBlock == curContainer) { break; - } else if (notEmpty(subBlock)) { + } else if (!isEmpty(subBlock)) { return false; } } @@ -95,25 +93,25 @@ public class ReturnVisitor extends AbstractVisitor { return true; } - private static boolean notEmpty(IContainer subBlock) { - if (subBlock.contains(AFlag.RETURN)) { - return false; - } - int insnCount = RegionUtils.insnsCount(subBlock); - if (insnCount > 1) { - return true; - } - if (insnCount == 1) { - // don't count one 'return' instruction (it will be removed later) - Set blocks = new HashSet(); - RegionUtils.getAllRegionBlocks(subBlock, blocks); - for (BlockNode node : blocks) { - if (!node.contains(AFlag.RETURN) && !node.getInstructions().isEmpty()) { - return true; + /** + * Check if container not contains instructions, + * don't count one 'return' instruction (it will be removed later). + */ + private static boolean isEmpty(IContainer container) { + if (container instanceof BlockNode) { + BlockNode block = (BlockNode) container; + return block.getInstructions().isEmpty() || block.contains(AFlag.RETURN); + } else if (container instanceof IRegion) { + IRegion region = (IRegion) container; + for (IContainer block : region.getSubBlocks()) { + if(!isEmpty(block)) { + return false; } } + return true; + } else { + throw new JadxRuntimeException("Unknown container type: " + container.getClass()); } - return false; } } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/FinishTypeInference.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/FinishTypeInference.java index 07a3a9c8f6ed2d3d17969954ceda404b4d76794b..b002a7f50869621f11323762ac97314bbafcdb80 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/FinishTypeInference.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/FinishTypeInference.java @@ -19,7 +19,7 @@ public class FinishTypeInference extends AbstractVisitor { change = false; for (BlockNode block : mth.getBasicBlocks()) { for (InsnNode insn : block.getInstructions()) { - if (PostTypeInference.visit(mth, insn)) { + if (PostTypeInference.process(mth, insn)) { change = true; } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/PostTypeInference.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/PostTypeInference.java index f869692b8bf57a72d882fd6abe4430b6f9395e0f..30d1d96be5a53177ab6e18833610096b898c728e 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/PostTypeInference.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/PostTypeInference.java @@ -15,7 +15,7 @@ import java.util.List; public class PostTypeInference { - public static boolean visit(MethodNode mth, InsnNode insn) { + public static boolean process(MethodNode mth, InsnNode insn) { switch (insn.getType()) { case CONST: RegisterArg res = insn.getResult();