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.*;

final class ThrowsClause
{
   @Nonnull private final ConstantPoolGeneration cp;

   /**
    * Number of exceptions that can be thrown by the method/constructor.
    */
   @Nonnegative private final int exceptionCount;

   /**
    * The exceptions that can be thrown by the method/constructor. More precisely, this array contains the indexes of
    * the constant pool items that contain the internal names of these exception classes.
    */
   @Nullable private final int[] exceptions;

   ThrowsClause(@Nonnull ConstantPoolGeneration cp, @Nullable String[] exceptionTypeDescs) {
      this.cp = cp;

      if (exceptionTypeDescs == null) {
         exceptionCount = 0;
         exceptions = null;
         return;
      }

      int n = exceptionTypeDescs.length;
      exceptionCount = n;
      exceptions = n == 0 ? null : new int[n];

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

   @Nonnegative int getExceptionCount() { return exceptionCount; }

   boolean hasExceptions() { return exceptionCount > 0; }

   int getExceptionIndex(int i) {
      //noinspection ConstantConditions
      return exceptions[i];
   }

   @Nonnegative
   int getSize() {
      if (exceptionCount > 0) {
         cp.newUTF8("Exceptions");
         return 8 + 2 * exceptionCount;
      }

      return 0;
   }

   void put(@Nonnull ByteVector out) {
      int n = exceptionCount;

      if (n > 0) {
         @SuppressWarnings("ConstantConditions") @Nonnull int[] exceptions = this.exceptions;

         out.putShort(cp.newUTF8("Exceptions")).putInt(2 * n + 2);
         out.putShort(n);

         for (int i = 0; i < n; i++) {
            out.putShort(exceptions[i]);
         }
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy