Commit b5dc9017 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch 'remove-more-unnecessary-code'

parents b9f42901 d61face1
Pipeline #4383 passed with stage
in 12 minutes and 3 seconds
......@@ -793,22 +793,6 @@ public class ASMifier extends Printer {
text.add(stringBuilder.toString());
}
/**
* Deprecated.
*
* @deprecated use {@link #visitMethodInsn(int, String, String, String, boolean)} instead.
*/
@Deprecated
@Override
public void visitMethodInsn(
final int opcode, final String owner, final String name, final String descriptor) {
if (api >= Opcodes.ASM5) {
super.visitMethodInsn(opcode, owner, name, descriptor);
return;
}
doVisitMethodInsn(opcode, owner, name, descriptor, opcode == Opcodes.INVOKEINTERFACE);
}
@Override
public void visitMethodInsn(
final int opcode,
......@@ -816,19 +800,6 @@ public class ASMifier extends Printer {
final String name,
final String descriptor,
final boolean isInterface) {
if (api < Opcodes.ASM5) {
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
return;
}
doVisitMethodInsn(opcode, owner, name, descriptor, isInterface);
}
private void doVisitMethodInsn(
final int opcode,
final String owner,
final String name,
final String descriptor,
final boolean isInterface) {
stringBuilder.setLength(0);
stringBuilder
.append(this.name)
......@@ -1221,7 +1192,7 @@ public class ASMifier extends Printer {
// DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility).
protected ASMifier createASMifier(
final String visitorVariableName, final int annotationVisitorId) {
return new ASMifier(Opcodes.ASM7, visitorVariableName, annotationVisitorId);
return new ASMifier(api, visitorVariableName, annotationVisitorId);
}
/**
......
......@@ -882,12 +882,10 @@ public abstract class Printer {
@Deprecated
public void visitMethodInsn(
final int opcode, final String owner, final String name, final String descriptor) {
if (api >= Opcodes.ASM5) {
boolean isInterface = opcode == Opcodes.INVOKEINTERFACE;
visitMethodInsn(opcode, owner, name, descriptor, isInterface);
return;
}
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION);
// This method was abstract before ASM5, and was therefore always overridden (without any
// call to 'super'). Thus, at this point we necessarily have api >= ASM5, and we must then
// redirect the method call to the ASM5 visitMethodInsn() method.
visitMethodInsn(opcode, owner, name, descriptor, opcode == Opcodes.INVOKEINTERFACE);
}
/**
......@@ -907,13 +905,6 @@ public abstract class Printer {
final String name,
final String descriptor,
final boolean isInterface) {
if (api < Opcodes.ASM5) {
if (isInterface != (opcode == Opcodes.INVOKEINTERFACE)) {
throw new IllegalArgumentException("INVOKESPECIAL/STATIC on interfaces require ASM 5");
}
visitMethodInsn(opcode, owner, name, descriptor);
return;
}
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION);
}
......
......@@ -891,22 +891,6 @@ public class Textifier extends Printer {
text.add(stringBuilder.toString());
}
/**
* Deprecated.
*
* @deprecated use {@link #visitMethodInsn(int, String, String, String, boolean)} instead.
*/
@Deprecated
@Override
public void visitMethodInsn(
final int opcode, final String owner, final String name, final String descriptor) {
if (api >= Opcodes.ASM5) {
super.visitMethodInsn(opcode, owner, name, descriptor);
return;
}
doVisitMethodInsn(opcode, owner, name, descriptor, opcode == Opcodes.INVOKEINTERFACE);
}
@Override
public void visitMethodInsn(
final int opcode,
......@@ -914,19 +898,6 @@ public class Textifier extends Printer {
final String name,
final String descriptor,
final boolean isInterface) {
if (api < Opcodes.ASM5) {
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
return;
}
doVisitMethodInsn(opcode, owner, name, descriptor, isInterface);
}
private void doVisitMethodInsn(
final int opcode,
final String owner,
final String name,
final String descriptor,
final boolean isInterface) {
stringBuilder.setLength(0);
stringBuilder.append(tab2).append(OPCODES[opcode]).append(' ');
appendDescriptor(INTERNAL_NAME, owner);
......@@ -1626,6 +1597,6 @@ public class Textifier extends Printer {
* @return a new {@link Textifier}.
*/
protected Textifier createTextifier() {
return new Textifier();
return new Textifier(api);
}
}
......@@ -162,13 +162,26 @@ public final class TraceMethodVisitor extends MethodVisitor {
}
@Override
@SuppressWarnings("deprecation")
public void visitMethodInsn(
final int opcode,
final String owner,
final String name,
final String descriptor,
final boolean isInterface) {
p.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
// Call the method that p is supposed to implement, depending on its api version.
if (p.api < Opcodes.ASM5) {
if (isInterface != (opcode == Opcodes.INVOKEINTERFACE)) {
throw new IllegalArgumentException("INVOKESPECIAL/STATIC on interfaces require ASM5");
}
// If p is an ASMifier (resp. Textifier), or a subclass that does not override the old
// visitMethodInsn method, the default implementation in Printer will redirect this to the
// new method in ASMifier (resp. Textifier). In all other cases, p overrides the old method
// and this call executes it.
p.visitMethodInsn(opcode, owner, name, descriptor);
} else {
p.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
}
if (mv != null) {
mv.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
}
......
......@@ -52,7 +52,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.test.AsmTest;
import org.objectweb.asm.test.ClassFile;
......@@ -78,41 +77,6 @@ public class ASMifierTest extends AsmTest {
assertThrows(IllegalStateException.class, () -> new ASMifier() {});
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedVisitMethodInsn() {
ASMifier asmifier = new ASMifier();
asmifier.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V");
assertEquals(
"classWriter.visitMethodInsn(INVOKESPECIAL, \"owner\", \"name\", \"()V\", false);\n",
asmifier.getText().get(0));
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedVisitMethodInsn_asm4() {
ASMifier asmifier = new ASMifier(Opcodes.ASM4, "classWriter", 0) {};
asmifier.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V");
assertEquals(
"classWriter.visitMethodInsn(INVOKESPECIAL, \"owner\", \"name\", \"()V\", false);\n",
asmifier.getText().get(0));
}
@Test
public void testVisitMethodInsn_asm4() {
ASMifier asmifier = new ASMifier(Opcodes.ASM4, "classWriter", 0) {};
asmifier.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V", false);
assertEquals(
"classWriter.visitMethodInsn(INVOKESPECIAL, \"owner\", \"name\", \"()V\", false);\n",
asmifier.getText().get(0));
}
/**
* Tests that the code produced with an ASMifier compiles and generates the original class.
*
......
......@@ -29,9 +29,7 @@ package org.objectweb.asm.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.objectweb.asm.Attribute;
......@@ -215,52 +213,6 @@ public class PrinterTest {
assertEquals(UNSUPPORTED_OPERATION_MESSAGE, exception.getMessage());
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedVisitMethodInsn_asm4_unsupportedByDefault() {
Printer printer = new EmptyPrinter(Opcodes.ASM4);
Executable visitMethodInsn =
() -> printer.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V");
Exception exception = assertThrows(UnsupportedOperationException.class, visitMethodInsn);
assertEquals(UNSUPPORTED_OPERATION_MESSAGE, exception.getMessage());
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedVisitMethodInsn_asm5_unsupportedByDefault() {
Printer printer = new EmptyPrinter(Opcodes.ASM5);
Executable visitMethodInsn =
() -> printer.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V");
Exception exception = assertThrows(UnsupportedOperationException.class, visitMethodInsn);
assertEquals(UNSUPPORTED_OPERATION_MESSAGE, exception.getMessage());
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedVisitMethodInsn_asm5_callsNewMethodIfOverridden() {
AtomicBoolean visitMethodInsnCalled = new AtomicBoolean();
Printer printer =
new EmptyPrinter(Opcodes.ASM5) {
@Override
public void visitMethodInsn(
final int opcode,
final String owner,
final String name,
final String descriptor,
final boolean isInterface) {
visitMethodInsnCalled.set(true);
}
};
printer.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V");
assertTrue(visitMethodInsnCalled.get());
}
@Test
public void testVisitMethodInsn_asm4_unsupportedByDefault() {
Printer printer = new EmptyPrinter(Opcodes.ASM4);
......@@ -272,35 +224,6 @@ public class PrinterTest {
assertEquals(UNSUPPORTED_OPERATION_MESSAGE, exception.getMessage());
}
@Test
public void testVisitMethodInsn_asm4_callsNewMethodIfOverridden() {
AtomicBoolean deprecatedVisitMethodInsnCalled = new AtomicBoolean();
Printer printer =
new EmptyPrinter(Opcodes.ASM4) {
@Override
@Deprecated
public void visitMethodInsn(
final int opcode, final String owner, final String name, final String descriptor) {
deprecatedVisitMethodInsnCalled.set(true);
}
};
printer.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V", false);
assertTrue(deprecatedVisitMethodInsnCalled.get());
}
@Test
public void testVisitMethodInsn_asm4_illegalArgument() {
Printer printer = new EmptyPrinter(Opcodes.ASM4);
Executable visitMethodInsn =
() -> printer.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V", true);
Exception exception = assertThrows(IllegalArgumentException.class, visitMethodInsn);
assertEquals("INVOKESPECIAL/STATIC on interfaces require ASM 5", exception.getMessage());
}
@Test
public void testVisitMethodInsn_unsupportedByDefault() {
Printer printer = new EmptyPrinter(Opcodes.ASM7);
......
......@@ -45,7 +45,6 @@ import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.test.AsmTest;
/**
......@@ -66,49 +65,24 @@ public class TextifierTest extends AsmTest {
assertThrows(IllegalStateException.class, () -> new Textifier() {});
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedVisitMethodInsn() {
Textifier textifier = new Textifier();
textifier.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V");
assertEquals(" INVOKESPECIAL owner.name ()V\n", textifier.getText().get(0));
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedVisitMethodInsn_asm4() {
Textifier textifier = new Textifier(Opcodes.ASM4) {};
textifier.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V");
assertEquals(" INVOKESPECIAL owner.name ()V\n", textifier.getText().get(0));
}
@Test
public void testVisitMethodInsn_asm4() {
Textifier textifier = new Textifier(Opcodes.ASM4) {};
textifier.visitMethodInsn(Opcodes.INVOKESPECIAL, "owner", "name", "()V", false);
assertEquals(" INVOKESPECIAL owner.name ()V\n", textifier.getText().get(0));
}
/**
* Tests that the text produced with a Textifier is equal to the expected text.
*
* @throws IOException if the expected text can't be read from disk.
*/
@ParameterizedTest
@MethodSource(ALL_CLASSES_AND_LATEST_API)
@MethodSource(ALL_CLASSES_AND_ALL_APIS)
public void testTextify_precompiledClass(
final PrecompiledClass classParameter, final Api apiParameter) throws IOException {
byte[] classFile = classParameter.getBytes();
StringWriter output = new StringWriter();
assumeTrue(classFile.length < 32768);
new ClassReader(classFile).accept(new TraceClassVisitor(new PrintWriter(output, true)), 0);
new ClassReader(classFile)
.accept(
new TraceClassVisitor(
null, new Textifier(apiParameter.value()) {}, new PrintWriter(output)),
0);
String expectedText =
new String(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment