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

org.bbottema.javareflection.model.MethodModifier Maven / Gradle / Ivy

Go to download

Java Reflection provides a small package with nifty reflection features that will help with finding constructors, methods and value conversions

There is a newer version: 4.1.0
Show newest version
package org.bbottema.javareflection.model;

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

import static java.util.EnumSet.allOf;

@SuppressWarnings("unused")
public enum MethodModifier {
	PUBLIC(Modifier.PUBLIC),
	PROTECTED(Modifier.PROTECTED),
	PRIVATE(Modifier.PRIVATE),
	ABSTRACT(Modifier.ABSTRACT),
	DEFAULT(-1),
	STATIC(Modifier.STATIC),
	FINAL(Modifier.FINAL),
	SYNCHRONIZED(Modifier.SYNCHRONIZED),
	NATIVE(Modifier.NATIVE),
	STRICT(Modifier.STRICT);
	
	public static final EnumSet MATCH_ANY = allOf(MethodModifier.class);
	
	private final int modifierFlag;
	
	MethodModifier(int modifierFlag) {
		this.modifierFlag = modifierFlag;
	}
	
	public static boolean meetsModifierRequirements(Method method, EnumSet modifiers) {
		final int m = method.getModifiers();
		
		for (MethodModifier methodModifier : modifiers) {
			if (methodModifier != MethodModifier.DEFAULT) {
				if ((m & methodModifier.modifierFlag) != 0) {
					return true;
				}
			} else {
				if (!Modifier.isPrivate(m) && !Modifier.isProtected(m) && !Modifier.isPublic(m)) {
					return true;
				}
			}
		}
		return false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy