Example usage for java.lang.reflect Modifier isSynchronized

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

Introduction

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

Prototype

public static boolean isSynchronized(int mod) 

Source Link

Document

Return true if the integer argument includes the synchronized modifier, false otherwise.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class<?> clazz = String.class;
    int modifier = clazz.getModifiers();

    if (Modifier.isSynchronized(modifier)) {
        System.out.println("isSynchronized");
    }/*from   w w w  . j  a  v a 2 s.  c o m*/
}

From source file:DeclarationInfoDemo.java

public static void printModifiers(final Class dataType) {
    final int modifiers = dataType.getModifiers();
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }/*from   www . j  a v a2 s  . co m*/
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isPublic(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isAbstract(modifiers)) {
        System.out.print("abstract ");
    }
    if (Modifier.isFinal(modifiers)) {
        System.out.print("final ");
    }
    if (Modifier.isNative(modifiers)) {
        System.out.print("native ");
    }
    if (Modifier.isInterface(modifiers)) {
        System.out.print("interface ");
    }
    if (Modifier.isStatic(modifiers)) {
        System.out.print("static ");
    }
    if (Modifier.isStrict(modifiers)) {
        System.out.print("strict ");
    }
    if (Modifier.isSynchronized(modifiers)) {
        System.out.print("synchronized ");
    }
    if (Modifier.isTransient(modifiers)) {
        System.out.print("transient ");
    }
    if (Modifier.isVolatile(modifiers)) {
        System.out.print("volatile ");
    }
    System.out.println(dataType.getName());
}

From source file:ModifierUtil.java

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

From source file:in.hatimi.nosh.support.CommandExecutor.java

private Method findMainMethod() {
    Method[] methods = cmdCls.getMethods();
    for (Method method : methods) {
        if (!method.getName().equals("execute")) {
            continue; //method name must be 'execute'
        }//w  w w . j ava 2 s .  c o  m
        int mod = method.getModifiers();
        if (Modifier.isAbstract(mod)) {
            continue; //method cannot be abstract.
        }
        if (Modifier.isStatic(mod)) {
            continue; //method cannot be static.
        }
        if (Modifier.isSynchronized(mod)) {
            continue; //method cannot be synthetic.
        }
        if (!Modifier.isPublic(mod)) {
            continue; //method must be public.
        }
        if (method.getReturnType() != Void.TYPE) {
            continue; //method must not return a value.
        }
        Class<?>[] paramTypes = method.getParameterTypes();
        if (paramTypes.length > 1) {
            continue; //method can take at most one parameter.
        }
        if (paramTypes.length == 1 && !paramTypes[0].equals(String[].class)) {
            continue; //if single parameter, must be String[]
        }
        return method;
    }
    return null;
}

From source file:objenome.util.bytecode.SgUtils.java

private static void checkModifiers(int type, int modifiers) {
    for (int modifier = ABSTRACT; modifier <= STRICTFP; modifier++) {
        if (Modifier.isPrivate(modifiers) && !MODIFIERS_MATRIX[PRIVATE][type]) {
            throwIllegalArgument(type, PRIVATE);
        }/*from w w  w  . j a  v a 2 s. c o  m*/
        if (Modifier.isProtected(modifiers) && !MODIFIERS_MATRIX[PROTECTED][type]) {
            throwIllegalArgument(type, PROTECTED);
        }
        if (Modifier.isPublic(modifiers) && !MODIFIERS_MATRIX[PUBLIC][type]) {
            throwIllegalArgument(type, PUBLIC);
        }
        if (Modifier.isStatic(modifiers) && !MODIFIERS_MATRIX[STATIC][type]) {
            throwIllegalArgument(type, STATIC);
        }
        if (Modifier.isAbstract(modifiers) && !MODIFIERS_MATRIX[ABSTRACT][type]) {
            throwIllegalArgument(type, ABSTRACT);
        }
        if (Modifier.isFinal(modifiers) && !MODIFIERS_MATRIX[FINAL][type]) {
            throwIllegalArgument(type, FINAL);
        }
        if (Modifier.isNative(modifiers) && !MODIFIERS_MATRIX[NATIVE][type]) {
            throwIllegalArgument(type, NATIVE);
        }
        if (Modifier.isSynchronized(modifiers) && !MODIFIERS_MATRIX[SYNCHRONIZED][type]) {
            throwIllegalArgument(type, SYNCHRONIZED);
        }
        if (Modifier.isTransient(modifiers) && !MODIFIERS_MATRIX[TRANSIENT][type]) {
            throwIllegalArgument(type, TRANSIENT);
        }
        if (Modifier.isVolatile(modifiers) && !MODIFIERS_MATRIX[VOLATILE][type]) {
            throwIllegalArgument(type, VOLATILE);
        }
        if (Modifier.isStrict(modifiers) && !MODIFIERS_MATRIX[STRICTFP][type]) {
            throwIllegalArgument(type, STRICTFP);
        }
    }
}

From source file:objenome.util.bytecode.SgUtils.java

/**
 * Checks if the modifiers are valid for a method. If any of the modifiers
 * is not valid an <code>IllegalArgumentException</code> is thrown.
 * /*from   www .  j av a  2 s .  c  o m*/
 * @param modifiers
 *            Modifiers.
 */
// CHECKSTYLE:OFF Cyclomatic complexity is OK
public static void checkMethodModifiers(int modifiers) {

    // Base check
    checkModifiers(METHOD, modifiers);

    // Check overlapping modifiers
    if (Modifier.isPrivate(modifiers)) {
        if (Modifier.isProtected(modifiers) || Modifier.isPublic(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }
    if (Modifier.isProtected(modifiers)) {
        if (Modifier.isPrivate(modifiers) || Modifier.isPublic(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }
    if (Modifier.isPublic(modifiers)) {
        if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ACCESS_MODIFIER_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }

    // Check illegal abstract modifiers
    if (Modifier.isAbstract(modifiers)) {
        if (Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)
                || Modifier.isNative(modifiers) || Modifier.isStrict(modifiers)
                || Modifier.isSynchronized(modifiers)) {
            throw new IllegalArgumentException(
                    METHOD_ILLEGAL_ABSTRACT_MODIFIERS_ERROR + " [" + Modifier.toString(modifiers) + ']');
        }
    }

    // Check native and strictfp
    if (Modifier.isNative(modifiers) && Modifier.isStrict(modifiers)) {
        throw new IllegalArgumentException(
                METHOD_NATIVE_STRICTFP_ERROR + " [" + Modifier.toString(modifiers) + ']');
    }

}

From source file:org.lmn.fc.common.utilities.pending.Utilities.java

/***********************************************************************************************
 * Show the Member Modifiers.//from   w  w w .  ja  v  a  2 s  .com
 *
 * @param member
 *
 * @return String
 */

public static String showModifiers(final Member member) {
    final int modifiers;
    final StringBuffer buffer;

    buffer = new StringBuffer();

    if (member != null) {
        modifiers = member.getModifiers();

        if (Modifier.isAbstract(modifiers)) {
            buffer.append("Abstract ");
        }

        if (Modifier.isFinal(modifiers)) {
            buffer.append("Final ");
        }

        if (Modifier.isInterface(modifiers)) {
            buffer.append("Interface ");
        }

        if (Modifier.isNative(modifiers)) {
            buffer.append("Native ");
        }

        if (Modifier.isPrivate(modifiers)) {
            buffer.append("Private ");
        }

        if (Modifier.isProtected(modifiers)) {
            buffer.append("Protected ");
        }

        if (Modifier.isPublic(modifiers)) {
            buffer.append("Public ");
        }

        if (Modifier.isStatic(modifiers)) {
            buffer.append("Static ");
        }

        if (Modifier.isStrict(modifiers)) {
            buffer.append("Strict ");
        }

        if (Modifier.isSynchronized(modifiers)) {
            buffer.append("Synchronized ");
        }

        if (Modifier.isTransient(modifiers)) {
            buffer.append("Transient ");
        }

        if (Modifier.isVolatile(modifiers)) {
            buffer.append("Volatile ");
        }
    }

    return (buffer.toString().trim());
}

From source file:com.judoscript.jamaica.parser.JamaicaDumpVisitor.java

static void printAccessFlags(int flags) {
    if (Modifier.isPublic(flags))
        out.print("public ");
    else if (Modifier.isProtected(flags))
        out.print("protected ");
    else if (Modifier.isPrivate(flags))
        out.print("private ");

    if (Modifier.isAbstract(flags))
        out.print("abstract ");
    if (Modifier.isFinal(flags))
        out.print("final ");
    if (Modifier.isNative(flags))
        out.print("native ");
    if (Modifier.isStatic(flags))
        out.print("static ");
    if (Modifier.isStrict(flags))
        out.print("strict ");
    if (Modifier.isSynchronized(flags))
        out.print("synchronized ");
    if (Modifier.isTransient(flags))
        out.print("transient ");
    if (Modifier.isVolatile(flags))
        out.print("volative ");
}

From source file:name.yumaa.ChromeLogger4J.java

/**
 * Returns a nicely formatted key of the field or method name
 * @param mod    .getModifiers()//from www  .  ja  v a  2 s.  c  o  m
 * @param end    key ending
 * @return class member keys, converted to string
 */
private String getKey(int mod, String end) {
    StringBuilder key = new StringBuilder("");
    if (Modifier.isPublic(mod))
        key.append("public ");
    if (Modifier.isPrivate(mod))
        key.append("private ");
    if (Modifier.isProtected(mod))
        key.append("protected ");
    if (Modifier.isStatic(mod))
        key.append("static ");
    if (Modifier.isTransient(mod))
        key.append("transient ");
    if (Modifier.isVolatile(mod))
        key.append("volatile ");
    if (Modifier.isFinal(mod))
        key.append("final ");
    if (Modifier.isSynchronized(mod))
        key.append("synchronized ");
    return key.append(end).toString();
}

From source file:ca.oson.json.Oson.java

private boolean ignoreModifiers(int modifiers, Set<MODIFIER> includeFieldsWithModifiers) {
    //Set<MODIFIER> includeFieldsWithModifiers = getIncludeFieldsWithModifiers();
    if (includeFieldsWithModifiers == null || includeFieldsWithModifiers.size() == 0) {
        // by default, transient and volatile are ignored
        // unless you specify otherwise, by using MODIFIER.Transient enum, or all
        if (Modifier.isTransient(modifiers)) {
            return true;
        }/*  www.j  a  va2s.c  o m*/
        if (Modifier.isVolatile(modifiers)) {
            return true;
        }

        return false;
    }

    if (includeFieldsWithModifiers.contains(MODIFIER.All)) {
        return false;
    }

    for (MODIFIER modifier : includeFieldsWithModifiers) {
        switch (modifier) {
        case Abstract:
            if (Modifier.isAbstract(modifiers)) {
                return false;
            }
            break;
        case Final:
            if (Modifier.isFinal(modifiers)) {
                return false;
            }
            break;
        case Interface:
            if (Modifier.isInterface(modifiers)) {
                return false;
            }
            break;
        case Native:
            if (Modifier.isNative(modifiers)) {
                return false;
            }
            break;
        case Private:
            if (Modifier.isPrivate(modifiers)) {
                return false;
            }
            break;
        case Protected:
            if (Modifier.isProtected(modifiers)) {
                return false;
            }
            break;
        case Public:
            if (Modifier.isPublic(modifiers)) {
                return false;
            }
            break;
        case Package:
            if (ObjectUtil.isPackage(modifiers)) {
                return false;
            }
            break;
        case Static:
            if (Modifier.isStatic(modifiers)) {
                return false;
            }
            break;
        case Strict:
            if (Modifier.isStrict(modifiers)) {
                return false;
            }
            break;
        case Synchronized:
            if (Modifier.isSynchronized(modifiers)) {
                return false;
            }
            break;
        case Transient:
            if (Modifier.isTransient(modifiers)) {
                return false;
            }
            break;
        case Volatile:
            if (Modifier.isVolatile(modifiers)) {
                return false;
            }
            break;
        }
    }

    return true;
}