Example usage for java.lang.reflect Modifier SYNCHRONIZED

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

Introduction

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

Prototype

int SYNCHRONIZED

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

Click Source Link

Document

The int value representing the synchronized 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.SYNCHRONIZED;
        int mods = accessModifiers(ctor.getModifiers());
        if (searchMod == mods) {
            System.out.println(ctor);
        }//ww w  . j  a  v a2  s  . co m
    }
}

From source file:Main.java

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

From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java

/**
 * Validates the fields of the class./*from   www  .  j av a  2  s .co  m*/
 *
 * @param validator
 *            a validator
 */
private void validateFields(final AbstractValidator<?> validator) {
    // check: only constant ("public static final") or synthetic fields
    for (Field field : javaClass.getDeclaredFields()) {
        if (field.isSynthetic()) {
            // skip for synthetic fields (e.g. switch for enum generates
            // synthetic methods and fields)
            continue;
        }

        FieldValidator v = new FieldValidator(field);
        v.withModifiers(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);
        v.withoutModifiers(Modifier.SYNCHRONIZED | Modifier.TRANSIENT | Modifier.VOLATILE);

        validator.addChildIfInvalid(v);
    }
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetInputFactoryContainer.java

/**
 * Validates methods of the class./*from w ww  . j a v a  2s. c  om*/
 *
 * @param validator
 *            a validator
 * @return a map containing the input factory methods by their name
 */
private Map<String, Method> validateMethods(final AbstractValidator<?> validator) {
    // check: only "public static" or synthetic methods
    Map<String, Method> factoryMethods = new HashMap<String, Method>();

    for (Method method : javaClass.getDeclaredMethods()) {
        if (method.isSynthetic()) {
            // skip synthetic methods
            continue;
        }

        MethodValidator v = new MethodValidator(method);

        if (factoryMethods.get(method.getName()) != null) {
            v.addException("The method must have a unique name");
        }

        v.withModifiers(Modifier.PUBLIC | Modifier.STATIC);
        v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED);

        factoryMethods.put(method.getName(), method);

        validator.addChildIfInvalid(v);
    }

    return factoryMethods;
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java

/**
 * Validates methods of the class./*w  w w.j a  va2 s . c  om*/
 *
 * @param validator
 *            a validator
 * @return a map containing the snippet methods by their name
 */
private Map<String, Method> validateMethods(final AbstractValidator<?> validator) {
    // check: only "[public|private] static" or synthetic methods
    Map<String, Method> snippetMethods = new HashMap<String, Method>();

    for (Method method : javaClass.getDeclaredMethods()) {
        if (method.isSynthetic()) {
            // skip synthetic methods
            continue;
        }

        MethodValidator v = new MethodValidator(method);

        if (snippetMethods.get(method.getName()) != null) {
            v.addException("The method must have a unique name");
        }

        int methodModifiers = method.getModifiers();

        if (!Modifier.isPublic(methodModifiers) && !Modifier.isPrivate(methodModifiers)) {
            v.addException("The method must be public or private");
        }

        v.withModifiers(Modifier.STATIC);
        v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED);

        AnnotationMap methodAnns = SetteAnnotationUtils.getSetteAnnotations(method);

        if (Modifier.isPublic(methodModifiers)) {
            if (methodAnns.get(SetteNotSnippet.class) == null) {
                // should be snippet, validated by Snippet class and added
                // later
                snippetMethods.put(method.getName(), method);
            } else {
                // not snippet
                snippetMethods.put(method.getName(), null);

                if (methodAnns.size() != 1) {
                    v.addException("The method must not have " + "any other SETTE annotations "
                            + "if it is not a snippet.");
                }
            }
        } else {
            // method is private
            if (methodAnns.size() != 0) {
                v.addException("The method must not have " + "any SETTE annotations");
            }
        }

        validator.addChildIfInvalid(v);
    }

    return snippetMethods;
}

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/*  ww w. ja  v a  2s . co m*/
 * @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;
}