get Modifier Level - Java Reflection

Java examples for Reflection:Modifier

Description

get Modifier Level

Demo Code


//package com.java2s;
import java.util.Set;
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;

public class Main {
    static final int PRIVATE = -1;
    static final int DEFAULT = 0;
    static final int PROTECTED = 1;
    static final int PUBLIC = 2;

    static int getModifierLevel(Element element) {
        Set<Modifier> modifiers = element.getModifiers();
        if (modifiers.contains(Modifier.PUBLIC)) {
            return PUBLIC;
        }/* w w w  .ja  v  a 2  s  . c o m*/
        if (modifiers.contains(Modifier.PROTECTED)) {
            return PROTECTED;
        }
        if (modifiers.contains(Modifier.PRIVATE)) {
            return PRIVATE;
        }
        return DEFAULT;
    }
}

Related Tutorials