[java-decompiler] IDEA-346312 adapt patches

- add comments with examples

GitOrigin-RevId: 22a84867e417c1a326f78c19d1146b3580f583a4
This commit is contained in:
Mikhail Pyltsin
2024-09-25 13:21:31 +02:00
committed by intellij-monorepo-bot
parent 041ae74f7e
commit cdb57601a8
5 changed files with 112 additions and 1 deletions

View File

@@ -268,6 +268,26 @@ public class MethodProcessorRunnable implements Runnable {
return finished;
}
/**
* Clean monitor of synchronizer: <p>
* Simple synthetic example:<p>
* before: <pre>
* {@code
* var a = b; // a is not used anywhere
* synchronized (b){
* doSomething();
* }
* }
* </pre>
* after:
* <pre>
* {@code
* synchronized (b){
* doSomething();
* }
* }
* </pre>
*/
public static void cleanSynchronizedVar(Statement stat) {
for (Statement st : stat.getStats()) {
cleanSynchronizedVar(st);

View File

@@ -12,6 +12,30 @@ import java.util.*;
public final class EliminateLoopsHelper {
/**
* Remove loops from the given root statement. <p>
* Simple synthetic example:<p>
* before: <pre>
* {@code
* LABEL:
* while(true){
* while(true){
* doSomething();
* break LABEL;
* }
* }
* }
* </pre>
* after:
* <pre>
* {@code
* while(true){
* doSomething();
* break;
* }
* }
* </pre>
*/
public static boolean eliminateLoops(RootStatement root, StructMethod mt, StructClass cl) {
boolean ret = eliminateLoopsRec(root);

View File

@@ -19,7 +19,29 @@ import java.util.Set;
public final class LoopExtractHelper {
/**
* Analyzes the provided statement structure to identify and extract loop constructs.
* If any loops are successfully extracted, the statement sequences are condensed.<p>
* Simple synthetic example:<p>
* before: <pre>
* {@code
* while(true){
* if (var1 >= 10){
* break
* }
* doSomething();
* }
* }
* </pre>
* after:
* <pre>
* {@code
* while(var1 >= 10){
* doSomething();
* }
* }
* </pre>
*/
public static boolean extractLoops(Statement root) {
boolean res = (extractLoopsRec(root) != 0);

View File

@@ -17,6 +17,26 @@ import java.util.Set;
import static org.jetbrains.java.decompiler.modules.decompiler.StatEdge.EdgeDirection;
public final class MergeHelper {
/**
* Enhances the loops in the provided statement tree.
* Simple example:<p>
* before: <pre>
* {@code
* Iterator var6 = a.iterator();
* while(true) {
* if (!var6.hasNext()) {
* break;
* }
* A<String> s = (A)var6.next();
* }
* }
* </pre>
* after:
* <pre>
* {@code
* for(A<String> s : a) {}
* </pre>
*/
public static void enhanceLoops(Statement root) {
while (enhanceLoopsRec(root)) /**/;
SequenceHelper.condenseSequences(root);
@@ -714,6 +734,28 @@ public final class MergeHelper {
return inv.isUnboxingCall() && isNextCall(inv.getInstance());
}
/**
* Convert `while` to `do-while`.
* Simple synthetic example:<p>
* before: <pre>
* {@code
* while(true){
* doSomething();
* if (i >= 10) {
* break;,
* }
* }
* }
* </pre>
* after:
* <pre>
* {@code
* do {
* doSomething();
* } while(i < 10);
* }
* </pre>
*/
public static boolean makeDoWhileLoops(RootStatement root) {
if (makeDoWhileRec(root)) {
SequenceHelper.condenseSequences(root);

View File

@@ -20,6 +20,9 @@ import java.util.stream.Collectors;
public final class TryHelper
{
/**
* Tries to convert `try` statement to `try-with-resource`
*/
public static boolean enhanceTryStats(RootStatement root, StructMethod mt) {
boolean ret = makeTryWithResourceRec(root, mt, root.getDummyExit(), new ArrayList<>());
if (ret) {