Using reflection, generate the related method and return it.
344873
def set_related_method(self, resource, full_resource_url):
        
        method_name = self.get_method_name(resource, 'get')

        def get(self, **kwargs):
            return self._call_api_single_related_resource(
                resource, full_resource_url, method_name, **kwargs
            )

        def get_list(self, **kwargs):
            return self._call_api_many_related_resources(
                resource, full_resource_url, method_name, **kwargs
            )

        if isinstance(full_resource_url, list):
            setattr(
                self, method_name,
                types.MethodType(get_list, self)
            )
        else:
            setattr(
                self, method_name,
                types.MethodType(get, self)
            )
814265
private static void generateSingleReadMethod(PrefsEntity entity) {
		// read method
		PrefsTransform transform;
		Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_CAMEL);

		for (PrefsProperty item : entity.getCollection()) {
			MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("get" + converter.convert(item.getName())).addModifiers(Modifier.PUBLIC)
					.addJavadoc("reads property <code>$L</code> from shared pref with key <code>$L</code>\n\n", item.getName(), item.getPreferenceKey())
					.addJavadoc("@return property $L value\n", item.getName()).returns(item.getPropertyType().getTypeName());

			if (item.hasTypeAdapter()) {
				transform = PrefsTransformer.lookup(item.typeAdapter.getDataTypeTypename());
			} else {
				transform = PrefsTransformer.lookup(item);
			}

			transform.generateReadProperty(methodBuilder, "prefs", typeName(item.getElement().asType()), "defaultBean", item, false, ReadType.RETURN);

			builder.addMethod(methodBuilder.build());
		}

	}
1320952
private Object getMethods(Class sender, String name, boolean isCallToSuper) {
        Object answer;

        final MetaMethodIndex.Entry entry = metaMethodIndex.getMethods(sender, name);
        if (entry == null)
            answer = FastArray.EMPTY_LIST;
        else
            if (isCallToSuper) {
                answer = entry.methodsForSuper;
            } else {
                answer = entry.methods;
            }

        if (answer == null) answer = FastArray.EMPTY_LIST;

        if (!isCallToSuper) {
            List used = GroovyCategorySupport.getCategoryMethods(name);
            if (used != null) {
                FastArray arr;
                if (answer instanceof MetaMethod) {
                    arr = new FastArray();
                    arr.add(answer);
                }
                else
                    arr = ((FastArray) answer).copy();

                for (Iterator iter = used.iterator(); iter.hasNext();) {
                    MetaMethod element = (MetaMethod) iter.next();
                    if (!element.getDeclaringClass().getTheClass().isAssignableFrom(sender))
                      continue;
                    filterMatchingMethodForCategory(arr, element);
                }
                answer = arr;
            }
        }
        return answer;
    }
968092
private static Method getMethod(final Class<?> mbean,
                                  final String method,
                                  final String... params) {
    try {
      final ClassLoader loader = mbean.getClassLoader();
      final Class<?>[] paramClasses = new Class<?>[params.length];
      for (int i = 0; i < params.length; i++) {
        paramClasses[i] = primitives.get(params[i]);
        if (paramClasses[i] == null) {
          paramClasses[i] = Class.forName(params[i], false, loader);
        }
      }
      return mbean.getMethod(method, paramClasses);
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      return null;
    }
  }
785351
def _generate_standard_methods(cls):
        """"""
        for state in cls.context.states_enum:
            getter_name = 'is_{name}'.format(name=state.value)
            cls.context.new_methods[getter_name] = utils.generate_getter(state)

            setter_name = 'set_{name}'.format(name=state.value)
            cls.context.new_methods[setter_name] = utils.generate_setter(state)

            checker_name = 'can_be_{name}'.format(name=state.value)
            checker = utils.generate_checker(state)
            cls.context.new_methods[checker_name] = checker

        cls.context.new_methods['actual_state'] = utils.actual_state
        cls.context.new_methods['as_enum'] = utils.as_enum
        cls.context.new_methods['force_set'] = utils.force_set
496434
def _GenerateNonImplementedMethod(self, method):
    
    return lambda inst, rpc_controller, request, callback: (
        self._NonImplementedMethod(method.name, rpc_controller, callback))
20206
private static void generateResetMethod(PrefsEntity entity) {
		// write method
		MethodSpec.Builder method = MethodSpec.methodBuilder("reset").addModifiers(Modifier.PUBLIC).addJavadoc("reset shared preferences\n").returns(Void.TYPE);

		if (entity.isImmutablePojo()) {
			ImmutableUtility.generateImmutableVariableInit(entity, method);
			ImmutableUtility.generateImmutableEntityCreation(entity, method, "bean", true);
		} else {
			method.addStatement("$T bean=new $T()", entity.getElement(), entity.getElement());
		}

		method.addStatement("write(bean)");
		builder.addMethod(method.build());
	}
431415
def create_method(self):
        
        # Distance computation
        metric_name = '.'.join(['separated', 'metric', self.metric])
        distance_comp = self.temp(metric_name, n_indents=1, skipping=True)

        temp_method = self.temp('separated.method.predict', n_indents=1,
                                skipping=True)
        return temp_method.format(class_name=self.class_name,
                                  method_name=self.method_name,
                                  distance_computation=distance_comp)
28341
public static Map<String, Method> getPropGetMethodList(final Class<?> cls) {
        Map<String, Method> getterMethodList = entityDeclaredPropGetMethodPool.get(cls);

        if (getterMethodList == null) {
            loadPropGetSetMethodList(cls);
            getterMethodList = entityDeclaredPropGetMethodPool.get(cls);
        }

        return getterMethodList;
    }
856759
def call(self, methodname, *args, **kwargs):
        """"""

        for plugin in self._plugins:
            method = getattr(plugin, methodname, None)
            if method is None:
                continue
            yield method(*args, **kwargs)
72502
def generate_method(service_module, service_name, method_name):
    
    assert service_module
    assert service_name
    assert method_name

    args_type = getattr(service_module, method_name + '_args')
    result_type = getattr(service_module, method_name + '_result', None)
    serializer = ThriftSerializer(result_type)
    # oneway not currently supported
    # TODO - write test for this
    if result_type is None:
        def not_supported(self, *args, **kwags):
            raise OneWayNotSupportedError(
                'TChannel+Thrift does not currently support oneway procedues'
            )
        return not_supported

    result_spec = result_type.thrift_spec
    # result_spec is a tuple of tuples in the form:
    #
    #   (fieldId, fieldType, fieldName, ...)
    #
    # Where "..." is other information we don't care about right now.
    #
    # result_spec will be empty if there is no return value or exception for
    # the method.
    #
    # Its first element, with field ID 0, contains the spec for the return
    # value. It is None if the result type is void but the method may still
    # throw exceptions.
    #
    # Elements after the first one are specs for the exceptions.

    endpoint = '%s::%s' % (service_name, method_name)

    @gen.coroutine
    def send(self, *args, **kwargs):
        params = inspect.getcallargs(
            getattr(service_module.Iface, method_name), self, *args, **kwargs
        )
        params.pop('self')  # self is already known

        # $methodName_args is the implicit struct containing the various
        # method parameters.
        call_args = args_type()
        for name, value in params.items():
            setattr(call_args, name, value)

        tracer = tracing.ClientTracer(channel=self.tchannel)
        span, headers = tracer.start_span(
            service=service_name, endpoint=method_name, headers={}
        )

        body = serializer.serialize_body(call_args)
        header = serializer.serialize_header(headers)

        # Glue for old API.
        if hasattr(self.tchannel, 'request'):
            tracing.apply_trace_flag(span, self.trace, True)
            with span:
                response = yield self.tchannel.request(
                    hostport=self.hostport, service=self.service
                ).send(
                    arg1=endpoint,
                    arg2=header,
                    arg3=body,  # body
                    headers=self.protocol_headers,
                )
                body = yield response.get_body()
        else:
            with span:
                response = yield self.tchannel.call(
                    scheme=schemes.THRIFT,
                    service=self.service,
                    arg1=endpoint,
                    arg2=header,
                    arg3=body,
                    hostport=self.hostport,
                    trace=self.trace,
                    tracing_span=span
                    # TODO: Need to handle these!
                    # headers=self.protocol_headers,
                )
                body = response.body

        call_result = serializer.deserialize_body(body)

        if not result_spec:
            # void return type and no exceptions allowed
            raise gen.Return(None)

        for exc_spec in result_spec[1:]:
            # May have failed with an exception
            exc = getattr(call_result, exc_spec[2])
            if exc is not None:
                raise exc

        if result_spec[0]:
            # Non-void return type. Return the result.
            success = getattr(call_result, result_spec[0][2])
            if success is not None:
                raise gen.Return(success)
        else:
            # No return type specified and no exceptions raised.
            raise gen.Return(None)

        # Expected a result but nothing was present in the object. Something
        # went wrong.
        from thrift import Thrift
        raise Thrift.TApplicationException(
            Thrift.TApplicationException.MISSING_RESULT,
            '%s failed: did not receive a result as expected' % method_name
        )
        # TODO: We should probably throw a custom exception instead.

    send.__name__ = method_name
    return send
873447
public JMethod getMethod(String name, JClass []param)
  {
    return getRawClass().getMethod(name, param);
  }
362739
public function get_callback_reflection() {
		if ( is_array( $this->callback ) ) {
			return new \ReflectionMethod( $this->callback[0], $this->callback[1] );
		} else {
			return new \ReflectionFunction( $this->callback );
		}
	}
1032221
public static function fromReflection(ReflectionMethod $reflectionMethod)
    {
        $method = new static($reflectionMethod->getName());
        foreach ($reflectionMethod->getParameters() as $parameter) {
            $method->addParameter(ParameterGenerator::fromReflection($parameter));
        }

        $method->setFinal($reflectionMethod->isFinal());
        $method->setAbstract($reflectionMethod->isAbstract());

        if ($reflectionMethod->isStatic() === true) {
            $method->setStatic(true);
        }

        if ($reflectionMethod->isPrivate() === true) {
            $method->setVisibility(Modifiers::VISIBILITY_PRIVATE);
        } elseif ($reflectionMethod->isProtected() === true) {
            $method->setVisibility(Modifiers::VISIBILITY_PROTECTED);
        } else {
            $method->setVisibility(Modifiers::VISIBILITY_PUBLIC);
        }

        if ($reflectionMethod->getReflectionDocComment()->isEmpty() !== true) {
            $method->setDocumentation(
                DocCommentGenerator::fromReflection($reflectionMethod->getReflectionDocComment())
            );
        }

        if ($reflectionMethod->isAbstract() !== true) {
            $body = trim($reflectionMethod->getBody());
            if ($body !== '') {
                $method->setBody($body);
            }
        }

        return $method;
    }
1187586
def _create_class_proxy(cls, theclass):
        """"""

        def make_method(name):
            def method(self, *args, **kw):
                return getattr(object.__getattribute__(self, "_obj"), name)(*args, **kw)
            return method

        namespace = {}
        for name in cls._special_names:
            if hasattr(theclass, name):
                namespace[name] = make_method(name)
        return type("%s(%s)" % (cls.__name__, theclass.__name__), (cls,), namespace)
115840
private function addMethodMap()
    {
        if (!$definitions = $this->container->getDefinitions()) {
            return '';
        }

        $code = "        \$this->methodMap = array(\n";
        ksort($definitions);
        foreach ($definitions as $id => $definition) {
            $code .= '            '.$this->export($id).' => '.$this->export($this->generateMethodName($id)).",\n";
        }

        return $code."        );\n";
    }
1209414
public function generateClass(): ClassGenerator
    {
        $interfaces = $this->getInterfaces();
        foreach ($interfaces as $interface) {
            $this->classGenerator->addUse($interface);
        }
        $this->classGenerator->setImplementedInterfaces($interfaces);

        $traits = $this->getTraits();
        foreach ($traits as $trait) {
            $this->classGenerator->addUse($trait);
            $this->classGenerator->addTrait((new \ReflectionClass($trait))->getShortName());
        }

        foreach ($this->metadata->getFieldsMetadata() as $fieldMetadata) {
            $fieldMetadata->generateProxy($this);
        }

        $this->generateBsonUnserializeMethod();

        return $this->classGenerator;
    }