Commit e36723c9 authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Fix code smells found with SonarQube.

parent 3417fa65
......@@ -219,7 +219,14 @@ public class ClassRemapper extends ClassVisitor {
super.visitNestMember(remapper.mapType(nestMember));
}
/**
* <b>Experimental, use at your own risk.</b>.
*
* @param permittedSubtype the internal name of a permitted subtype.
* @deprecated this API is experimental.
*/
@Override
@Deprecated
public void visitPermittedSubtypeExperimental(final String permittedSubtype) {
super.visitPermittedSubtypeExperimental(remapper.mapType(permittedSubtype));
}
......
......@@ -173,10 +173,7 @@ public abstract class AsmTest {
if (name.startsWith("jdk14.") && api.value() < Api.ASM8.value()) {
return true;
}
if (name.startsWith("jdk15.") && api.value() < Api.ASM9.value()) {
return true;
}
return false;
return name.startsWith("jdk15.") && api.value() < Api.ASM9.value();
}
/**
......
......@@ -1700,8 +1700,8 @@ public class ClassFile {
*/
private static void dumpPermittedSubtypesAttribute(final Parser parser, final Builder builder)
throws IOException {
int numberOfClasses = builder.add("number_of_classes: ", parser.u2());
for (int i = 0; i < numberOfClasses; ++i) {
int permittedSubTypesCount = builder.add("permitted_subtypes_count: ", parser.u2());
for (int i = 0; i < permittedSubTypesCount; ++i) {
builder.addCpInfo("class: ", parser.u2());
}
}
......
......@@ -250,7 +250,14 @@ public class ClassNode extends ClassVisitor {
nestMembers = Util.add(nestMembers, nestMember);
}
/**
* <b>Experimental, use at your own risk.</b>.
*
* @param permittedSubtype the internal name of a permitted subtype.
* @deprecated this API is experimental.
*/
@Override
@Deprecated
public void visitPermittedSubtypeExperimental(final String permittedSubtype) {
permittedSubtypesExperimental = Util.add(permittedSubtypesExperimental, permittedSubtype);
}
......
......@@ -323,11 +323,18 @@ public class ASMifier extends Printer {
text.add(stringBuilder.toString());
}
/**
* <b>Experimental, use at your own risk.</b>.
*
* @param permittedSubtype the internal name of a permitted subtype.
* @deprecated this API is experimental.
*/
@Override
public void visitPermittedSubtypeExperimental(final String visitPermittedSubtype) {
@Deprecated
public void visitPermittedSubtypeExperimental(final String permittedSubtype) {
stringBuilder.setLength(0);
stringBuilder.append("classWriter.visitPermittedSubtypeExperimental(");
appendConstant(visitPermittedSubtype);
appendConstant(permittedSubtype);
stringBuilder.append(END_PARAMETERS);
text.add(stringBuilder.toString());
}
......
......@@ -321,7 +321,14 @@ public class CheckClassAdapter extends ClassVisitor {
super.visitNestMember(nestMember);
}
/**
* <b>Experimental, use at your own risk.</b>.
*
* @param permittedSubtype the internal name of a permitted subtype.
* @deprecated this API is experimental.
*/
@Override
@Deprecated
public void visitPermittedSubtypeExperimental(final String permittedSubtype) {
checkState();
CheckMethodAdapter.checkInternalName(version, permittedSubtype, "permittedSubtype");
......
......@@ -30,6 +30,7 @@ package org.objectweb.asm.util;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
......@@ -825,9 +826,7 @@ public class CheckMethodAdapter extends MethodVisitor {
checkLabel(labels[i], false, "label at index " + i);
}
super.visitTableSwitchInsn(min, max, dflt, labels);
for (Label label : labels) {
referencedLabels.add(label);
}
Collections.addAll(referencedLabels, labels);
++insnCount;
}
......@@ -844,9 +843,7 @@ public class CheckMethodAdapter extends MethodVisitor {
}
super.visitLookupSwitchInsn(dflt, keys, labels);
referencedLabels.add(dflt);
for (Label label : labels) {
referencedLabels.add(label);
}
Collections.addAll(referencedLabels, labels);
++insnCount;
}
......@@ -1079,7 +1076,8 @@ public class CheckMethodAdapter extends MethodVisitor {
|| value == Opcodes.NULL
|| value == Opcodes.UNINITIALIZED_THIS) {
return;
} else if (value instanceof String) {
}
if (value instanceof String) {
checkInternalName(version, (String) value, "Invalid stack frame value");
} else if (value instanceof Label) {
referencedLabels.add((Label) value);
......
......@@ -302,7 +302,14 @@ public class Textifier extends Printer {
text.add(stringBuilder.toString());
}
/**
* <b>Experimental, use at your own risk.</b>.
*
* @param permittedSubtype the internal name of a permitted subtype.
* @deprecated this API is experimental.
*/
@Override
@Deprecated
public void visitPermittedSubtypeExperimental(final String permittedSubtype) {
stringBuilder.setLength(0);
stringBuilder.append(tab).append("PERMITTEDSUBTYPE ");
......
......@@ -187,7 +187,14 @@ public final class TraceClassVisitor extends ClassVisitor {
super.visitNestMember(nestMember);
}
/**
* <b>Experimental, use at your own risk.</b>.
*
* @param permittedSubtype the internal name of a permitted subtype.
* @deprecated this API is experimental.
*/
@Override
@Deprecated
public void visitPermittedSubtypeExperimental(final String permittedSubtype) {
p.visitPermittedSubtypeExperimental(permittedSubtype);
super.visitPermittedSubtypeExperimental(permittedSubtype);
......
......@@ -372,7 +372,14 @@ public class ClassWriter extends ClassVisitor {
nestMemberClasses.putShort(symbolTable.addConstantClass(nestMember).index);
}
/**
* <b>Experimental, use at your own risk.</b>
*
* @param permittedSubtype the internal name of a permitted subtype.
* @deprecated this API is experimental.
*/
@Override
@Deprecated
public final void visitPermittedSubtypeExperimental(final String permittedSubtype) {
if (permittedSubtypeClasses == null) {
permittedSubtypeClasses = new ByteVector();
......
......@@ -39,7 +39,7 @@ import java.util.regex.Pattern;
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-6.html">JVMS 6</a>
* @author Eric Bruneton
*/
final class Constants implements Opcodes {
final class Constants {
// The ClassFile attribute names, in the order they are defined in
// https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.7-300.
......@@ -147,7 +147,7 @@ final class Constants implements Opcodes {
// Constants to convert between normal and wide jump instructions.
// The delta between the GOTO_W and JSR_W opcodes and GOTO and JUMP.
static final int WIDE_JUMP_OPCODE_DELTA = GOTO_W - GOTO;
static final int WIDE_JUMP_OPCODE_DELTA = GOTO_W - Opcodes.GOTO;
// Constants to convert JVM opcodes to the equivalent ASM specific opcodes, and vice versa.
......@@ -160,24 +160,24 @@ final class Constants implements Opcodes {
// ASM specific opcodes, used for long forward jump instructions.
static final int ASM_IFEQ = IFEQ + ASM_OPCODE_DELTA;
static final int ASM_IFNE = IFNE + ASM_OPCODE_DELTA;
static final int ASM_IFLT = IFLT + ASM_OPCODE_DELTA;
static final int ASM_IFGE = IFGE + ASM_OPCODE_DELTA;
static final int ASM_IFGT = IFGT + ASM_OPCODE_DELTA;
static final int ASM_IFLE = IFLE + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPEQ = IF_ICMPEQ + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPNE = IF_ICMPNE + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPLT = IF_ICMPLT + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPGE = IF_ICMPGE + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPGT = IF_ICMPGT + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPLE = IF_ICMPLE + ASM_OPCODE_DELTA;
static final int ASM_IF_ACMPEQ = IF_ACMPEQ + ASM_OPCODE_DELTA;
static final int ASM_IF_ACMPNE = IF_ACMPNE + ASM_OPCODE_DELTA;
static final int ASM_GOTO = GOTO + ASM_OPCODE_DELTA;
static final int ASM_JSR = JSR + ASM_OPCODE_DELTA;
static final int ASM_IFNULL = IFNULL + ASM_IFNULL_OPCODE_DELTA;
static final int ASM_IFNONNULL = IFNONNULL + ASM_IFNULL_OPCODE_DELTA;
static final int ASM_IFEQ = Opcodes.IFEQ + ASM_OPCODE_DELTA;
static final int ASM_IFNE = Opcodes.IFNE + ASM_OPCODE_DELTA;
static final int ASM_IFLT = Opcodes.IFLT + ASM_OPCODE_DELTA;
static final int ASM_IFGE = Opcodes.IFGE + ASM_OPCODE_DELTA;
static final int ASM_IFGT = Opcodes.IFGT + ASM_OPCODE_DELTA;
static final int ASM_IFLE = Opcodes.IFLE + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPEQ = Opcodes.IF_ICMPEQ + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPNE = Opcodes.IF_ICMPNE + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPLT = Opcodes.IF_ICMPLT + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPGE = Opcodes.IF_ICMPGE + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPGT = Opcodes.IF_ICMPGT + ASM_OPCODE_DELTA;
static final int ASM_IF_ICMPLE = Opcodes.IF_ICMPLE + ASM_OPCODE_DELTA;
static final int ASM_IF_ACMPEQ = Opcodes.IF_ACMPEQ + ASM_OPCODE_DELTA;
static final int ASM_IF_ACMPNE = Opcodes.IF_ACMPNE + ASM_OPCODE_DELTA;
static final int ASM_GOTO = Opcodes.GOTO + ASM_OPCODE_DELTA;
static final int ASM_JSR = Opcodes.JSR + ASM_OPCODE_DELTA;
static final int ASM_IFNULL = Opcodes.IFNULL + ASM_IFNULL_OPCODE_DELTA;
static final int ASM_IFNONNULL = Opcodes.IFNONNULL + ASM_IFNULL_OPCODE_DELTA;
static final int ASM_GOTO_W = 220;
private Constants() {}
......
......@@ -31,11 +31,8 @@ final class RecordComponentWriter extends RecordComponentVisitor {
/** Where the constants used in this RecordComponentWriter must be stored. */
private final SymbolTable symbolTable;
// Note: fields are ordered as in the component_info structure, and those related to attributes
// are ordered as in Section TODO of the JVMS.
// The field accessFlag doesn't exist in the component_info structure but is used to carry
// ACC_DEPRECATED which is represented by an attribute in the structure and as an access flag by
// ASM.
// Note: fields are ordered as in the record_component_info structure, and those related to
// attributes are ordered as in Section 4.7 of the JVMS.
/** The name_index field of the Record attribute. */
private final int nameIndex;
......
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