當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。