Master mock method.

        This gets "instantiated" in AddMethod(). Execute the code snippet of
        the method and return the "ret" variable if it was set.
494590
def mock_method(self, interface, dbus_method, in_signature, *args, **kwargs):
        '''
        '''
        # print('mock_method', dbus_method, self, in_signature, args, kwargs, file=sys.stderr)

        # convert types of arguments according to signature, using
        # MethodCallMessage.append(); this will also provide type/length
        # checks, except for the case of an empty signature
        if in_signature == '' and len(args) > 0:
            raise TypeError('Fewer items found in D-Bus signature than in Python arguments')
        m = dbus.connection.MethodCallMessage('a.b', '/a', 'a.b', 'a')
        m.append(signature=in_signature, *args)
        args = m.get_args_list()

        self.log(dbus_method + self.format_args(args))
        self.call_log.append((int(time.time()), str(dbus_method), args))
        self.MethodCalled(dbus_method, args)

        # The code may be a Python 3 string to interpret, or may be a function
        # object (if AddMethod was called from within Python itself, rather than
        # over D-Bus).
        code = self.methods[interface][dbus_method][2]
        if code and isinstance(code, types.FunctionType):
            return code(self, *args)
        elif code:
            loc = locals().copy()
            exec(code, globals(), loc)
            if 'ret' in loc:
                return loc['ret']
1081058
def _exec_method(self, method, request, data, *args, **kw):
        
        if self._is_data_method(request):
            return method(data, request, *args, **kw)
        else:
            return method(request, *args, **kw)
977096
def code(self, code=None, ret_r=False):
        '''
        
        '''
        if code or ret_r:
            self._code = code
            return self
        return self._code
35609
def _capture(self, args, kwargs):
        ''''''
        self.called = self.called + 1
        self.method_args.append(args)
        self.named_method_args.append(kwargs)
        self.never_called = False
404746
def method_call_if_def(obj, attr_name, m_name, default, *args, **kwargs):
    
    try:
        attr = getattr(obj, attr_name)
    except AttributeError:
        return default
    else:
        return getattr(attr, m_name)(*args, **kwargs)
1036644
def AddMethod(self, function, name=None):
        
        method = MethodWrapper(self, function, name)
        self.added_methods.append(method)
335426
def addMethod(self, m):
        
        if m.nargs == -1:
            m.nargs = len([a for a in marshal.genCompleteTypes(m.sigIn)])
            m.nret = len([a for a in marshal.genCompleteTypes(m.sigOut)])
        self.methods[m.name] = m
        self._xml = None
283436
def _VerifyMethodCall(self):
    

    expected = self._PopNextMethod()

    # Loop here, because we might have a MethodGroup followed by another
    # group.
    while isinstance(expected, MethodGroup):
      expected, method = expected.MethodCalled(self)
      if method is not None:
        return method

    # This is a mock method, so just check equality.
    if expected != self:
      raise UnexpectedMethodCallError(self, expected)

    return expected
1246565
@Override
    public void visitCode(Code obj) {
        Method m = getMethod();
        if (!Values.CONSTRUCTOR.equals(m.getName())) {
            super.visitCode(obj);
        }
    }
840830
def value_call(method_name, *args, **kwargs):
    

    def value_call(value, context, **_params):
        method = getattr(value, method_name)
        return _call(method, args, kwargs)

    return value_call
464862
private String generateMethodKey(CtMethod method) throws NotFoundException {
        String classQualifiedName = method.getDeclaringClass().getName();
        String methodSimpleName = method.getName();
        List<String> argClassQualifiedNames = getArgClassQualifiedNames(method);
        return TestMethod.generateMethodKey(classQualifiedName, methodSimpleName, argClassQualifiedNames);
    }
1298173
def get_method_invocation_code(c, method)
      target = method.singleton ? get_complete_class_name(c) : instance_name(c)
      "#{target}.#{method.name}#{to_params_part(method.params)}#{get_block_code(method)}"
    end
885924
private static Method getMethod(Class<?> clazz, String methodName)
    {
        try
        {
            char string[] = methodName.toCharArray();
            string[0] = Character.toUpperCase(string[0]);
            methodName = new String(string);
            try
            {
                return clazz.getDeclaredMethod("get" + methodName);
            }
            catch (NoSuchMethodException e)
            {
                return clazz.getDeclaredMethod("is" + methodName);
            }
        }
        catch (NoSuchMethodException e)
        {
            return null;
        }
    }
1279800
private static String getClassMethod(Class clazz, Method method) {
		StringBuilder builder = new StringBuilder();
		builder.append(clazz.getName()).append(".").append(method.getName());
		builder.append("(");
		if (method.getParameterCount() > 0) {
			for (int i = 0; i < method.getParameterCount(); i++) {
				Parameter param = method.getParameters()[i];
				builder.append(param.getType().getSimpleName()).append(" ").append(param.getName());

				if (i + 1 < method.getParameterCount()) {
					builder.append(", ");
				}
			}
		}
		builder.append(")");
		return builder.toString();
	}
1364366
public Method getMethod(Class clz, String mangledMethodName) {

		Map<String, Method> methods = methodsByComponentType.get(clz);

		if (methods == null) {
			methods = new HashMap<String, Method>();
			methodsByComponentType.put(clz, methods);

			for (Method method : clz.getDeclaredMethods()) {
				Class<?>[] param = method.getParameterTypes();
				String mangledName1 = method.getName() + "__" + param.length;
				String mangledName2 = AbstractSkeleton
						.mangleName(method, false);

				if (param.length == 0 || !methods.containsKey(method.getName())) {
					methods.put(method.getName(), method);
				}

				methods.put(mangledName1, method);
				methods.put(mangledName2, method);
			}
		}

		return (Method) methods.get(mangledMethodName);
	}
364052
private Map<Class<?>, Object> executeBeforeBenchClass(
			final Map<Class<?>, Object> instantiatedObj,
			final BenchmarkResult res) {

		final Map<Class<?>, Object> returnVal = new Hashtable<Class<?>, Object>();

		// invoking before bench class
		for (final Class<?> clazz : instantiatedObj.keySet()) {

			final Object objectToUse = instantiatedObj.get(clazz);
			// ..the search for the beforeClassMeth begins...
			Method beforeClassMeth = null;
			boolean continueVal = true;
			try {
				beforeClassMeth = BenchmarkMethod
						.findAndCheckAnyMethodByAnnotation(clazz,
								BeforeBenchClass.class);
				// ... and if this search is throwing an exception, the
				// exception will be added and a flag is set to break up
			} catch (final PerfidixMethodCheckException e) {
				res.addException(e);
				continueVal = false;
			}
			// if everything worked well...
			if (continueVal) {
				if (beforeClassMeth == null) {
					// ...either the objects is directly mapped to the class
					// for executing the benches
					returnVal.put(clazz, objectToUse);
				} else {
					// ... or the beforeMethod will be executed and a
					// possible exception stored to the result...
					final PerfidixMethodCheckException beforeByCheck = BenchmarkExecutor
							.checkMethod(objectToUse, BeforeBenchClass.class,
									beforeClassMeth);
					if (beforeByCheck == null) {
						final PerfidixMethodInvocationException beforeByInvok = BenchmarkExecutor
								.invokeMethod(objectToUse,
										BeforeBenchClass.class, beforeClassMeth);
						if (beforeByInvok == null) {
							returnVal.put(clazz, objectToUse);
						} else {
							res.addException(beforeByInvok);
						}
					} else {
						res.addException(beforeByCheck);
					}
				}
			}
		}
		return returnVal;
	}
598798
private boolean insertCodeBodyHook(TestMethod method, CtMethod ctMethod,
            String classQualifiedName, String methodSimpleName, String methodArgClassesStr) throws CannotCompileException {
        String hookClassName = HookMethodDef.class.getCanonicalName();
        String initializeSrc = hookInitializeSrc();
        boolean transformed = false;

        // iterate code body in the inverse order,
        // so that beforeHook is always inserted after the afterHook of the previous line
        // even if target line of these two hooks are the same
        for (int i = method.getCodeBody().size() - 1; i >= 0; i--) {
            int hookedLine = method.getCodeBody().get(i).getStartLine();

            // insert afterHook first and beforeHook second in each iteration,
            // so that beforeHook is always inserted before the afterHook
            // even if actual inserted lines for these two hooks are the same

            int afterHookInsertedLine = afterHookInsertLine(method, i);
            if (afterHookInsertedLine != -1) {
                int actualAfterHookInsertedLine = ctMethod.insertAt(afterHookInsertedLine, false, null);
                ctMethod.insertAt(afterHookInsertedLine,
                        String.format("%s%s.afterCodeLineHook(\"%s\",\"%s\",\"%s\",\"%s\",%d, %d);",
                                initializeSrc, hookClassName, classQualifiedName,
                                methodSimpleName, methodSimpleName,
                                methodArgClassesStr, hookedLine, actualAfterHookInsertedLine));
                transformed = true;
            }

            int beforeHookInsertedLine = beforeHookInsertLine(method, i);
            if (beforeHookInsertedLine != -1) {
                int actualBeforeHookInsertedLine = ctMethod.insertAt(beforeHookInsertedLine, false, null);
                ctMethod.insertAt(beforeHookInsertedLine,
                        String.format("%s%s.beforeCodeLineHook(\"%s\",\"%s\",\"%s\",\"%s\",%d, %d);",
                                initializeSrc, hookClassName, classQualifiedName,
                                methodSimpleName, methodSimpleName,
                                methodArgClassesStr, hookedLine, actualBeforeHookInsertedLine));
                transformed = true;
            }
        }

        return transformed;
    }