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

mockit.internal.state.ParameterNames Maven / Gradle / Ivy

/*
 * Copyright (c) 2006-2012 Rogério Liesenfeld
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.internal.state;

import java.util.*;

import mockit.external.asm4.*;

public final class ParameterNames
{
   private static final Map> classesToMethodsToParameters =
      new HashMap>();

   public static boolean hasNamesForClass(String classDesc)
   {
      return classesToMethodsToParameters.containsKey(classDesc);
   }

   public static void registerName(String classDesc, String methodName, String methodDesc, String name)
   {
      if ("this".equals(name)) {
         return;
      }

      Map methodsToParameters = classesToMethodsToParameters.get(classDesc);

      if (methodsToParameters == null) {
         methodsToParameters = new HashMap();
         classesToMethodsToParameters.put(classDesc, methodsToParameters);
      }

      String methodKey = methodName + methodDesc;
      String[] parameterNames = methodsToParameters.get(methodKey);

      if (parameterNames == null) {
         parameterNames = new String[Type.getArgumentTypes(methodDesc).length];
         methodsToParameters.put(methodKey, parameterNames);
      }

      for (int i = 0; i < parameterNames.length; i++) {
         if (parameterNames[i] == null) {
            parameterNames[i] = name;
            break;
         }
      }
   }

   public static String getName(String classDesc, String methodDesc, int index)
   {
      Map methodsToParameters = classesToMethodsToParameters.get(classDesc);

      if (methodsToParameters == null) {
         return null;
      }

      String[] parameterNames = methodsToParameters.get(methodDesc);
      return parameterNames == null ? null : parameterNames[index];
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy