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

mockit.internal.util.ParameterNameExtractor 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
/*
 * Copyright (c) 2006 JMockit developers
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.internal.util;

import java.util.*;
import javax.annotation.*;

import mockit.asm.*;
import mockit.asm.ClassMetadataReader.*;
import mockit.internal.*;
import mockit.internal.state.*;

public final class ParameterNameExtractor
{
   private static final EnumSet PARAMETERS = EnumSet.of(Attribute.Parameters);

   private ParameterNameExtractor() {}

   @Nonnull
   public static String extractNames(@Nonnull Class classOfInterest) {
      String className = classOfInterest.getName();
      String classDesc = className.replace('.', '/');

      if (!ParameterNames.hasNamesForClass(classDesc)) {
         byte[] classfile = ClassFile.readBytesFromClassFile(classDesc);
         ClassMetadataReader cmr = new ClassMetadataReader(classfile, PARAMETERS);
         List methods = cmr.getMethods();

         for (MethodInfo method : methods) {
            if (!method.isSynthetic()) {
               String[] parameters = method.parameters;

               if (parameters != null) {
                  ParameterNames.register(classDesc, method.name, method.desc, parameters);
               }
            }
         }
      }

      return classDesc;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy