Example usage for java.lang.reflect Modifier toString

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

Introduction

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

Prototype

public static String toString(int mod) 

Source Link

Document

Return a string describing the access modifier flags in the specified modifier.

Usage

From source file:kilim.tools.DumpClass.java

public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    pn("");/*from w  w  w .  j ava2  s. co m*/
    pn("; -------------------------------------------------------------");
    p(".method ");
    p(Modifier.toString(access));
    p(" ");
    p(name);
    pn(desc);
    pn("; signature = " + signature);
    pn("; -------------------------------------------------------------\n");
    if (exceptions != null) {
        for (int i = 0; i < exceptions.length; i++) {
            p(".throws ");
            pn(exceptions[i]);
        }
    }
    return new DumpMethodVisitor();
}

From source file:com.googlecode.xtecuannet.framework.catalina.manager.tomcat.constants.Constants.java

public static List<Field> getOnlyFields(Class clazz) {

    List<Field> salida = new ArrayList<Field>(0);

    Field[] all = clazz.getDeclaredFields();

    for (int i = 0; i < all.length; i++) {
        Field field = all[i];/*from  w ww. j  a va2s . c o m*/

        logger.debug(Modifier.toString(field.getModifiers()) + "-" + field.getModifiers());
        if (field.getModifiers() == Modifier.PRIVATE) {

            salida.add(field);
        }
    }

    return salida;
}

From source file:hu.bme.mit.sette.common.validator.reflection.ClassValidator.java

/**
 * Sets the required modifiers for the Java class.
 *
 * @param modifiers//ww w .j a v a  2 s. c o m
 *            the required modifiers for the Java class.
 * @return this object
 */
public ClassValidator withModifiers(final int modifiers) {
    if (getSubject() != null) {
        Class<?> javaClass = getSubject();

        if ((javaClass.getModifiers() & modifiers) != modifiers) {
            this.addException(String.format(
                    "The Java class must have all the " + "specified modifiers\n(modifiers: [%s])",
                    Modifier.toString(modifiers)));
        }
    }

    return this;
}

From source file:hu.bme.mit.sette.common.validator.reflection.ClassValidator.java

/**
 * Sets the prohibited modifiers for the Java class.
 *
 * @param modifiers// w w  w  .  j  a  v  a 2 s .co m
 *            the prohibited modifiers for the Java class.
 * @return this object
 */
public ClassValidator withoutModifiers(final int modifiers) {
    if (getSubject() != null) {
        Class<?> javaClass = getSubject();

        if ((javaClass.getModifiers() & modifiers) != 0) {
            this.addException(String.format(
                    "The Java class must not have " + "any of the specified modifiers\n" + "(modifiers: [%s])",
                    Modifier.toString(modifiers)));
        }
    }

    return this;
}

From source file:kenh.xscript.elements.Debug.java

private void list(JList c) {
    if (result == null)
        return;//w ww .j a  v a 2 s .c o  m

    if (StringUtils.isBlank(c.getSelectedValue().toString()))
        return;

    if (this.getEnvironment() != null) {

        String context = "";
        try {
            Object obj = this.getEnvironment().getVariable(c.getSelectedValue().toString());
            if (obj != null) {

                context = c.getSelectedValue().toString() + LINE_SEP + LINE_SEP;

                context += "-- Class: " + obj.getClass().getCanonicalName() + LINE_SEP;

                context += LINE_SEP;
                context += "-- Fields: " + LINE_SEP;
                Field[] fields = obj.getClass().getFields();

                for (Field field : fields) {
                    int i = field.getModifiers();
                    String retval = Modifier.toString(i);
                    if (StringUtils.contains(retval, "public")) {
                        context += "\t" + field.getName() + " - " + retval + LINE_SEP;
                    }
                }

                context += LINE_SEP;
                context += "-- Method: " + LINE_SEP;
                java.lang.reflect.Method[] methods = obj.getClass().getMethods();

                for (java.lang.reflect.Method method : methods) {
                    int i = method.getModifiers();
                    String retval = Modifier.toString(i);
                    if (StringUtils.contains(retval, "public")) {
                        Class[] pcs = method.getParameterTypes();
                        StringBuffer sb = new StringBuffer();

                        for (Class c_ : pcs) {
                            String s = c_.getSimpleName();
                            sb.append(s + ", ");
                        }

                        String p = StringUtils.trimToEmpty(StringUtils.substringBeforeLast(sb.toString(), ","));

                        context += "\t" + method.getName() + "(" + p + ") - " + retval + LINE_SEP;
                    }
                }

            } else {
                context = "<null>";
            }
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            context = sw.toString();
        }

        result.setText(context);

    } else {
        result.setText(c.getSelectedValue().toString());
    }

    result.setCaretPosition(0);
    c.requestFocus();
}

From source file:net.orfjackal.retrolambda.test.LambdaTest.java

/**
 * We could make private lambda implementation methods package-private,
 * so that the lambda class may call them, but we should not make any
 * more methods non-private than is absolutely necessary.
 *///from   w  w w.  j  a  v a 2s. c  o m
@Test
public void will_not_change_the_visibility_of_unrelated_methods() throws Exception {
    assertThat(unrelatedPrivateMethod(), is("foo"));

    Method method = getClass().getDeclaredMethod("unrelatedPrivateMethod");
    int modifiers = method.getModifiers();

    assertTrue("expected " + method.getName() + " to be private, but modifiers were: "
            + Modifier.toString(modifiers), Modifier.isPrivate(modifiers));
}

From source file:Mopex.java

/**
 * Returns a String that represents the header for a constructor.
 * //  w w w  . j a v  a2s  .c  om
 * @return String
 * @param c
 *            java.lang.Constructor
 */
//start extract constructorHeaderToString
public static String headerToString(Constructor c) {
    String mods = Modifier.toString(c.getModifiers());
    if (mods.length() == 0)
        return headerSuffixToString(c);
    else
        return mods + " " + headerSuffixToString(c);
}

From source file:Mopex.java

/**
 * Returns a String that represents the header of a method.
 * /*from  w  w w .ja  v a  2s . c o  m*/
 * @return String
 * @param m
 *            java.lang.Method
 */
//start extract headerToString
public static String headerToString(Method m) {
    String mods = Modifier.toString(m.getModifiers());
    if (mods.length() == 0)
        return headerSuffixToString(m);
    else
        return mods + " " + headerSuffixToString(m);
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteria.java

/**
 * Set the criterion that selects only {@link Member}s that exactly have the
 * specified modifiers. The access modifiers are set separately. Use
 * {@link #withAccess(AccessType...)} to set access modifiers.
 *
 * @param modifiers//from  w w w  .j  a v a2 s .  c om
 * @since 1.0.0.0
 */
public void withModifiers(int modifiers) {
    if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)) {
        throw new IllegalArgumentException(
                "access modifiers are not allowed as argument. Use withAccess() instead.");
    }
    int allowedModifiers = Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT
            | Modifier.VOLATILE | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT
            | Modifier.INTERFACE;

    if ((modifiers & allowedModifiers) == 0) {
        throw new IllegalArgumentException(
                "modifiers must be one of [" + Modifier.toString(allowedModifiers) + "]");
    }

    this.modifiers = modifiers;
}

From source file:com.appleframework.core.utils.ClassUtility.java

/** ??method?? */
public static String getSimpleMethodSignature(Method method, boolean withModifiers, boolean withReturnType,
        boolean withClassName, boolean withExceptionType) {
    if (method == null) {
        return null;
    }//from w  w w . j a v  a  2  s. c o m

    StringBuilder buf = new StringBuilder();

    if (withModifiers) {
        buf.append(Modifier.toString(method.getModifiers())).append(' ');
    }

    if (withReturnType) {
        buf.append(getSimpleClassName(method.getReturnType())).append(' ');
    }

    if (withClassName) {
        buf.append(getSimpleClassName(method.getDeclaringClass())).append('.');
    }

    buf.append(method.getName()).append('(');

    Class<?>[] paramTypes = method.getParameterTypes();

    for (int i = 0; i < paramTypes.length; i++) {
        Class<?> paramType = paramTypes[i];

        buf.append(getSimpleClassName(paramType));

        if (i < paramTypes.length - 1) {
            buf.append(", ");
        }
    }

    buf.append(')');

    if (withExceptionType) {
        Class<?>[] exceptionTypes = method.getExceptionTypes();

        if (!isEmptyArray(exceptionTypes)) {
            buf.append(" throws ");

            for (int i = 0; i < exceptionTypes.length; i++) {
                Class<?> exceptionType = exceptionTypes[i];

                buf.append(getSimpleClassName(exceptionType));

                if (i < exceptionTypes.length - 1) {
                    buf.append(", ");
                }
            }
        }
    }

    return buf.toString();
}