Java Code Examples for java.lang.reflect.Method.equals()

The following are Jave code examples for showing how to use equals() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: MBeanInfo.java   View Source Code Vote up 6 votes
public Boolean run() {
    Method[] methods = immutableClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String methodName = method.getName();
        if (methodName.startsWith("get") &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType().isArray()) {
            try {
                Method submethod =
                    subclass.getMethod(methodName);
                if (!submethod.equals(method))
                    return false;
            } catch (NoSuchMethodException e) {
                return false;
            }
        }
    }
    return true;
}
 
Example 2
Project: FirefoxData-android   File: ResponseProxyHandler.java   View Source Code Vote up 6 votes
public Object invoke(
        final Object proxy, final Method method, final Object[] args) throws Throwable {
    if (method.equals(CLOSE_METHOD)) {
        close();
        return null;
    } else {
        try {
            return method.invoke(this.original, args);
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause != null) {
                throw cause;
            } else {
                throw ex;
            }
        }
    }
}
 
Example 3
Project: jdk8u-jdk   File: MBeanInfo.java   View Source Code Vote up 6 votes
public Boolean run() {
    Method[] methods = immutableClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String methodName = method.getName();
        if (methodName.startsWith("get") &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType().isArray()) {
            try {
                Method submethod =
                    subclass.getMethod(methodName);
                if (!submethod.equals(method))
                    return false;
            } catch (NoSuchMethodException e) {
                return false;
            }
        }
    }
    return true;
}
 
Example 4
Project: OpenJSharp   File: MBeanInfo.java   View Source Code Vote up 6 votes
public Boolean run() {
    Method[] methods = immutableClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String methodName = method.getName();
        if (methodName.startsWith("get") &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType().isArray()) {
            try {
                Method submethod =
                    subclass.getMethod(methodName);
                if (!submethod.equals(method))
                    return false;
            } catch (NoSuchMethodException e) {
                return false;
            }
        }
    }
    return true;
}
 
Example 5
Project: AgentWorkbench   File: DynFormBase.java   View Source Code Vote up 5 votes
/**
 * This Method checks if an instance of an object has an asked method.
 *
 * @param ontologyObject the ontology object
 * @param methode2check the methode2check
 * @return true, if the method is available
 */
private boolean hasObjectMethod(Object ontologyObject, Method methode2check) {
	
	if (ontologyObject==null) return false;
	
	Method[] meths = ontologyObject.getClass().getMethods();
	for (int i = 0; i < meths.length; i++) {
		Method meth = meths[i];
		if (meth.equals(methode2check)) {
			return true;
		}
	}
	return false;
}
 
Example 6
Project: solo-spring   File: Reflections.java   View Source Code Vote up 5 votes
public static boolean matchInheritance(final Method subclassMethod, final Method superclassMethod) {
	if (Modifier.isStatic(superclassMethod.getModifiers()) || subclassMethod.equals(superclassMethod)) {
		return false;
	}

	if (matchSignature(subclassMethod, superclassMethod)) {
		final Package subclassPackage = subclassMethod.getDeclaringClass().getPackage();
		final Package superclassPackage = superclassMethod.getDeclaringClass().getPackage();
		final int superMethodModifiers = superclassMethod.getModifiers();

		return isAccessable(subclassPackage, superclassPackage, superMethodModifiers);
	} else {
		return false;
	}
}
 
Example 7
Project: openjdk-jdk10   File: Test7084904.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    System.setSecurityManager(new SecurityManager());
    Derived bean = new Derived();
    Class<?> type = bean.getClass();
    Method method1 = test("reflection", bean, type.getMethod("isAllowed"));
    Method method2 = test("bean introspection", bean, BeanUtils.getPropertyDescriptor(type, "allowed").getReadMethod());
    if (!method1.equals(method2)) {
        throw new Error("first method is not equal to the second one");
    }
}
 
Example 8
Project: openjdk-jdk10   File: Test4634390.java   View Source Code Vote up 5 votes
private static boolean compare(Method m1, Method m2) {
    if ((m1 == null) && (m2 == null)) {
        return true;
    }
    if ((m1 == null) || (m2 == null)) {
        return false;
    }
    return m1.equals(m2);
}
 
Example 9
Project: lams   File: GenericTypeAwarePropertyDescriptor.java   View Source Code Vote up 5 votes
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);
	this.beanClass = beanClass;
	this.propertyEditorClass = propertyEditorClass;

	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 && 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;
		}
	}
}
 
Example 10
Project: lams   File: ExtendedBeanInfo.java   View Source Code Vote up 5 votes
public static boolean compareMethods(Method a, Method b) {
	if ((a == null) != (b == null)) {
		return false;
	}
	if (a != null) {
		if (!a.equals(b)) {
			return false;
		}
	}
	return true;
}
 
Example 11
Project: lams   File: BeanUtils.java   View Source Code Vote up 5 votes
/**
 * Find a JavaBeans {@code PropertyDescriptor} for the given method,
 * with the method either being the read method or the write method for
 * that bean property.
 * @param method the method to find a corresponding PropertyDescriptor for
 * @return the corresponding PropertyDescriptor, or {@code null} if none
 * @throws BeansException if PropertyDescriptor lookup fails
 */
public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException {
	Assert.notNull(method, "Method must not be null");
	PropertyDescriptor[] pds = getPropertyDescriptors(method.getDeclaringClass());
	for (PropertyDescriptor pd : pds) {
		if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) {
			return pd;
		}
	}
	return null;
}
 
Example 12
Project: jdk8u-jdk   File: Test4634390.java   View Source Code Vote up 5 votes
private static boolean compare(Method m1, Method m2) {
    if ((m1 == null) && (m2 == null)) {
        return true;
    }
    if ((m1 == null) || (m2 == null)) {
        return false;
    }
    return m1.equals(m2);
}
 
Example 13
Project: martini-core   File: StepsAnnotationProcessorTest.java   View Source Code Vote up 5 votes
@Test
public void testMultipleGivenRegex() throws NoSuchMethodException {
	MultipleGivenBean source = new MultipleGivenBean();
	ClassPathXmlApplicationContext context = getContext(source);
	process(context, source);

	MultipleGivenBean steps = context.getBean(MultipleGivenBean.class);
	Class<?> wrapped = AopUtils.getTargetClass(steps);
	Method method = wrapped.getMethod("doSomething");

	Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
	Collection<StepImplementation> givens = givenBeanIndex.values();

	Set<String> matches = Sets.newHashSetWithExpectedSize(2);
	for (StepImplementation given : givens) {
		Method givenMethod = given.getMethod();
		if (givenMethod.equals(method)) {
			Pattern pattern = given.getPattern();
			String regex = pattern.pattern();
			matches.add(regex);
		}
	}

	int count = matches.size();
	assertEquals(count, 2, "wrong number of GivenStep objects registered for MultipleGivenBean.getMartinis()");

	Set<String> expected = Sets.newHashSet(
		"this is regular expression one", "this is regular expression two");
	assertEquals(matches, expected, "Steps contain wrong regex Pattern objects");
}
 
Example 14
Project: whackpad   File: ShellLine.java   View Source Code Vote up 5 votes
@SuppressWarnings({"unchecked"})
public Object invoke(Object proxy, Method method, Object[] args) {
    if (method.equals(this.completeMethod)) {
        int result = complete((String)args[0], ((Integer) args[1]).intValue(),
                (List<String>) args[2]);
        return Integer.valueOf(result);
    }
    throw new NoSuchMethodError(method.toString());
}
 
Example 15
Project: openjdk-jdk10   File: SnippetTemplate.java   View Source Code Vote up 5 votes
public static Method findMethod(Class<? extends Snippets> declaringClass, String methodName, Method except) {
    for (Method m : declaringClass.getDeclaredMethods()) {
        if (m.getName().equals(methodName) && !m.equals(except)) {
            return m;
        }
    }
    return null;
}
 
Example 16
Project: OpenJSharp   File: Class.java   View Source Code Vote up 5 votes
void addIfNotPresent(Method newMethod) {
    for (int i = 0; i < length; i++) {
        Method m = methods[i];
        if (m == newMethod || (m != null && m.equals(newMethod))) {
            return;
        }
    }
    add(newMethod);
}
 
Example 17
Project: OpenJSharp   File: Class.java   View Source Code Vote up 5 votes
void addIfNotPresent(Method newMethod) {
    for (int i = 0; i < length; i++) {
        Method m = methods[i];
        if (m == newMethod || (m != null && m.equals(newMethod))) {
            return;
        }
    }
    add(newMethod);
}
 
Example 18
Project: openjdk-jdk10   File: TestProvider.java   View Source Code Vote up 5 votes
private static void verifyOneInvocation(Method method, Object[] args,
                                        List invocationQueue)
{
    TestProvider.Invocation inv =
        (TestProvider.Invocation) invocationQueue.remove(0);

    if (!method.equals(inv.method)) {
        throw new RuntimeException(
            "unexpected provider method invoked: expected " + method +
            ", detected " + inv.method);
    }

    List expectedArgs = Arrays.asList(args);
    List detectedArgs = Arrays.asList(inv.args);
    if (!expectedArgs.equals(detectedArgs)) {
        throw new RuntimeException("TEST FAILED: " +
            "unexpected provider method invocation arguments: " +
            "expected " + expectedArgs + ", detected " + detectedArgs);
    }

    if (!invocationQueue.isEmpty()) {
        inv = (TestProvider.Invocation)
            invocationQueue.remove(0);
        throw new RuntimeException("TEST FAILED: " +
            "unexpected provider invocation: " + inv.method + " " +
            Arrays.asList(inv.args));
    }
}
 
Example 19
Project: uroborosql   File: Helper.java   View Source Code Vote up 5 votes
public static ResultSet newResultSet(final Object... defs) throws NoSuchMethodException, SecurityException {
	if (defs.length % 2 != 0) {
		throw new IllegalArgumentException();
	}

	Method wasNull = ResultSet.class.getMethod("wasNull");

	Map<Method, Object> values = new HashMap<>();
	for (int i = 0; i < defs.length; i += 2) {
		Method target = defs[i].equals("wasNull") ? wasNull : ResultSet.class.getMethod(defs[i].toString(), int.class);
		values.put(target, defs[i + 1]);
	}

	AtomicBoolean flg = new AtomicBoolean(false);

	InvocationHandler handler = new InvocationHandler() {

		@Override
		public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
			if (values.containsKey(method)) {
				Object o = values.get(method);
				flg.set(o == null);
				return o;
			}
			if (wasNull.equals(method)) {
				return flg.get();
			}

			return null;
		}
	};
	return (ResultSet) Proxy.newProxyInstance(Helper.class.getClassLoader(), new Class[] { ResultSet.class }, handler);
}
 
Example 20
Project: martini-core   File: StepsAnnotationProcessorTest.java   View Source Code Vote up 5 votes
@Test
public void testPostProcessAfterInitialization() throws IOException, NoSuchMethodException {
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
	TestSteps steps = context.getBean(TestSteps.class);

	Class<?> wrapped = AopUtils.getTargetClass(steps);
	Method method = wrapped.getMethod("anotherStep", String.class);

	Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
	Collection<StepImplementation> givens = givenBeanIndex.values();

	List<StepImplementation> matches = Lists.newArrayList();
	for (StepImplementation given : givens) {
		Method givenMethod = given.getMethod();
		if (givenMethod.equals(method)) {
			matches.add(given);
		}
	}

	int count = matches.size();
	assertEquals(count, 1, "wrong number of GivenStep objects registered for TestSteps.anotherStep()");

	StepImplementation match = matches.get(0);
	Pattern pattern = match.getPattern();
	Matcher matcher = pattern.matcher("another \"(.+)\" here");
	assertTrue(matcher.find(), "expected Pattern to match Gherkin regular expression");
	assertEquals(matcher.groupCount(), 1, "wrong number of parameters captured for TestSteps.anotherStep()");
}