org.bbottema.javareflection.model.MethodModifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-reflection Show documentation
Show all versions of java-reflection Show documentation
Java Reflection provides a small package with nifty reflection features that will help with finding constructors, methods and value conversions
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;
}
}