当前位置: 首页>>代码示例>>Java>>正文


Java Method.getParameterCount方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.getParameterCount方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getParameterCount方法的具体用法?Java Method.getParameterCount怎么用?Java Method.getParameterCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getParameterCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recordAPIMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private APIMethod recordAPIMethod(Method method) {
    if (method == null || !method.isAnnotationPresent(API.class)) {
        return null;
    }
    APIMethod m = new APIMethod(method.getName());
    if (method.getParameterCount() > 0) {
        Parameter[] parameters = method.getParameters();
        for (Parameter parameter : parameters) {
            String defaultValue = determineParameterDefaultValue(parameter);
            determineContentType(parameter);
            APIMethodArgument arg = new APIMethodArgument(parameter.getName(), parameter.getType(),
                    determineContentType(parameter), defaultValue);
            m.addArgument(arg);
        }
    }
    APIMethodArgument returnArg = new APIMethodArgument(method.getReturnType(), null);
    m.setReturnArgument(returnArg);
    return m;
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:20,代码来源:APIMappingGenerator.java

示例2: getArgMismatchString

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Gets the error message we should send when the input string is missing arguments
 *
 * @param method method with missing arguments
 * @return error message
 */
@Nonnull
public static String getArgMismatchString(Method method) {
    final String methodName = method.getName();
    final Class returnType = method.getReturnType();
    final String returnTypeName = returnType.getSimpleName();
    String returnInfo;

    if (returnType.equals(Void.TYPE)) {
        returnInfo = "returns void.";
    } else if (startsWithVowel.test(returnTypeName)) {
        returnInfo = "returns an " + returnTypeName;
    } else {
        returnInfo = "returns a " + returnTypeName;
    }

    return "Method " + methodName + " requires " + method.getParameterCount() + " args and " + returnInfo + "\n"
            + ReflectionUtil.getFormattedMethodSignature(method);
}
 
开发者ID:zachbr,项目名称:Debuggery,代码行数:25,代码来源:ReflectionUtil.java

示例3: isSubstitute

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Determines if a given method is the substitute method of this plugin.
 */
private boolean isSubstitute(Method m) {
    if (Modifier.isStatic(m.getModifiers()) && m.getName().equals(name)) {
        if (parameters.length == m.getParameterCount()) {
            Class<?>[] mparams = m.getParameterTypes();
            int start = 0;
            if (!originalIsStatic) {
                start = 1;
                if (!mparams[0].isAssignableFrom(resolveType(parameters[0], false))) {
                    return false;
                }
            }
            for (int i = start; i < mparams.length; i++) {
                if (mparams[i] != resolveType(parameters[i], false)) {
                    return false;
                }
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:MethodSubstitutionPlugin.java

示例4: findAffinityArg

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static OptionalInt findAffinityArg(Method meth) {
    OptionalInt affinityArg = OptionalInt.empty();

    if (meth.getParameterCount() > 0) {
        for (int i = 0; i < meth.getParameterCount() && !affinityArg.isPresent(); i++) {
            Annotation[] annotations = meth.getParameterAnnotations()[i];

            for (int j = 0; j < annotations.length; j++) {
                if (RpcAffinityKey.class.isAssignableFrom(annotations[j].annotationType())) {
                    affinityArg = OptionalInt.of(i);

                    break;
                }
            }
        }
    }

    return affinityArg;
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:20,代码来源:RpcMethodInfo.java

示例5: IntlTest

import java.lang.reflect.Method; //导入方法依赖的package包/类
protected IntlTest() {
    // Populate testMethods with all the test methods.
    Method[] methods = getClass().getDeclaredMethods();
    for (Method method : methods) {
        if (Modifier.isPublic(method.getModifiers())
            && method.getReturnType() == void.class
            && method.getParameterCount() == 0) {
            String name = method.getName();
            if (name.length() > 4) {
                if (name.startsWith("Test") || name.startsWith("test")) {
                    testMethods.put(name, method);
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:IntlTest.java

示例6: checkViewOnShowOrLeaveMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Check given method has a valid signature for {@link OnShow} or {@link OnLeave} view method
 * @param viewClass View class
 * @param method Method to check
 * @param message Error message annotation description
 * @throws ViewConfigurationException Method is not valid
 */
private static void checkViewOnShowOrLeaveMethod(Class<?> viewClass, Method method, String message)
		throws ViewConfigurationException {
	if (method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE) {
		throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
				+ ": method must be a void return method");
	}
	int params = method.getParameterCount();
	if (params > 1) {
		throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
				+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
	}
	if (params == 1) {
		Parameter param = method.getParameters()[0];
		if (param.isVarArgs() || !(ViewChangeEvent.class.isAssignableFrom(param.getType())
				|| ViewNavigatorChangeEvent.class.isAssignableFrom(param.getType()))) {
			throw new ViewConfigurationException(
					"Invalid " + message + " method in view class " + viewClass.getName()
							+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
		}
	}
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:29,代码来源:ViewNavigationUtils.java

示例7: test

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public boolean test(final Method candidate) {
  final boolean result = original.getName().equals(candidate.getName()) // methods must have equal names
      && original.getParameterCount() == candidate.getParameterCount() // and same number of parameters
      && !original.getReturnType().equals(candidate.getReturnType()); // and different return types
  if (!result) {
    return false;
  }
  // check every parameter type
  for (int i = 0; i < original.getParameterCount(); i++) {
    if (!original.getParameterTypes()[i].equals(candidate.getParameterTypes()[i])) {
      // if parameter type are not matching, the implementation candidate is refused.
      return false;
    }
  }
  return true;
}
 
开发者ID:camunda,项目名称:camunda-bpm-swagger,代码行数:18,代码来源:ReturnTypeInfo.java

示例8: reflect

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Object reflect(Object instance, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
    final int paramCount = method.getParameterCount();

    if (args.length != paramCount) {
        return ReflectionUtil.getArgMismatchString(method);
    }

    if (!method.isAccessible()) {
        method.setAccessible(true);
    }

    Object result;
    if (paramCount == 0) {
        result = method.invoke(instance);
    } else {
        result = method.invoke(instance, args);
    }

    return result;
}
 
开发者ID:zachbr,项目名称:Debuggery,代码行数:21,代码来源:ReflectionChain.java

示例9: fireViewOnShow

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Fire {@link OnShow} view methods
 * @param view View instance (not null)
 * @param configuration View configuration (not null)
 * @param event View change event
 * @param refresh <code>true</code> if is a page refresh
 * @throws ViewConfigurationException Error invoking view methods
 */
public static <E extends ViewChangeEvent & ViewNavigatorChangeEvent> void fireViewOnShow(View view,
		ViewConfiguration configuration, E event, boolean refresh) throws ViewConfigurationException {
	if (view == null) {
		throw new ViewConfigurationException("Null view instance");
	}
	if (configuration == null) {
		throw new ViewConfigurationException("Missing view configuration");
	}

	for (Method method : configuration.getOnShowMethods()) {
		if (!refresh || configuration.isFireOnRefresh(method)) {
			try {
				if (method.getParameterCount() == 0) {
					method.invoke(view, new Object[0]);
				} else {
					method.invoke(view, new Object[] { event });
				}
			} catch (Exception e) {
				throw new ViewConfigurationException("Failed to fire OnShow method " + method.getName()
						+ " on view class " + view.getClass().getName(), e);
			}
		}
	}
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:33,代码来源:ViewNavigationUtils.java

示例10: allMethodsThrowISE

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * All the methods of Disconnect should throw ISE.
 * @throws Exception If something goes wrong.
 */
@Test
public void allMethodsThrowISE() throws Exception {
    for(final Method method : Disconnected.class.getDeclaredMethods()) {
        try {
            if(!method.isAccessible()) {
                continue;
            }
            Object[] params = new Object[method.getParameterCount()];
            for(int i=0; i < method.getParameters().length; i++) {
                if(method.getParameters()[i].getType().equals(int.class)) {
                    params[i] = 0;
                } else if(method.getParameters()[i].getType().equals(boolean.class)) {
                    params[i] = false;
                } else {
                    params[i] = null;   
                }
            }
            method.invoke(new Disconnected(), params);
            Assert.fail("ISE should have been thrown by now!");
        } catch (final InvocationTargetException ex) {
            MatcherAssert.assertThat(
                ex.getCause().getMessage(),
                Matchers.equalTo(
                    "Not connected. Don't forget to "
                    + "get a connected instance by calling #connect()"
                )
            );
        }
    }
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:35,代码来源:DisconnectedTestCase.java

示例11: checkTgPrePostActionMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void checkTgPrePostActionMethod(Method preOrPostActionMethod) {

        if (preOrPostActionMethod.getParameterCount() != 0)
            throw new IllegalStateException(String.format("Pre and Post method parameters must be empty. Method: %s.%s",
                    preOrPostActionMethod.getDeclaringClass().getName(),
                    preOrPostActionMethod.getName())
            );

    }
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:10,代码来源:TgActionRegisterer.java

示例12: methodNameAndNumArgsMatch

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static boolean methodNameAndNumArgsMatch(Method interceptedMethod, HookMetadata.MethodSignature instrumentedMethod) {
    if (!interceptedMethod.getName().equals(instrumentedMethod.getMethodName())) {
        return false;
    }
    if (interceptedMethod.getParameterCount() != instrumentedMethod.getParameterTypes().size()) {
        return false;
    }
    return true;
}
 
开发者ID:fstab,项目名称:promagent,代码行数:10,代码来源:Delegator.java

示例13: getGuardedInvocation

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final Method m = getFunctionalInterfaceMethod(self.getClass());
        if (m != null) {
            final MethodType callType = desc.getMethodType();
            // 'callee' and 'thiz' passed from script + actual arguments
            if (callType.parameterCount() != m.getParameterCount() + 2) {
                throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
            }
            return new GuardedInvocation(
                    // drop 'thiz' passed from the script.
                    MH.dropArguments(desc.getLookup().unreflect(m), 1, callType.parameterType(1)),
                    Guards.getInstanceOfGuard(m.getDeclaringClass())).asTypeSafeReturn(
                            new NashornBeansLinkerServices(linkerServices), callType);
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:NashornBeansLinker.java

示例14: getParameterSuppliers

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static <M> List<Function<M, Object>> getParameterSuppliers(Method method,
                                                                   List<ParameterResolver<M>> resolvers) {
    if (method.getParameterCount() == 0) {
        throw new IllegalStateException("Annotated method should contain at least one parameter");
    }
    return Arrays.stream(method.getParameters())
            .map(p -> resolvers.stream().map(r -> r.resolve(p)).filter(Objects::nonNull).findFirst()
                    .orElseThrow(() -> new IllegalStateException("Could not resolve parameter " + p)))
            .collect(toList());
}
 
开发者ID:flux-capacitor-io,项目名称:flux-capacitor-client,代码行数:11,代码来源:HandlerInspector.java

示例15: register

import java.lang.reflect.Method; //导入方法依赖的package包/类
public void register(Class<?> c) {
	for (Method m : c.getMethods()) {
		if (Modifier.isStatic(m.getModifiers()) && m.getParameterCount() == 1
				&& m.getParameterTypes()[0] == CommandContext.class) {
			if (m.isAnnotationPresent(Command.class) && m.getReturnType() == boolean.class) {
				registerCommand(m, null);
			} else if (m.isAnnotationPresent(Completer.class) && m.getReturnType() == List.class) {
				registerCompleter(m, null);
			}
		}
	}
}
 
开发者ID:mcardy,项目名称:MystiCraft,代码行数:13,代码来源:CommandManager.java


注:本文中的java.lang.reflect.Method.getParameterCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。