fix: correct inline for enums in j$.time.temporal

This commit is contained in:
Skylot
2022-01-31 10:28:35 +00:00
parent 00b48473a0
commit bd3e62617e
6 changed files with 89 additions and 65 deletions
@@ -52,19 +52,18 @@ public class JadxCodeAssertions extends AbstractStringAssert<JadxCodeAssertions>
}
String indent = TestUtils.indent(commonIndent);
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String line : lines) {
if (!line.isEmpty()) {
if (first) {
first = false;
} else {
sb.append(ICodeWriter.NL);
}
sb.append(indent);
sb.append(line);
sb.append(ICodeWriter.NL);
if (line.isEmpty()) {
// don't add common indent to empty lines
continue;
}
String searchLine = indent + line;
sb.append(searchLine);
// check every line for easier debugging
contains(searchLine);
}
return containsOnlyOnce(sb.toString());
return containsOnlyOnce(sb.substring(ICodeWriter.NL.length()));
}
public JadxCodeAssertions removeBlockComments() {
@@ -2,11 +2,10 @@ package jadx.tests.integration.enums;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.api.CommentsLevel;
import jadx.tests.api.IntegrationTest;
import jadx.tests.api.utils.JadxMatchers;
import static org.hamcrest.MatcherAssert.assertThat;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestEnums2 extends IntegrationTest {
@@ -32,25 +31,25 @@ public class TestEnums2 extends IntegrationTest {
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = removeLineComments(cls);
assertThat(code, JadxMatchers.containsLines(1,
"public enum Operation {",
indent(1) + "PLUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x + y;",
indent(2) + '}',
indent(1) + "},",
indent(1) + "MINUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x - y;",
indent(2) + '}',
indent(1) + "};",
"",
indent(1) + "public abstract int apply(int i, int i2);",
"}"));
getArgs().setCommentsLevel(CommentsLevel.WARN);
assertThat(getClassNode(TestCls.class))
.code()
.containsLines(1,
"public enum Operation {",
indent(1) + "PLUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x + y;",
indent(2) + '}',
indent(1) + "},",
indent(1) + "MINUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x - y;",
indent(2) + '}',
indent(1) + "};",
"",
indent(1) + "public abstract int apply(int i, int i2);",
"}");
}
}
@@ -2,11 +2,10 @@ package jadx.tests.integration.enums;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.api.CommentsLevel;
import jadx.tests.api.IntegrationTest;
import jadx.tests.api.utils.JadxMatchers;
import static org.hamcrest.MatcherAssert.assertThat;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestEnumsInterface extends IntegrationTest {
@@ -34,23 +33,23 @@ public class TestEnumsInterface extends IntegrationTest {
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = removeLineComments(cls);
assertThat(code, JadxMatchers.containsLines(1,
"public enum Operation implements IOperation {",
indent(1) + "PLUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x + y;",
indent(2) + '}',
indent(1) + "},",
indent(1) + "MINUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x - y;",
indent(2) + '}',
indent(1) + '}',
"}"));
getArgs().setCommentsLevel(CommentsLevel.WARN);
assertThat(getClassNode(TestCls.class))
.code()
.containsLines(1,
"public enum Operation implements IOperation {",
indent(1) + "PLUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x + y;",
indent(2) + '}',
indent(1) + "},",
indent(1) + "MINUS {",
indent(2) + "@Override",
indent(2) + "public int apply(int x, int y) {",
indent(3) + "return x - y;",
indent(2) + '}',
indent(1) + '}',
"}");
}
}