Example usage for java.lang.reflect Method equals

List of usage examples for java.lang.reflect Method equals

Introduction

In this page you can find the example usage for java.lang.reflect Method equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this Method against the specified object.

Usage

From source file:java2typescript.jackson.module.visitors.TSJsonObjectFormatVisitor.java

private boolean isAccessorMethod(Method method, BeanInfo beanInfo) {
    for (PropertyDescriptor property : beanInfo.getPropertyDescriptors()) {
        if (method.equals(property.getReadMethod())) {
            return true;
        }//from   www .ja  v a 2  s.  co m
        if (method.equals(property.getWriteMethod())) {
            return true;
        }
    }
    return false;
}

From source file:com.springframework.beans.GenericTypeAwarePropertyDescriptor.java

public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName, Method readMethod,
        Method writeMethod, Class<?> propertyEditorClass) throws IntrospectionException {

    super(propertyName, null, null);

    if (beanClass == null) {
        throw new IntrospectionException("Bean class must not be null");
    }//from w  ww  .  ja  va2s . c om
    this.beanClass = beanClass;

    Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
    Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
    if (writeMethodToUse == null && readMethodToUse != null) {
        // Fallback: Original JavaBeans introspection might not have found matching setter
        // method due to lack of bridge method resolution, in case of the getter using a
        // covariant return type whereas the setter is defined for the concrete property type.
        Method candidate = ClassUtils.getMethodIfAvailable(this.beanClass,
                "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
        if (candidate != null && candidate.getParameterTypes().length == 1) {
            writeMethodToUse = candidate;
        }
    }
    this.readMethod = readMethodToUse;
    this.writeMethod = writeMethodToUse;

    if (this.writeMethod != null) {
        if (this.readMethod == null) {
            // Write method not matched against read method: potentially ambiguous through
            // several overloaded variants, in which case an arbitrary winner has been chosen
            // by the JDK's JavaBeans Introspector...
            Set<Method> ambiguousCandidates = new HashSet<Method>();
            for (Method method : beanClass.getMethods()) {
                if (method.getName().equals(writeMethodToUse.getName()) && !method.equals(writeMethodToUse)
                        && !method.isBridge()) {
                    ambiguousCandidates.add(method);
                }
            }
            if (!ambiguousCandidates.isEmpty()) {
                this.ambiguousWriteMethods = ambiguousCandidates;
            }
        }
        this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
        GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
    }

    if (this.readMethod != null) {
        this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
    } else if (this.writeMethodParameter != null) {
        this.propertyType = this.writeMethodParameter.getParameterType();
    }

    this.propertyEditorClass = propertyEditorClass;
}

From source file:springfox.documentation.spring.web.readers.operation.HandlerMethodResolver.java

private Predicate<ResolvedMethod> sameMethod(final Method methodToResolve) {
    return new Predicate<ResolvedMethod>() {
        @Override/*from w ww  .j  a  v  a2 s  .co m*/
        public boolean apply(ResolvedMethod input) {
            return methodToResolve.equals(input.getRawMember());
        }
    };
}

From source file:com.bstek.dorado.util.proxy.MethodInterceptorDispatcher.java

public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    // ??equals()?dorado??AOP??
    if (method.equals(EQUALS_METHOD)) {
        Object proxyTarget = ProxyBeanUtils.getProxyTarget(args[0]);
        if (proxyTarget == object)
            return Boolean.TRUE;
        args = new Object[] { proxyTarget };
    }// w  w w  .  j  a v a 2 s.  c  om

    if (subMethodInterceptors != null && filterMethod(method)) {
        MethodInterceptorChain methodInterceptorChain = new MethodInterceptorChain(subMethodInterceptors,
                createCglibFinalMethodInterceptor(methodProxy),
                getMethodInterceptorFilter(object, method, args));

        MethodInvocation mockMethodInvocation = createMethodInvocation(object, method, args,
                methodInterceptorChain);
        MethodInterceptor methodInterceptor = methodInterceptorChain.next(mockMethodInvocation);
        return methodInterceptor.invoke(mockMethodInvocation);
    } else {
        return methodProxy.invokeSuper(object, args);
    }
}

From source file:com.link_intersystems.lang.reflect.Method2.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    } else if (obj == null) {
        return false;
    } else if (getClass() != obj.getClass()) {
        return false;
    } else {//from   w ww  .  ja  v  a 2 s . c  om
        Method2 otherMethod2 = (Method2) obj;
        Method member = getMember();
        return member.equals(otherMethod2.getMember());
    }
}

From source file:com.dbs.sdwt.jpa.JpaUtil.java

public String methodToProperty(Method m) {
    PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(m.getDeclaringClass());
    for (PropertyDescriptor pd : pds) {
        if (m.equals(pd.getReadMethod()) || m.equals(pd.getWriteMethod())) {
            return pd.getName();
        }//w  ww . ja  va 2s . c  o m
    }
    return null;
}

From source file:de.taimos.dvalin.interconnect.core.spring.InterconnectBeanPostProcessor.java

private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
    Class<?> targetClass = clazz;

    do {// w  w w.  j  a v  a 2 s  .c  om
        LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
        for (Field field : targetClass.getDeclaredFields()) {
            if (field.isAnnotationPresent(Interconnect.class)) {
                if (Modifier.isStatic(field.getModifiers())) {
                    throw new IllegalStateException(
                            "@Interconnect annotation is not supported on static fields");
                }
                currElements.add(new InterconnectElement(field, null));
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
            if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
                continue;
            }
            if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                if (bridgedMethod.isAnnotationPresent(Interconnect.class)) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException(
                                "@Interconnect annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length != 1) {
                        throw new IllegalStateException(
                                "@Interconnect annotation requires a single-arg method: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
                    currElements.add(new InterconnectElement(method, pd));
                }
            }
        }
        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    } while ((targetClass != null) && (targetClass != Object.class));

    return new InjectionMetadata(clazz, elements);
}

From source file:de.taimos.dvalin.test.jaxrs.TestProxyBeanPostProcessor.java

private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
    Class<?> targetClass = clazz;

    do {/*from   w w  w.  j av  a 2s. c  om*/
        LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
        for (Field field : targetClass.getDeclaredFields()) {
            if (field.isAnnotationPresent(TestProxy.class)) {
                if (Modifier.isStatic(field.getModifiers())) {
                    throw new IllegalStateException("@TestProxy annotation is not supported on static fields");
                }
                currElements.add(new TestProxyElement(field, null));
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
            if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
                continue;
            }
            if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                if (bridgedMethod.isAnnotationPresent(TestProxy.class)) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException(
                                "@TestProxy annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length != 1) {
                        throw new IllegalStateException(
                                "@TestProxy annotation requires a single-arg method: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
                    currElements.add(new TestProxyElement(method, pd));
                }
            }
        }
        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    } while ((targetClass != null) && (targetClass != Object.class));

    return new InjectionMetadata(clazz, elements);
}

From source file:de.taimos.dvalin.jaxrs.remote.RemoteServiceBeanPostProcessor.java

private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
    Class<?> targetClass = clazz;

    do {/*ww w  . jav  a2 s. c o  m*/
        LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
        for (Field field : targetClass.getDeclaredFields()) {
            if (field.isAnnotationPresent(RemoteService.class)) {
                if (Modifier.isStatic(field.getModifiers())) {
                    throw new IllegalStateException(
                            "@RemoteService annotation is not supported on static fields");
                }
                currElements.add(new RemoteServiceElement(field, field, null));
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
            if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
                continue;
            }
            if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                if (bridgedMethod.isAnnotationPresent(RemoteService.class)) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException(
                                "@RemoteService annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length != 1) {
                        throw new IllegalStateException(
                                "@RemoteService annotation requires a single-arg method: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
                    currElements.add(new RemoteServiceElement(method, bridgedMethod, pd));
                }
            }
        }
        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    } while ((targetClass != null) && (targetClass != Object.class));

    return new InjectionMetadata(clazz, elements);
}

From source file:de.taimos.dvalin.cloud.aws.AWSClientBeanPostProcessor.java

private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<>();
    Class<?> targetClass = clazz;

    do {/*w  w  w  . j a v a  2  s  . c  o  m*/
        LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
        for (Field field : targetClass.getDeclaredFields()) {
            if (field.isAnnotationPresent(AWSClient.class)) {
                if (Modifier.isStatic(field.getModifiers())) {
                    throw new IllegalStateException("@AWSClient annotation is not supported on static fields");
                }
                currElements.add(new AWSClientElement(field, null, field.getAnnotation(AWSClient.class)));
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
            if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
                continue;
            }
            if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                if (bridgedMethod.isAnnotationPresent(AWSClient.class)) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException(
                                "@AWSClient annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length != 1) {
                        throw new IllegalStateException(
                                "@AWSClient annotation requires a single-arg method: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
                    currElements.add(new AWSClientElement(method, pd, method.getAnnotation(AWSClient.class)));
                }
            }
        }
        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    } while ((targetClass != null) && (targetClass != Object.class));

    return new InjectionMetadata(clazz, elements);
}