List of usage examples for java.lang.reflect Method getParameterCount
public int getParameterCount()
From source file:org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.java
private boolean isGetStartupFailure(Method method) { return ("getStartupFailure".equals(method.getName()) && method.getParameterCount() == 0); }
From source file:com.flipkart.polyguice.dropwiz.DropConfigProvider.java
private String getNameFromMethod(Method method) { if (method.getParameterCount() > 0) { return null; }/*from w w w . java 2 s. co m*/ if (method.getReturnType().equals(Void.TYPE)) { return null; } String mthdName = method.getName(); if (mthdName.startsWith("get")) { if (mthdName.length() <= 3) { return null; } if (method.getReturnType().equals(Boolean.class) || method.getReturnType().equals(Boolean.TYPE)) { return null; } StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "get")); buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0))); return buffer.toString(); } else if (!mthdName.startsWith("is")) { if (mthdName.length() <= 2) { return null; } if (!method.getReturnType().equals(Boolean.class) && !method.getReturnType().equals(Boolean.TYPE)) { return null; } StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "is")); buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0))); return buffer.toString(); } return null; }
From source file:org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.java
private boolean isGetSourceContext(Method method) { return "getSourceApplicationContext".equals(method.getName()) && ((method.getParameterCount() == 0) || Arrays.equals(new Class<?>[] { Class.class }, method.getParameterTypes())); }
From source file:org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.java
/** * Create a new ThrowsAdviceInterceptor for the given ThrowsAdvice. * @param throwsAdvice the advice object that defines the exception * handler methods (usually a {@link org.springframework.aop.ThrowsAdvice} * implementation)/*from w w w . ja v a2 s . c o m*/ */ public ThrowsAdviceInterceptor(Object throwsAdvice) { Assert.notNull(throwsAdvice, "Advice must not be null"); this.throwsAdvice = throwsAdvice; Method[] methods = throwsAdvice.getClass().getMethods(); for (Method method : methods) { if (method.getName().equals(AFTER_THROWING) && (method.getParameterCount() == 1 || method.getParameterCount() == 4) && Throwable.class .isAssignableFrom(method.getParameterTypes()[method.getParameterCount() - 1])) { // Have an exception handler this.exceptionHandlerMap.put(method.getParameterTypes()[method.getParameterCount() - 1], method); if (logger.isDebugEnabled()) { logger.debug("Found exception handler method: " + method); } } } if (this.exceptionHandlerMap.isEmpty()) { throw new IllegalArgumentException( "At least one handler method must be found in class [" + throwsAdvice.getClass() + "]"); } }
From source file:org.kie.server.controller.client.websocket.WebSocketKieServerControllerClientTest.java
private void verifyServiceMethods(final Class service) throws Exception { final String name = service.getName(); final Method[] methods = service.getMethods(); for (int i = 0; i < methods.length; i++) { final Method m = methods[i]; MethodUtils.invokeMethod(controllerClient, m.getName(), new Object[m.getParameterCount()]); ArgumentCaptor<String> contentCaptor = ArgumentCaptor.forClass(String.class); verify(client).sendTextWithInternalHandler(contentCaptor.capture(), any(InternalMessageHandler.class)); final DescriptorCommand command = WebSocketUtils.unmarshal(contentCaptor.getValue(), DescriptorCommand.class); assertNotNull(command);/*from www .ja v a 2 s . c o m*/ assertEquals(name, command.getService()); assertEquals(m.getName(), command.getMethod()); reset(client); } }
From source file:telegram.polling.BotApiProxy.java
@Override public Object invoke(Object o, Method method, Object[] os) throws Throwable { ArrayList<NameValuePair> nvps = new ArrayList<>(); for (int i = 0; i < method.getParameterCount(); i++) { Parameter parameter = method.getParameters()[i]; if (os[i] != null) { String name;//w w w.j a v a 2 s . co m if (parameter.isAnnotationPresent(Param.class)) { name = parameter.getDeclaredAnnotation(Param.class).name(); } else { name = parameter.getName(); } nvps.add(new BasicNameValuePair(name, os[i].toString())); } } return callApiMethod(method.getName(), nvps, method.getReturnType()); }
From source file:com.github.tddts.jet.config.spring.postprocessor.MessageAnnotationBeanPostProcessor.java
private boolean checkMethod(Method method, Class<?> type) { if (!method.isAnnotationPresent(Message.class)) { return false; }/*w w w. j a v a 2s .co m*/ if (method.getParameterCount() == 1 && method.getParameterTypes()[0].equals(String.class)) { return true; } logger.warn("Method [" + type + "." + method.getName() + "] is not populated with message. Method should have a single String parameter."); return false; }
From source file:de.fraunhofer.iosb.ilt.sta.model.core.AbstractEntity.java
@Override public void setProperty(Property property, Object value) { String methodName = property.getSetterName(); try {//from w w w . j av a 2s .com for (Method m : this.getClass().getMethods()) { if (m.getParameterCount() == 1 && methodName.equals(m.getName())) { try { m.invoke(this, value); return; } catch (SecurityException | IllegalAccessException | InvocationTargetException | IllegalArgumentException e) { LOGGER.trace("Wrong setter method."); } } } } catch (SecurityException ex) { LOGGER.error("Failed to find or execute method " + methodName, ex); } }
From source file:psyriccio.voteflow.api.LawAPI.java
protected Map<String, String> getParams(Object obj) { Map<String, String> params = new HashMap<>(); final Function<Date, String> formatDate = (Date t) -> { return DateFormatUtils.format(t, "yyyy-MM-dd"); };// w w w. j a v a 2 s .c o m if (obj == null) { return params; } for (Method method : obj.getClass().getMethods()) { if (method.getParameterCount() == 0) { if (method.getName().startsWith("get") || method.getName().startsWith("is")) { String name = method.getName().replaceAll("get", "").replaceAll("is", "").toLowerCase(); if (name.equals("class")) { continue; } try { Object objVal = method.invoke(obj); if (objVal != null) { String value = ""; if (objVal instanceof Boolean) { value = ((Boolean) objVal) ? "1" : "0"; } else if (objVal instanceof Date) { value = formatDate.apply((Date) objVal); } else { value = objVal.toString(); } params.put(name, value); } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Main.log.error("Exception: {}", ex); } } } } return params; }
From source file:de.fraunhofer.iosb.ilt.sta.model.core.AbstractEntity.java
@Override public void unsetProperty(Property property) { String methodName = property.getSetterName(); try {//from ww w .j av a 2 s . c om Method[] methods = this.getClass().getMethods(); for (Method method : methods) { if (method.getName().equalsIgnoreCase(methodName) && method.getParameterCount() == 1) { method.invoke(this, new Object[] { null }); return; } } LOGGER.error("Failed to find method {}.", methodName); } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { LOGGER.error("Failed to find or execute method " + methodName, ex); } }