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

Merge branch 'improve-nestmates-code-quality' into 'ASM7_NESTMATES'

Improve the quality of the code related to nest mates.

See merge request asm/asm!168
parents ac801b75 b157bf68
......@@ -155,12 +155,12 @@ public class ClassRemapper extends ClassVisitor {
}
@Override
public void visitNestHost(String nestHost) {
public void visitNestHost(final String nestHost) {
super.visitNestHost(remapper.mapType(nestHost));
}
@Override
public void visitNestMember(String nestMember) {
public void visitNestMember(final String nestMember) {
super.visitNestMember(remapper.mapType(nestMember));
}
......
......@@ -43,7 +43,7 @@ public class RemappingAnnotationAdapter extends AnnotationVisitor {
protected final Remapper remapper;
public RemappingAnnotationAdapter(final AnnotationVisitor av, final Remapper remapper) {
this(Opcodes.ASM7, av, remapper);
this(Opcodes.ASM6, av, remapper);
}
protected RemappingAnnotationAdapter(
......
......@@ -50,7 +50,7 @@ public class RemappingClassAdapter extends ClassVisitor {
protected String className;
public RemappingClassAdapter(final ClassVisitor cv, final Remapper remapper) {
this(Opcodes.ASM7, cv, remapper);
this(Opcodes.ASM6, cv, remapper);
}
protected RemappingClassAdapter(final int api, final ClassVisitor cv, final Remapper remapper) {
......@@ -140,16 +140,6 @@ public class RemappingClassAdapter extends ClassVisitor {
desc == null ? null : remapper.mapMethodDesc(desc));
}
@Override
public void visitNestHost(String nestHost) {
throw new RuntimeException("RemappingClassAdapter is deprecated, use ClassRemapper instead");
}
@Override
public void visitNestMember(String nestMember) {
throw new RuntimeException("RemappingClassAdapter is deprecated, use ClassRemapper instead");
}
protected FieldVisitor createRemappingFieldAdapter(FieldVisitor fv) {
return new RemappingFieldAdapter(fv, remapper);
}
......
......@@ -45,7 +45,7 @@ public class RemappingFieldAdapter extends FieldVisitor {
private final Remapper remapper;
public RemappingFieldAdapter(final FieldVisitor fv, final Remapper remapper) {
this(Opcodes.ASM7, fv, remapper);
this(Opcodes.ASM6, fv, remapper);
}
protected RemappingFieldAdapter(final int api, final FieldVisitor fv, final Remapper remapper) {
......
......@@ -48,7 +48,7 @@ public class RemappingMethodAdapter extends LocalVariablesSorter {
public RemappingMethodAdapter(
final int access, final String desc, final MethodVisitor mv, final Remapper remapper) {
this(Opcodes.ASM7, access, desc, mv, remapper);
this(Opcodes.ASM6, access, desc, mv, remapper);
}
protected RemappingMethodAdapter(
......
......@@ -47,7 +47,7 @@ public class RemappingSignatureAdapter extends SignatureVisitor {
private String className;
public RemappingSignatureAdapter(final SignatureVisitor v, final Remapper remapper) {
this(Opcodes.ASM7, v, remapper);
this(Opcodes.ASM6, v, remapper);
}
protected RemappingSignatureAdapter(
......
......@@ -188,7 +188,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.1">JVMS
* 4.1</a>
*/
private static void dumpAttributeList(final Parser parser, final Builder builder) throws IOException {
private static void dumpAttributeList(final Parser parser, final Builder builder)
throws IOException {
int attributeCount = builder.add("attributes_count: ", parser.u2());
SortedBuilder sortedBuilder = builder.addSortedBuilder();
for (int i = 0; i < attributeCount; ++i) {
......@@ -206,7 +207,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.4">JVMS
* 4.4</a>
*/
private static CpInfo parseCpInfo(final Parser parser, final ClassContext classContext) throws IOException {
private static CpInfo parseCpInfo(final Parser parser, final ClassContext classContext)
throws IOException {
int tag = parser.u1();
switch (tag) {
case 7:
......@@ -407,7 +409,8 @@ class ClassDump {
* @param classContext a context to lookup constant pool items from their index.
* @throws IOException if the class can't be parsed.
*/
ConstantInterfaceMethodRefInfo(final Parser parser, final ClassContext classContext) throws IOException {
ConstantInterfaceMethodRefInfo(final Parser parser, final ClassContext classContext)
throws IOException {
super(classContext);
this.classIndex = parser.u2();
this.nameAndTypeIndex = parser.u2();
......@@ -551,7 +554,8 @@ class ClassDump {
* @param classContext a context to lookup constant pool items from their index.
* @throws IOException if the class can't be parsed.
*/
ConstantNameAndTypeInfo(final Parser parser, final ClassContext classContext) throws IOException {
ConstantNameAndTypeInfo(final Parser parser, final ClassContext classContext)
throws IOException {
super(classContext);
this.nameIndex = parser.u2();
this.descriptorIndex = parser.u2();
......@@ -600,7 +604,8 @@ class ClassDump {
* @param classContext a context to lookup constant pool items from their index.
* @throws IOException if the class can't be parsed.
*/
ConstantMethodHandleInfo(final Parser parser, final ClassContext classContext) throws IOException {
ConstantMethodHandleInfo(final Parser parser, final ClassContext classContext)
throws IOException {
super(classContext);
this.referenceKind = parser.u1();
this.referenceIndex = parser.u2();
......@@ -628,7 +633,8 @@ class ClassDump {
* @param classContext a context to lookup constant pool items from their index.
* @throws IOException if the class can't be parsed.
*/
ConstantMethodTypeInfo(final Parser parser, final ClassContext classContext) throws IOException {
ConstantMethodTypeInfo(final Parser parser, final ClassContext classContext)
throws IOException {
super(classContext);
this.descriptorIndex = parser.u2();
}
......@@ -656,7 +662,8 @@ class ClassDump {
* @param classContext a context to lookup constant pool items from their index.
* @throws IOException if the class can't be parsed.
*/
ConstantInvokeDynamicInfo(final Parser parser, final ClassContext classContext) throws IOException {
ConstantInvokeDynamicInfo(final Parser parser, final ClassContext classContext)
throws IOException {
super(classContext);
this.bootstrapMethodAttrIndex = parser.u2();
this.nameAndTypeIndex = parser.u2();
......@@ -749,7 +756,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.6">JVMS
* 4.6</a>
*/
private static void dumpMethodInfo(final Parser parser, final Builder builder) throws IOException {
private static void dumpMethodInfo(final Parser parser, final Builder builder)
throws IOException {
// method_info has the same top level structure as field_info.
dumpFieldInfo(parser, builder);
}
......@@ -859,7 +867,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.3">JVMS
* 4.7.3</a>
*/
private static void dumpCodeAttribute(final Parser parser, final Builder builder) throws IOException {
private static void dumpCodeAttribute(final Parser parser, final Builder builder)
throws IOException {
builder.add("max_stack: ", parser.u2());
builder.add("max_locals: ", parser.u2());
int codeLength = parser.u4();
......@@ -913,8 +922,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5">JVMS
* 6.5</a>
*/
private static void dumpInstructions(final int codeLength, final Parser parser, final Builder builder)
throws IOException {
private static void dumpInstructions(
final int codeLength, final Parser parser, final Builder builder) throws IOException {
int bytecodeOffset = 0; // Number of bytes parsed so far.
int insnIndex = 0; // Number of instructions parsed so far.
while (bytecodeOffset < codeLength) {
......@@ -1423,7 +1432,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.2">JVMS
* 4.7.2</a>
*/
private static void dumpVerificationTypeInfo(final Parser parser, final Builder builder) throws IOException {
private static void dumpVerificationTypeInfo(final Parser parser, final Builder builder)
throws IOException {
int tag = builder.add("tag: ", parser.u1());
if (tag > 8) {
throw new IOException("Unknown verification_type_info tag: " + tag);
......@@ -1444,7 +1454,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.5">JVMS
* 4.7.5</a>
*/
private static void dumpExceptionsAttribute(final Parser parser, final Builder builder) throws IOException {
private static void dumpExceptionsAttribute(final Parser parser, final Builder builder)
throws IOException {
int exceptionCount = builder.add("number_of_exceptions: ", parser.u2());
for (int i = 0; i < exceptionCount; ++i) {
builder.addCpInfo("exception_index: ", parser.u2());
......@@ -1460,7 +1471,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.6">JVMS
* 4.7.6</a>
*/
private static void dumpInnerClassesAttribute(final Parser parser, final Builder builder) throws IOException {
private static void dumpInnerClassesAttribute(final Parser parser, final Builder builder)
throws IOException {
int classCount = builder.add("number_of_classes: ", parser.u2());
for (int i = 0; i < classCount; ++i) {
builder.addCpInfo("inner_class_info_index: ", parser.u2());
......@@ -1504,7 +1516,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9">JVMS
* 4.7.9</a>
*/
private static void dumpSignatureAttribute(final Parser parser, final Builder builder) throws IOException {
private static void dumpSignatureAttribute(final Parser parser, final Builder builder)
throws IOException {
builder.addCpInfo("signature_index: ", parser.u2());
}
......@@ -1517,7 +1530,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.10">JVMS
* 4.7.10</a>
*/
private static void dumpSourceFileAttribute(final Parser parser, final Builder builder) throws IOException {
private static void dumpSourceFileAttribute(final Parser parser, final Builder builder)
throws IOException {
builder.addCpInfo("sourcefile_index: ", parser.u2());
}
......@@ -1531,8 +1545,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.11">JVMS
* 4.7.11</a>
*/
private static void dumpSourceDebugAttribute(final int attributeLength, final Parser parser, final Builder builder)
throws IOException {
private static void dumpSourceDebugAttribute(
final int attributeLength, final Parser parser, final Builder builder) throws IOException {
byte[] attributeData = parser.bytes(attributeLength);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < attributeData.length; ++i) {
......@@ -1589,8 +1603,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.14">JVMS
* 4.7.14</a>
*/
private static void dumpLocalVariableTypeTableAttribute(final Parser parser, final Builder builder)
throws IOException {
private static void dumpLocalVariableTypeTableAttribute(
final Parser parser, final Builder builder) throws IOException {
int localVariableCount = builder.add("local_variable_type_table_length: ", parser.u2());
for (int i = 0; i < localVariableCount; ++i) {
int startPc = builder.addInsnIndex("start_pc: ", parser.u2());
......@@ -1620,8 +1634,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16">JVMS
* 4.7.16</a>
*/
private static void dumpRuntimeVisibleAnnotationsAttribute(final Parser parser, final Builder builder)
throws IOException {
private static void dumpRuntimeVisibleAnnotationsAttribute(
final Parser parser, final Builder builder) throws IOException {
int annotationCount = builder.add("num_annotations: ", parser.u2());
for (int i = 0; i < annotationCount; ++i) {
dumpAnnotation(parser, builder);
......@@ -1637,7 +1651,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16">JVMS
* 4.7.16</a>
*/
private static void dumpAnnotation(final Parser parser, final Builder builder) throws IOException {
private static void dumpAnnotation(final Parser parser, final Builder builder)
throws IOException {
builder.addCpInfo("type_index: ", parser.u2());
int elementValuePairCount = builder.add("num_element_value_pairs: ", parser.u2());
for (int i = 0; i < elementValuePairCount; ++i) {
......@@ -1656,7 +1671,8 @@ class ClassDump {
* href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16.1">JVMS
* 4.7.16.1</a>
*/
private static void dumpElementValue(final Parser parser, final Builder builder) throws IOException {
private static void dumpElementValue(final Parser parser, final Builder builder)
throws IOException {
int tag = parser.u1();
switch (tag) {
case 'B':
......@@ -1701,8 +1717,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.17">JVMS
* 4.7.17</a>
*/
private static void dumpRuntimeInvisibleAnnotationsAttribute(final Parser parser, final Builder builder)
throws IOException {
private static void dumpRuntimeInvisibleAnnotationsAttribute(
final Parser parser, final Builder builder) throws IOException {
dumpRuntimeVisibleAnnotationsAttribute(parser, builder);
}
......@@ -1749,8 +1765,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.20">JVMS
* 4.7.20</a>
*/
private static void dumpRuntimeVisibleTypeAnnotationsAttribute(final Parser parser, final Builder builder)
throws IOException {
private static void dumpRuntimeVisibleTypeAnnotationsAttribute(
final Parser parser, final Builder builder) throws IOException {
int annotationCount = builder.add("num_annotations: ", parser.u2());
SortedBuilder sortedBuilder = builder.addSortedBuilder();
for (int i = 0; i < annotationCount; ++i) {
......@@ -1869,8 +1885,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.21">JVMS
* 4.7.21</a>
*/
private static void dumpRuntimeInvisibleTypeAnnotationsAttribute(final Parser parser, final Builder builder)
throws IOException {
private static void dumpRuntimeInvisibleTypeAnnotationsAttribute(
final Parser parser, final Builder builder) throws IOException {
dumpRuntimeVisibleTypeAnnotationsAttribute(parser, builder);
}
......@@ -1936,7 +1952,8 @@ class ClassDump {
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.25">JVMS
* 4.7.25</a>
*/
private static void dumpModuleAttribute(final Parser parser, final Builder builder) throws IOException {
private static void dumpModuleAttribute(final Parser parser, final Builder builder)
throws IOException {
builder.addCpInfo("name: ", parser.u2());
builder.add("access: ", parser.u2());
builder.addCpInfo("version: ", parser.u2());
......@@ -2049,7 +2066,8 @@ class ClassDump {
* @see <a
* href="http://docs.oracle.com/javame/config/cldc/opt-pkgs/api/cldc/api/Appendix1-verifier.pdf">CLDC</a>
*/
private static void dumpStackMapAttribute(final Parser parser, final Builder builder) throws IOException {
private static void dumpStackMapAttribute(final Parser parser, final Builder builder)
throws IOException {
int entryCount = builder.add("number_of_entries: ", parser.u2());
for (int i = 0; i < entryCount; ++i) {
builder.addInsnIndex("offset: ", parser.u2());
......
......@@ -121,10 +121,10 @@ public class ClassNode extends ClassVisitor {
/** The inner classes of this class. */
public List<InnerClassNode> innerClasses;
/** The internal name of the nest host class of this class. */
/** The internal name of the nest host class of this class. May be <tt>null</tt>. */
public String nestHostClass;
/** The internal names of the nest members of this class. */
/** The internal names of the nest members of this class. May be <tt>null</tt>. */
public List<String> nestMembers;
/** The fields of this class. */
......
......@@ -316,7 +316,7 @@ public class CheckClassAdapter extends ClassVisitor {
* Constructs a new {@link CheckClassAdapter}.
*
* @param api the ASM API version implemented by this visitor. Must be one of {@link
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
* @param classVisitor the class visitor to which this adapter must delegate calls.
* @param checkDataFlow <tt>true</tt> to perform basic data flow checks, or <tt>false</tt> to not
* perform any data flow check (see {@link CheckMethodAdapter}). This option requires valid
......@@ -439,7 +439,7 @@ public class CheckClassAdapter extends ClassVisitor {
CheckMethodAdapter.checkInternalName(nestMember, "nestMember");
if (visitNestHostCalled) {
throw new IllegalStateException(
"visitMemberOfNest and and visitNestHost are mutually exclusive.");
"visitMemberOfNest and visitNestHost are mutually exclusive.");
}
String packageName = packageName(nestMember);
if (nestMemberPackageName == null) {
......
......@@ -236,7 +236,7 @@ public class Textifier extends Printer {
}
@Override
public void visitNestHost(String nestHost) {
public void visitNestHost(final String nestHost) {
stringBuilder.setLength(0);
stringBuilder.append(tab).append("NESTHOST ");
appendDescriptor(INTERNAL_NAME, nestHost);
......
......@@ -136,11 +136,12 @@ public abstract class ClassVisitor {
}
/**
* Visits the nest host class of the current class. A nest is a set of classes of the same package
* that share access to their private members. The host class should list the current class as
* {@link #visitNestMember(String) nest member}. This method must be called only once and only if
* the current class is a member of a nest. A class is implicitly its own nest, so it's invalid to
* call this method with the current class as argument.
* Visits the nest host class of the class. A nest is a set of classes of the same package that
* share access to their private members. One of these classes, called the host, lists the other
* members of the nest, which in turn should link to the host of their nest. This method must be
* called only once and only if the visited class is a non-host member of a nest. A class is
* implicitly its own nest, so it's invalid to call this method with the visited class name as
* argument.
*
* @param nestHost the internal name of the host class of the nest.
*/
......@@ -223,8 +224,10 @@ public abstract class ClassVisitor {
/**
* Visits a member of the nest. A nest is a set of classes of the same package that share access
* to their private members. The nest member should declare the current class as its {@link
* #visitNestMember(String) host class}.
* to their private members. One of these classes, called the host, lists the other members of the
* nest, which in turn should link to the host of their nest. This method must be called only if
* the visited class is the host of a nest. A nest host is implicitly a member of its own nest, so
* it's invalid to call this method with the visited class name as argument.
*
* @param nestMember the internal name of a nest member.
*/
......
Supports Markdown
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