All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.external.asm.ThrowsClause Maven / Gradle / Ivy

Go to download

JMockit is a Java toolkit for automated developer testing. It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external APIs; JUnit (4 & 5) and TestNG test runners are supported. It also contains an advanced code coverage tool.

There is a newer version: 1.49
Show newest version
package mockit.external.asm;

import javax.annotation.*;

/**
 * Stores the exceptions that can be thrown by a method/constructor. For each thrown exception, stores the index of the
 * constant pool item containing the internal name of the thrown exception class. Provides the bytecode
 * {@linkplain #getSize() size}  of the "Exceptions" attribute, and allows it to be
 * {@linkplain #put(ByteVector) written out}.
 */
final class ThrowsClause
{
   @Nonnull private final int[] exceptions;
   @Nonnegative private final int attributeIndex;

   ThrowsClause(@Nonnull ConstantPoolGeneration cp, @Nonnull String[] exceptionTypeDescs) {
      int n = exceptionTypeDescs.length;
      exceptions = new int[n];

      for (int i = 0; i < n; i++) {
         String exceptionTypeDesc = exceptionTypeDescs[i];
         exceptions[i] = cp.newClass(exceptionTypeDesc);
      }

      attributeIndex = cp.newUTF8("Exceptions");
   }

   @Nonnegative int getCount() { return exceptions.length; }
   @Nonnegative int getExceptionIndex(@Nonnegative int exceptionIndex) { return exceptions[exceptionIndex]; }
   @Nonnegative int getSize() { return 8 + 2 * exceptions.length; }

   void put(@Nonnull ByteVector out) {
      int[] exceptions = this.exceptions;
      int n = exceptions.length;
      out.putShort(attributeIndex).putInt(2 * n + 2);
      out.putShort(n);

      for (int exception : exceptions) {
         out.putShort(exception);
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy