Modifier check utility. : Modifier « Reflection « Java






Modifier check utility.

        
//package org.t2framework.commons.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * 
 * <#if locale="en">
 * <p>
 * Modifier check utility.
 * </p>
 * <#else>
 * <p>
 * </p>
 * </#if>
 * 
 * @author shot
 * 
 */
public class ModifierUtil {

  public static boolean isAbstract(Member member) {
    return Modifier.isAbstract(member.getModifiers());
  }

  public static boolean isAbstract(Class<?> clazz) {
    return Modifier.isAbstract(clazz.getModifiers());
  }

  public static boolean isFinal(Member member) {
    return Modifier.isFinal(member.getModifiers());
  }

  public static boolean isFinal(Class<?> clazz) {
    return Modifier.isFinal(clazz.getModifiers());
  }

  public static boolean isInterface(Member member) {
    return Modifier.isInterface(member.getModifiers());
  }

  public static boolean isInterface(Class<?> clazz) {
    return Modifier.isInterface(clazz.getModifiers());
  }

  public static boolean isNative(Member member) {
    return Modifier.isNative(member.getModifiers());
  }

  public static boolean isPrivate(Member member) {
    return Modifier.isPrivate(member.getModifiers());
  }

  public static boolean isPrivate(Class<?> clazz) {
    return Modifier.isPrivate(clazz.getModifiers());
  }

  public static boolean isProtected(Member member) {
    return Modifier.isProtected(member.getModifiers());
  }

  public static boolean isProtected(Class<?> clazz) {
    return Modifier.isProtected(clazz.getModifiers());
  }

  public static boolean isPublic(Member member) {
    return Modifier.isPublic(member.getModifiers());
  }

  public static boolean isPublic(Class<?> clazz) {
    return Modifier.isPublic(clazz.getModifiers());
  }

  public static boolean isStatic(Member member) {
    return Modifier.isStatic(member.getModifiers());
  }

  public static boolean isStatic(Class<?> clazz) {
    return Modifier.isStatic(clazz.getModifiers());
  }

  public static boolean isStrict(Member member) {
    return Modifier.isStrict(member.getModifiers());
  }

  public static boolean isSynchronized(Member member) {
    return Modifier.isSynchronized(member.getModifiers());
  }

  public static boolean isTransient(Member member) {
    return Modifier.isTransient(member.getModifiers());
  }

  public static boolean isVolatile(Member member) {
    return Modifier.isVolatile(member.getModifiers());
  }

  public static boolean isBridge(Member member) {
    if (member instanceof Method) {
      return Method.class.cast(member).isBridge();
    } else {
      return false;
    }
  }

  @SuppressWarnings("unchecked")
  public static boolean isVarArgs(Member member) {
    if (member instanceof Method) {
      return Method.class.cast(member).isVarArgs();
    } else if (member instanceof Constructor) {
      return Constructor.class.cast(member).isVarArgs();
    } else {
      return false;
    }
  }

  public static boolean isSynthetic(Member member) {

    return member.isSynthetic();
  }

  public static boolean isEnumConstant(Member member) {
    if (member instanceof Field) {
      return Field.class.cast(member).isEnumConstant();
    } else {
      return false;
    }
  }

}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Return true if the integer argument includes the public modifier, false otherwise
2.Return true if the integer argument includes the private modifier, false otherwise.
3.Return true if the integer argument includes the protected modifier,false otherwise.
4.Return true if the integer argument includes the static modifier, false otherwise.
5.Return true if the integer argument includes the final modifier, false otherwise.
6.Return true if the integer argument includes the abstract modifier, false otherwise.
7.Overriding Default Access
8.Listing the Modifiers of a Class Object
9.Listing the Modifiers of a Member Object: Field, Constructor, and Method are all subclasses of Member.
10.Is Accessible
11.Set Accessibility
12.Make field accessible, explicitly setting it accessible
13.find an accessible method passed in
14.Gets a method and forces it to be accessible, even if it is not.