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

mockit.asm.ThrowsClause Maven / Gradle / Ivy

Go to download

JMockit is a Java toolkit for automated developer testing. It contains mocking/faking APIs and a code coverage tool, supporting both JUnit and TestNG. The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested in isolation from selected dependencies.

There is a newer version: 1.49
Show newest version
package mockit.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