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

The following are Jave code examples for showing how to use isBridge() 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: aws-sdk-java-v2   File: StandardBeanProperties.java   View Source Code Vote up 6 votes
private boolean canMap(Method method, boolean inherited) {
    if (method.getName().matches("^(get|is).+") == false) {
        return false;
    } else if (method.getParameterTypes().length != 0) {
        return false;
    } else if (method.isBridge() || method.isSynthetic()) {
        return false;
    } else if (method.getDeclaringClass() == Object.class) {
        return false;
    } else if (!inherited && method.getDeclaringClass() != this.clazz &&
               StandardAnnotationMaps.of(method.getDeclaringClass()).attributeType() == null) {
        return false;
    } else {
        return true;
    }
}
 
Example 2
Project: drift   File: ReflectionHelper.java   View Source Code Vote up 6 votes
/**
 * Find methods that are tagged with a given annotation somewhere in the hierarchy
 */
public static Collection<Method> findAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation)
{
    List<Method> result = new ArrayList<>();

    // gather all publicly available methods
    // this returns everything, even if it's declared in a parent
    for (Method method : type.getMethods()) {
        // skip methods that are used internally by the vm for implementing covariance, etc
        if (method.isSynthetic() || method.isBridge() || isStatic(method.getModifiers())) {
            continue;
        }

        // look for annotations recursively in super-classes or interfaces
        Method managedMethod = findAnnotatedMethod(
                type,
                annotation,
                method.getName(),
                method.getParameterTypes());
        if (managedMethod != null) {
            result.add(managedMethod);
        }
    }

    return result;
}
 
Example 3
Project: lams   File: MockHelper.java   View Source Code Vote up 6 votes
private static Method getMethod(Class theClass, String propertyName) {
	Method[] methods = theClass.getDeclaredMethods();
	Method.setAccessible( methods, true );
	for ( Method method : methods ) {
		// if the method has parameters, skip it
		if ( method.getParameterTypes().length != 0 ) {
			continue;
		}
		// if the method is a "bridge", skip it
		if ( method.isBridge() ) {
			continue;
		}

		final String methodName = method.getName();
		if ( methodName.equals( propertyName ) ) {
			return method;
		}
	}

	return null;
}
 
Example 4
Project: Muster   File: MusterLambdaHandler.java   View Source Code Vote up 6 votes
private static void populateHandlerConfiguration(Class<?> handler) {
	Class<?> publicInterface = getPublicInterface(handler);
	if (publicInterface != null) {
		Method[] methods = publicInterface.getMethods();
		for (Method method : methods) {
			if (publicInterface.equals(method.getDeclaringClass()) && !method.isBridge()
					&& "execute".equals(method.getName())) {
				if (method.getParameterTypes().length == 1) {
					MusterServiceConfiguration annotation = publicInterface.getAnnotation(com.github.dmozzy.muster.api.MusterServiceConfiguration.class);
					functionHandlers.put(annotation.name(),
							new PublicIntferfaceReference((Class<? extends MusterService<?, ?>>) handler,
									method.getParameterTypes()[0], method.getReturnType(), annotation.service(),
									annotation.name(), annotation.idempotency()));
				}
			}
		}
	}
	Class<?>[] classes = handler.getClasses();
	for (Class<?> clazz : classes) {
		populateHandlerConfiguration(clazz);
	}
}
 
Example 5
Project: Phoenix-for-VK   File: AnnotatedHandlerFinder.java   View Source Code Vote up 5 votes
/**
 * Load all methods annotated with {@link OnGuiCreated} into their respective caches for the
 * specified class.
 */
private static void loadAnnotatedMethods(Class<?> listenerClass, Set<Method> methods) {
    for (Method method : listenerClass.getDeclaredMethods()) {
        // The compiler sometimes creates synthetic bridge methods as part of the
        // type erasure process. As of JDK8 these methods now include the same
        // annotations as the original declarations. They should be ignored for
        // subscribe/produce.
        if (method.isBridge()) {
            continue;
        }

        if (method.isAnnotationPresent(OnGuiCreated.class)) {
            Class<?>[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length != 0) {
                throw new IllegalArgumentException("Method " + method + " has @OnGuiCreated annotation but requires "
                        + parameterTypes.length + " arguments.  Methods must require zero arguments.");
            }

            //if ((method.getModifiers() & Modifier.PUBLIC) == 0) {
            //    throw new IllegalArgumentException("Method " + method + " has @OnGuiCreated annotation but is not 'public'.");
            //}

            methods.add(method);
        }
    }

    METHODS_ON_GUI_CREATED_CACHE.put(listenerClass, methods);
}
 
Example 6
Project: XSnow   File: EventFind.java   View Source Code Vote up 5 votes
private static EventComposite findAnnotatedMethods(Object listenerClass, Set<EventSubscriber> subscriberMethods,
                                                   CompositeDisposable compositeDisposable) {
    for (Method method : listenerClass.getClass().getDeclaredMethods()) {
        if (method.isBridge()) {
            continue;
        }
        if (method.isAnnotationPresent(Subscribe.class)) {
            Class<?>[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length != 1) {
                throw new IllegalArgumentException("Method " + method + " has @Subscribe annotation but requires " + parameterTypes
                        .length + " arguments.  Methods must require a single argument.");
            }

            Class<?> parameterClazz = parameterTypes[0];
            if ((method.getModifiers() & Modifier.PUBLIC) == 0) {
                throw new IllegalArgumentException("Method " + method + " has @EventSubscribe annotation on " + parameterClazz + " " +
                        "but is not 'public'.");
            }

            Subscribe annotation = method.getAnnotation(Subscribe.class);
            ThreadMode thread = annotation.threadMode();

            EventSubscriber subscriberEvent = new EventSubscriber(listenerClass, method, thread);
            if (!subscriberMethods.contains(subscriberEvent)) {
                subscriberMethods.add(subscriberEvent);//添加事件订阅者
                compositeDisposable.add(subscriberEvent.getDisposable());//管理订阅,方便取消订阅
            }
        }
    }
    return new EventComposite(compositeDisposable, listenerClass, subscriberMethods);
}
 
Example 7
Project: Muster   File: LambdaMusterOrchestrationManager.java   View Source Code Vote up 5 votes
private <T, R> Class<R> getReturnType(Class<? extends MusterService<T, R>> publicInterface) {
	if (publicInterface != null) {
		Method[] methods = publicInterface.getMethods();
		for (Method method : methods) {
			if (publicInterface.equals(method.getDeclaringClass()) && !method.isBridge()
					&& "execute".equals(method.getName())) {
				if (method.getParameterTypes().length == 1) {
					return (Class<R>) method.getReturnType();
				}
			}
		}
	}
	return null;
}
 
Example 8
Project: lams   File: ReflectionHelper.java   View Source Code Vote up 5 votes
public static boolean isProperty(Member m) {
	if ( m instanceof Method ) {
		Method method = (Method) m;
		return !method.isSynthetic()
				&& !method.isBridge()
				&& !Modifier.isStatic( method.getModifiers() )
				&& method.getParameterTypes().length == 0
				&& ( method.getName().startsWith( "get" ) || method.getName().startsWith( "is" ) );
	}
	else {
		return !Modifier.isTransient( m.getModifiers() ) && !m.isSynthetic();
	}
}
 
Example 9
Project: openjdk-jdk10   File: ReflectionNavigator.java   View Source Code Vote up 4 votes
public boolean isBridgeMethod(Method method) {
    return method.isBridge();
}
 
Example 10
Project: jDialects   File: ReflectionUtils.java   View Source Code Vote up 4 votes
@Override
public boolean matches(Method method) {
	return !method.isBridge();
}
 
Example 11
Project: util   File: ReflectionUtils.java   View Source Code Vote up 4 votes
@Override
public boolean matches(Method method) {
	return (!method.isBridge() && method.getDeclaringClass() != Object.class);
}
 
Example 12
Project: spark-project   File: ReflectionUtils.java   View Source Code Vote up 4 votes
@Override
public boolean matches(Method method) {
	return !method.isBridge();
}
 
Example 13
Project: spark-project   File: ReflectionUtils.java   View Source Code Vote up 4 votes
@Override
public boolean matches(Method method) {
	return (!method.isBridge() && method.getDeclaringClass() != Object.class);
}
 
Example 14
Project: ProjectAres   File: EventHandlerScanner.java   View Source Code Vote up 4 votes
public boolean isHandler(Method method) {
    return findAnnotation(method) != null &&
           !method.isBridge() &&
           !method.isSynthetic();
}
 
Example 15
Project: tangyuan2   File: ReflectionUtils.java   View Source Code Vote up 4 votes
@Override
public boolean matches(Method method) {
	return (!method.isBridge() && method.getDeclaringClass() != Object.class);
}
 
Example 16
Project: CoreX   File: PluginManager.java   View Source Code Vote up 4 votes
public void registerEvents(Listener listener, Plugin plugin) {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + listener.getClass().getName() + " while not enabled");
    }

    Map<Class<? extends Event>, Set<RegisteredListener>> ret = new HashMap<>();
    Set<Method> methods;
    try {
        Method[] publicMethods = listener.getClass().getMethods();
        Method[] privateMethods = listener.getClass().getDeclaredMethods();
        methods = new HashSet<>(publicMethods.length + privateMethods.length, 1.0f);
        Collections.addAll(methods, publicMethods);
        Collections.addAll(methods, privateMethods);
    } catch (NoClassDefFoundError e) {
        plugin.getLogger().error("Plugin " + plugin.getDescription().getFullName() + " has failed to register events for " + listener.getClass() + " because " + e.getMessage() + " does not exist.");
        return;
    }

    for (final Method method : methods) {
        final EventHandler eh = method.getAnnotation(EventHandler.class);
        if (eh == null) continue;
        if (method.isBridge() || method.isSynthetic()) {
            continue;
        }
        final Class<?> checkClass;

        if (method.getParameterTypes().length != 1 || !Event.class.isAssignableFrom(checkClass = method.getParameterTypes()[0])) {
            plugin.getLogger().error(plugin.getDescription().getFullName() + " attempted to register an invalid EventHandler method signature \"" + method.toGenericString() + "\" in " + listener.getClass());
            continue;
        }

        final Class<? extends Event> eventClass = checkClass.asSubclass(Event.class);
        method.setAccessible(true);

        for (Class<?> clazz = eventClass; Event.class.isAssignableFrom(clazz); clazz = clazz.getSuperclass()) {
            // This loop checks for extending deprecated events
            if (clazz.getAnnotation(Deprecated.class) != null) {
                if (Boolean.valueOf(String.valueOf(this.server.getConfig("settings.deprecated-verbpse", true)))) {
                    this.server.getLogger().warning(this.server.getLanguage().translateString("nukkit.plugin.deprecatedEvent", plugin.getName(), clazz.getName(), listener.getClass().getName() + "." + method.getName() + "()"));
                }
                break;
            }
        }
        EventExecutor executor = EventExecutor.create(method, eventClass);
        this.registerEvent(eventClass, listener, eh.priority(), executor, plugin, eh.ignoreCancelled());
    }
}
 
Example 17
Project: OpenJSharp   File: ReflectionNavigator.java   View Source Code Vote up 4 votes
public boolean isBridgeMethod(Method method) {
    return method.isBridge();
}
 
Example 18
Project: ooso   File: AWSLambdaAsyncMockClient.java   View Source Code Vote up 3 votes
private Class getLambdaPayloadClass(Class functionClass) {

        Class payloadClass = null;

        for (Method method : functionClass.getDeclaredMethods())
            if (method.getName().equals("handleRequest") && !method.isSynthetic() && !method.isBridge())
                payloadClass = method.getParameterTypes()[0];

        return payloadClass;
    }
 
Example 19
Project: jDialects   File: ClassUtils.java   View Source Code Vote up 2 votes
/**
 * Determine whether the given method is declared by the user or at least pointing to
 * a user-declared method.
 * <p>Checks {@link Method#isSynthetic()} (for implementation methods) as well as the
 * {@code GroovyObject} interface (for interface methods; on an implementation class,
 * implementations of the {@code GroovyObject} methods will be marked as synthetic anyway).
 * Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
 * as user-level methods since they are eventually pointing to a user-declared generic method.
 * @param method the method to check
 * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
 */
public static boolean isUserLevelMethod(Method method) {
	Assert.notNull(method, "Method must not be null");
	return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
}
 
Example 20
Project: businessworks   File: InjectionPoint.java   View Source Code Vote up 2 votes
/** 
 * Returns true if the method is eligible to be injected.  This is different than
 * {@link #isValidMethod}, because ineligibility will not drop a method
 * from being injected if a superclass was eligible & valid. 
 * Bridge & synthetic methods are excluded from eligibility for two reasons:
 * 
 * <p>Prior to Java8, javac would generate these methods in subclasses without
 * annotations, which means this would accidentally stop injecting a method
 * annotated with {@link javax.inject.Inject}, since the spec says to stop
 * injecting if a subclass isn't annotated with it.
 * 
 * <p>Starting at Java8, javac copies the annotations to the generated subclass
 * method, except it leaves out the generic types.  If this considered it a valid
 * injectable method, this would eject the parent's overridden method that had the
 * proper generic types, and would use invalid injectable parameters as a result.
 * 
 * <p>The fix for both is simply to ignore these synthetic bridge methods.
 */
private static boolean isEligibleForInjection(Method method, boolean statics) {
  return Modifier.isStatic(method.getModifiers()) == statics
      && !method.isBridge()
      && !method.isSynthetic();
}