Example usage for java.lang.reflect Modifier PUBLIC

List of usage examples for java.lang.reflect Modifier PUBLIC

Introduction

In this page you can find the example usage for java.lang.reflect Modifier PUBLIC.

Prototype

int PUBLIC

To view the source code for java.lang.reflect Modifier PUBLIC.

Click Source Link

Document

The int value representing the public modifier.

Usage

From source file:Main.java

public static void main(String... args) throws Exception {
    Class<?> c = Class.forName("java.lang.String");
    Constructor[] allConstructors = c.getDeclaredConstructors();
    for (Constructor ctor : allConstructors) {
        int searchMod = Modifier.PUBLIC;
        int mods = accessModifiers(ctor.getModifiers());
        if (searchMod == mods) {
            System.out.println(ctor);
        }//from  www  .j  a  v  a 2  s  .  com
    }
}

From source file:Main.java

private static int accessModifiers(int m) {
    return m & Modifier.PUBLIC;
}

From source file:Main.java

private static int accessModifiers(int m) {
    return m & (Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
}

From source file:Main.java

private static boolean isPublicNoStatic(int i) {
    return ((i & Modifier.PUBLIC) == Modifier.PUBLIC) && ((i & Modifier.STATIC) != Modifier.STATIC);
}

From source file:Main.java

private static int modifierFromString(String s) {
    if ("public".equals(s))
        return Modifier.PUBLIC;
    else if ("protected".equals(s))
        return Modifier.PROTECTED;
    else if ("private".equals(s))
        return Modifier.PRIVATE;
    else if ("package-private".equals(s))
        return 0;
    else//from   ww w.  j av a2s  .c o  m
        return -1;
}

From source file:Main.java

/**
 * Key to lowercase String, extracts the effective key that was pressed
 * (without shift, control, alt)/*from  w w  w  .  java  2s .c om*/
 */
public static String getKeyText(KeyEvent e) {
    // special cases
    if (e.getKeyCode() == KeyEvent.VK_DELETE) {
        return "delete";
    }
    // prio 1: get text of unresolved code (shift-1 --> '1')
    String s = "" + e.getKeyChar();
    if (e.getKeyCode() > 0) {
        int flags = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
        for (Field f : KeyEvent.class.getFields()) {
            if ((f.getModifiers() & flags) == flags) {
                try {
                    if (f.getName().startsWith("VK_") && ((Integer) f.get(null)) == e.getKeyCode()) {
                        s = f.getName().substring(3).toLowerCase();
                        break;
                    }
                } catch (Throwable t) {
                    // nop
                }
            }
        }
    }
    if (s.length() != 1) {
        // prio 2: check if the resolved char is valid (shift-1 --> '+')
        if (e.getKeyChar() >= 32 && e.getKeyChar() < 128) {
            s = "" + e.getKeyChar();
        }
    }
    return s.toLowerCase();
}

From source file:de.pribluda.android.jsonmarshaller.JSONMarshaller.java

/**
 * recursively marshall to JSON/*from w  w  w .j a  va  2 s .  com*/
 *
 * @param sink
 * @param object
 */
static void marshallRecursive(JSONObject sink, Object object)
        throws JSONException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
    // nothing to marshall
    if (object == null)
        return;
    // primitive object is a field and does not interes us here
    if (object.getClass().isPrimitive())
        return;
    // object not null,  and is not primitive - iterate through getters
    for (Method method : object.getClass().getMethods()) {
        // our getters are parameterless and start with "get"
        if ((method.getName().startsWith(GETTER_PREFIX) && method.getName().length() > BEGIN_INDEX
                || method.getName().startsWith(IS_PREFIX) && method.getName().length() > IS_LENGTH)
                && (method.getModifiers() & Modifier.PUBLIC) != 0 && method.getParameterTypes().length == 0
                && method.getReturnType() != void.class) {
            // is return value primitive?
            Class<?> type = method.getReturnType();
            if (type.isPrimitive() || String.class.equals(type)) {
                // it is, marshall it
                Object val = method.invoke(object);
                if (val != null) {
                    sink.put(propertize(method.getName()), val);
                }
                continue;
            } else if (type.isArray()) {
                Object val = marshallArray(method.invoke(object));
                if (val != null) {
                    sink.put(propertize(method.getName()), val);
                }
                continue;
            } else if (type.isAssignableFrom(Date.class)) {
                Date date = (Date) method.invoke(object);
                if (date != null) {
                    sink.put(propertize(method.getName()), date.getTime());
                }
                continue;
            } else if (type.isAssignableFrom(Boolean.class)) {
                Boolean b = (Boolean) method.invoke(object);
                if (b != null) {
                    sink.put(propertize(method.getName()), b.booleanValue());
                }
                continue;
            } else if (type.isAssignableFrom(Integer.class)) {
                Integer i = (Integer) method.invoke(object);
                if (i != null) {
                    sink.put(propertize(method.getName()), i.intValue());
                }
                continue;
            } else if (type.isAssignableFrom(Long.class)) {
                Long l = (Long) method.invoke(object);
                if (l != null) {
                    sink.put(propertize(method.getName()), l.longValue());
                }
                continue;
            } else {
                // does it have default constructor?
                try {
                    if (method.getReturnType().getConstructor() != null) {
                        Object val = marshall(method.invoke(object));
                        if (val != null) {
                            sink.put(propertize(method.getName()), val);
                        }
                        continue;
                    }
                } catch (NoSuchMethodException ex) {
                    // just ignore it here, it means no such constructor was found
                }
            }
        }
    }
}

From source file:com.hihframework.core.utils.ReflectUtil.java

public static final String[] getPublicFieldsName(Object obj) {
    return getFieldsName(obj, Modifier.PUBLIC);
}

From source file:Spy.java

private static int modifierFromString(String s) {
    int m = 0x0;/*from www.ja  va2 s .co m*/
    if ("public".equals(s))
        m |= Modifier.PUBLIC;
    else if ("protected".equals(s))
        m |= Modifier.PROTECTED;
    else if ("private".equals(s))
        m |= Modifier.PRIVATE;
    else if ("static".equals(s))
        m |= Modifier.STATIC;
    else if ("final".equals(s))
        m |= Modifier.FINAL;
    else if ("transient".equals(s))
        m |= Modifier.TRANSIENT;
    else if ("volatile".equals(s))
        m |= Modifier.VOLATILE;
    return m;
}

From source file:net.ymate.platform.core.beans.intercept.InterceptProxy.java

public Object doProxy(IProxyChain proxyChain) throws Throwable {
    // @Ignored?PUBLICObject
    boolean _ignored = proxyChain.getTargetMethod().isAnnotationPresent(Ignored.class);
    if (_ignored || __excludedMethodNames.contains(proxyChain.getTargetMethod().getName())
            || proxyChain.getTargetMethod().getDeclaringClass().equals(Object.class)
            || proxyChain.getTargetMethod().getModifiers() != Modifier.PUBLIC) {
        return proxyChain.doProxyChain();
    }// ww w.  j a v a 2  s  .c  o  m
    //
    Map<String, String> _contextParams = null;
    // ??@Before
    if (proxyChain.getTargetClass().isAnnotationPresent(Before.class)
            || proxyChain.getTargetMethod().isAnnotationPresent(Before.class)) {

        _contextParams = InterceptAnnoHelper.getContextParams(proxyChain.getProxyFactory().getOwner(),
                proxyChain.getTargetClass(), proxyChain.getTargetMethod());

        InterceptContext _context = new InterceptContext(IInterceptor.Direction.BEFORE,
                proxyChain.getProxyFactory().getOwner(), proxyChain.getTargetObject(),
                proxyChain.getTargetMethod(), proxyChain.getMethodParams(), _contextParams);
        //
        for (Class<? extends IInterceptor> _interceptClass : __doGetBeforeIntercepts(
                proxyChain.getTargetClass(), proxyChain.getTargetMethod())) {
            IInterceptor _interceptor = _interceptClass.newInstance();
            // ???
            Object _resultObj = _interceptor.intercept(_context);
            if (_resultObj != null) {
                return _resultObj;
            }
        }
    }
    // ?
    Object _returnValue = proxyChain.doProxyChain();
    // ??@After
    if (proxyChain.getTargetClass().isAnnotationPresent(After.class)
            || proxyChain.getTargetMethod().isAnnotationPresent(After.class)) {

        if (_contextParams == null) {
            _contextParams = InterceptAnnoHelper.getContextParams(proxyChain.getProxyFactory().getOwner(),
                    proxyChain.getTargetClass(), proxyChain.getTargetMethod());
        }
        // ???
        InterceptContext _context = new InterceptContext(IInterceptor.Direction.AFTER,
                proxyChain.getProxyFactory().getOwner(), proxyChain.getTargetObject(),
                proxyChain.getTargetMethod(), proxyChain.getMethodParams(), _contextParams);
        _context.setResultObject(_returnValue);
        //
        for (Class<? extends IInterceptor> _interceptClass : __doGetAfterIntercepts(proxyChain.getTargetClass(),
                proxyChain.getTargetMethod())) {
            IInterceptor _interceptor = _interceptClass.newInstance();
            // ??
            _interceptor.intercept(_context);
        }
    }
    return _returnValue;
}