All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.zalando.sprocwrapper.globalvaluetransformer.ReflectionUtils Maven / Gradle / Ivy

Go to download

Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces including automatic object serialization and deserialization (using typemapper and convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types such as enums and hstore.

There is a newer version: 2.0.0
Show newest version
package de.zalando.sprocwrapper.globalvaluetransformer;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import java.util.List;

import org.springframework.util.Assert;

import com.google.common.collect.Lists;

public class ReflectionUtils {

    /**
     * Attempt to find exactly one {@link Method} on the supplied class with the supplied name Searches all superclasses
     * up to Object.
     *
     * 

Returns null if no {@link Method} can be found. * * @param clazz the class to introspect * @param name the name of the method * * @return the Method object, or null if none found */ public static Method findMethod(final Class clazz, final String name) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(name, "Method name must not be null"); Class searchType = clazz; final List foundMethods = Lists.newArrayList(); while (searchType != null && !searchType.isInterface() && !Modifier.isAbstract(searchType.getModifiers())) { final Method[] methods = searchType.getDeclaredMethods(); for (final Method method : methods) { if (name.equals(method.getName()) && !method.isSynthetic() && !method.isBridge()) { foundMethods.add(method); } } searchType = searchType.getSuperclass(); } if (foundMethods.isEmpty()) { return null; } if (foundMethods.size() > 1) { throw new IllegalArgumentException("The class " + clazz + " contains more than one methods with name " + name); } return foundMethods.get(0); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy