Example usage for java.lang.reflect Modifier STATIC

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

Introduction

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

Prototype

int STATIC

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

Click Source Link

Document

The int value representing the static modifier.

Usage

From source file:de.micromata.mgc.javafx.FXGuiUtils.java

public static void resetErroneousFields(AbstractModelController<?> controller) {
    List<Field> fields = PrivateBeanUtils.findAllFields(controller.getClass(), CommonMatchers
            .and(FieldMatchers.hasNotModifier(Modifier.STATIC), FieldMatchers.assignableTo(Node.class)));
    for (Field field : fields) {
        if (field.getName().equals("thisNode") == true) {
            continue;
        }/* w  ww .  j  a v a 2  s  .  c om*/
        Node node = (Node) PrivateBeanUtils.readField(controller, field);
        FXCssUtil.replaceStyleClass(CSS_CLASS_ERROR, CSS_CLASS_VALID, node);
    }

}

From source file:com.netflix.astyanax.util.StringUtils.java

public static <T> String joinClassGettersValues(final T object, String name, Class<T> clazz) {
    Method[] methods = clazz.getDeclaredMethods();

    StringBuilder sb = new StringBuilder();
    sb.append(name).append("[");
    sb.append(org.apache.commons.lang.StringUtils.join(Collections2.transform(
            // Filter any field that does not start with lower case
            // (we expect constants to start with upper case)
            Collections2.filter(Arrays.asList(methods), new Predicate<Method>() {
                @Override//  ww  w.ja  v a2 s. co m
                public boolean apply(Method method) {
                    if ((method.getModifiers() & Modifier.STATIC) == Modifier.STATIC)
                        return false;
                    return org.apache.commons.lang.StringUtils.startsWith(method.getName(), "get");
                }
            }),
            // Convert field to "name=value". value=*** on error
            new Function<Method, String>() {
                @Override
                public String apply(Method method) {
                    Object value;
                    try {
                        value = method.invoke(object);
                    } catch (Exception e) {
                        value = "***";
                    }
                    return org.apache.commons.lang.StringUtils.uncapitalize(
                            org.apache.commons.lang.StringUtils.substring(method.getName(), 3)) + "=" + value;
                }
            }), ","));
    sb.append("]");

    return sb.toString();
}

From source file:de.micromata.genome.tpsb.GroovyExceptionInterceptor.java

protected static void collectMethods(Class<?> cls, Map<String, Method> collected) {
    for (Method m : cls.getDeclaredMethods()) {
        if ((m.getModifiers() & Modifier.PUBLIC) != Modifier.PUBLIC) {
            continue;
        }//  ww w. j  a v  a 2  s.  c  om
        if ((m.getModifiers() & Modifier.STATIC) == Modifier.STATIC) {
            continue;
        }
        if (m.getAnnotation(TpsbIgnore.class) != null) {
            continue;
        }
        if (ignoreMethods.contains(m.getName()) == true) {
            continue;
        }
        if (m.getReturnType().isPrimitive() == true) {
            continue;
        }
        String sm = methodToString(m);
        if (collected.containsKey(sm) == true) {
            continue;
        }
        collected.put(sm, m);
    }
    Class<?> scls = cls.getSuperclass();
    if (scls == Object.class) {
        return;
    }
    collectMethods(scls, collected);
}

From source file:de.micromata.genome.util.matcher.cls.ContainsMethod.java

/**
 * Match this class.// w  ww . j av  a 2  s.  c  om
 *
 * @param cls the cls
 * @return true, if successful
 */
public boolean matchThisClass(Class<?> cls) {
    for (Method m : cls.getMethods()) {
        int mods = m.getModifiers();
        if (staticMethod == true && (mods & Modifier.STATIC) != Modifier.STATIC) {
            continue;
        }
        if (staticMethod == false && (mods & Modifier.STATIC) == Modifier.STATIC) {
            continue;
        }
        if (publicMethod == true && (mods & Modifier.PUBLIC) != Modifier.PUBLIC) {
            continue;
        }

        if (name != null) {
            if (StringUtils.equals(m.getName(), name) == false) {
                continue;
            }
        }
        if (returnType != null) {
            if (m.getReturnType() != returnType) {
                continue;
            }
        }
        if (params != null) {
            Class<?>[] pt = m.getParameterTypes();
            if (pt.length != params.length) {
                continue;
            }
            for (int i = 0; i < pt.length; ++i) {
                if (pt[i] != params[i]) {
                    continue;
                }
            }
        }
        return true;
    }
    return false;
}

From source file:org.eclipse.skalli.testutil.PropertyTestUtil.java

public static final void checkPropertyDefinitions(Class<?> classToCheck,
        Map<Class<?>, String[]> requiredProperties, Map<String, Object> values)
        throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException,
        InstantiationException, InvocationTargetException {
    Class<?> clazz = classToCheck;
    while (clazz != null) {

        // assert that the model class under test has a suitable constructor (either
        // a default constructor if requiredProperties is empty, or a constructor with the
        // correct number and type of parameters), and can be instantiated
        Object instance = assertExistsConstructor(clazz, requiredProperties, values);

        for (Field field : clazz.getDeclaredFields()) {
            if (hasAnnotation(field, PropertyName.class)) {

                // assert that the field is public static final
                Assert.assertTrue(clazz.getName() + ": constant " + field.getName() + " is not declared STATIC",
                        (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC); //$NON-NLS-1$
                Assert.assertTrue(clazz.getName() + ": constant " + field.getName() + " is not declared PUBLIC",
                        (field.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC); //$NON-NLS-1$
                Assert.assertTrue(clazz.getName() + ": constant " + field.getName() + " is not declared FINAL",
                        (field.getModifiers() & Modifier.FINAL) == Modifier.FINAL); //$NON-NLS-1$

                // assert that the constant if of type String and has a value assigned.
                Object object = field.get(null);
                Assert.assertNotNull(clazz.getName() + ": constant " + field.getName() + " is NULL", object); //$NON-NLS-1$
                Assert.assertTrue(clazz.getName() + ": constants " + field.getName() + " is not of type STRING",
                        object instanceof String); //$NON-NLS-1$

                // assert that there is a private non-static field with a name matching the
                // value of the constant unless the property is marked as derived
                String fieldName = (String) object;
                if (!hasAnnotation(field, Derived.class)) {
                    Assert.assertTrue(clazz.getName() + ": must have a private field named " + fieldName,
                            hasPrivateField(clazz, fieldName));
                }//from  w ww.j  a  v  a  2 s.  co  m

                // assert that the values argument contains a test value for this field
                Assert.assertTrue(clazz.getName() + ": no test value for field " + fieldName,
                        values.containsKey(fieldName));

                Methods methods = new Methods();

                // assert that the class has a getter for this property
                methods.getMethod = assertExistsGetMethod(clazz, fieldName);

                // assert that the class has a setter for this property if it is an optional property;
                // required properties must be set in the constructor;
                // skip properties that are annotated as @Derived
                if (isOptionalProperty(clazz, fieldName, requiredProperties)
                        && !hasAnnotation(field, Derived.class)) {
                    Class<?> returnType = methods.getMethod.getReturnType();
                    if (!Collection.class.isAssignableFrom(returnType)) {
                        methods.setMethod = assertExistsSetMethod(clazz, fieldName, returnType);
                    } else {
                        Class<?> entryType = ((Collection<?>) values.get(fieldName)).iterator().next()
                                .getClass();
                        methods.addMethod = assertExistsCollectionMethod(clazz, fieldName, entryType, "add");
                        methods.removeMethod = assertExistsCollectionMethod(clazz, fieldName, entryType,
                                "remove");
                        methods.hasMethod = assertExistsCollectionMethod(clazz, fieldName, entryType, "has");
                    }
                    // call the setter/adder and getter methods with the given test value
                    if (instance != null) {
                        assertChangeReadCycle(clazz, fieldName, methods, instance, values.get(fieldName));
                    }
                } else {
                    if (instance != null) {
                        assertReadCycle(clazz, methods, instance, values.get(fieldName));
                    }
                }
            }
        }

        // check the properties of the parent class (EntityBase!)
        clazz = clazz.getSuperclass();
    }
}

From source file:org.modeshape.rhq.util.I18n.java

/**
 * Should be called in a <code>static</code> block to load the properties file and assign values to the class string fields.
 * /*from ww  w. j a  va  2  s  .  com*/
 * @throws IllegalStateException if there is a problem reading the I8n class file or properties file
 */
protected void initialize() {
    final Map<String, Field> fields = new HashMap<String, Field>();

    // collect all public, static, non-final, string fields
    try {
        for (final Field field : getClass().getDeclaredFields()) {
            final int modifiers = field.getModifiers();

            if ((field.getType() == String.class) && ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC)
                    && ((modifiers & Modifier.STATIC) == Modifier.STATIC)
                    && ((modifiers & Modifier.FINAL) != Modifier.FINAL)) {
                fields.put(field.getName(), field);
            }
        }
    } catch (final Exception e) {
        throw new IllegalStateException(I18n.bind(UtilI18n.problemLoadingI18nClass, getClass().getName()), e);
    }

    // return if nothing to do
    if (ToolBox.isEmpty(fields)) {
        return;
    }

    // load properties file
    InputStream stream = null;
    IllegalStateException problem = null;

    try {
        final Class<? extends I18n> thisClass = getClass();
        final String bundleName = thisClass.getName().replaceAll("\\.", "/").concat(".properties"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        final URL url = thisClass.getClassLoader().getResource(bundleName);
        stream = url.openStream();

        final Collection<String> errors = new ArrayList<String>();
        final Properties props = new I18nProperties(fields, thisClass, errors);
        props.load(stream);

        // log errors for any properties keys that don't have fields
        for (final String error : errors) {
            if (problem == null) {
                problem = new IllegalStateException(error);
            }

            this.logger.error(error);
        }

        // log errors for any fields that don't have properties
        for (final String fieldName : fields.keySet()) {
            final String error = I18n.bind(UtilI18n.missingPropertiesKey, fieldName, getClass().getName());

            if (problem == null) {
                problem = new IllegalStateException(error);
            }

            this.logger.error(error);
        }
    } catch (final Exception e) {
        throw new IllegalStateException(I18n.bind(UtilI18n.problemLoadingI18nProperties, getClass().getName()),
                e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (final Exception e) {
            } finally {
                stream = null;
            }
        }

        if (problem != null) {
            throw problem;
        }
    }
}

From source file:org.lambdamatic.mongodb.apt.testutil.FieldAssertion.java

private static final boolean isStatic(final Field field) {
    return (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
}

From source file:com.github.geequery.codegen.ast.JavaMethod.java

public void setStatic(boolean isStatic) {
    if (isStatic != isStatic()) {
        modifier ^= Modifier.STATIC;
    }
}

From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderUserMetadata.java

public SafeSecurityProviderUserMetadata(String identifier, JavaType aspectName,
        PhysicalTypeMetadata governorPhysicalTypeMetadata) {
    super(identifier, aspectName, governorPhysicalTypeMetadata);
    /*Validate.isTrue(isValid(identifier), "Metadata identification string '"
        + identifier + "' does not appear to be a valid");*/

    // Helper itd generation
    this.helper = new ItdBuilderHelper(this, governorPhysicalTypeMetadata,
            builder.getImportRegistrationResolver());

    // Adding Fields
    builder.addField(getField("serialVersionUID", "5767016615242591655L", JavaType.LONG_PRIMITIVE,
            Modifier.PRIVATE + Modifier.STATIC + Modifier.FINAL));
    // User Details
    builder.addField(getField("username", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("password", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("accountNonExpired", null, JAVA_TYPE_BOOLEAN, Modifier.PRIVATE));
    builder.addField(getField("accountNonLocked", null, JAVA_TYPE_BOOLEAN, Modifier.PRIVATE));
    builder.addField(getField("credentialsNonExpired", null, JAVA_TYPE_BOOLEAN, Modifier.PRIVATE));
    builder.addField(getField("enabled", null, JAVA_TYPE_BOOLEAN, Modifier.PRIVATE));
    builder.addField(getField("authorities", null, GRANTED_AUTHORITY, Modifier.PRIVATE));
    // SAFE USER DATA
    builder.addField(getField("nombre", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("email", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("apellido1", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("apellido2", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("cif", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("habilitado", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("idHDFI", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("iusserDN", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("nif", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("oid", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("razonSocial", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("representante", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("serialNumber", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("subjectDN", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("tipoAut", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("tipoCertificado", null, JAVA_TYPE_STRING, Modifier.PRIVATE));

    // Creating methods
    builder.addMethod(getGetterMethod("username", JavaType.STRING));
    builder.addMethod(getSetterMethod("username", JavaType.STRING));
    builder.addMethod(getGetterMethod("password", JavaType.STRING));
    builder.addMethod(getSetterMethod("password", JavaType.STRING));
    builder.addMethod(getGetterMethod("accountNonExpired", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getSetterMethod("accountNonExpired", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getGetterMethod("accountNonLocked", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getSetterMethod("accountNonLocked", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getGetterMethod("credentialsNonExpired", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getSetterMethod("credentialsNonExpired", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getGetterMethod("enabled", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getSetterMethod("enabled", JAVA_TYPE_BOOLEAN));
    builder.addMethod(getGetterMethod("authorities", GRANTED_AUTHORITY));
    builder.addMethod(getSetterMethod("authorities", GRANTED_AUTHORITY));
    builder.addMethod(getGetterMethod("nombre", JavaType.STRING));
    builder.addMethod(getSetterMethod("nombre", JavaType.STRING));
    builder.addMethod(getGetterMethod("email", JavaType.STRING));
    builder.addMethod(getSetterMethod("email", JavaType.STRING));
    builder.addMethod(getGetterMethod("apellido1", JavaType.STRING));
    builder.addMethod(getSetterMethod("apellido1", JavaType.STRING));
    builder.addMethod(getGetterMethod("apellido2", JavaType.STRING));
    builder.addMethod(getSetterMethod("apellido2", JavaType.STRING));
    builder.addMethod(getGetterMethod("cif", JavaType.STRING));
    builder.addMethod(getSetterMethod("cif", JavaType.STRING));
    builder.addMethod(getGetterMethod("habilitado", JavaType.STRING));
    builder.addMethod(getSetterMethod("habilitado", JavaType.STRING));
    builder.addMethod(getGetterMethod("idHDFI", JavaType.STRING));
    builder.addMethod(getSetterMethod("idHDFI", JavaType.STRING));
    builder.addMethod(getGetterMethod("iusserDN", JavaType.STRING));
    builder.addMethod(getSetterMethod("iusserDN", JavaType.STRING));
    builder.addMethod(getGetterMethod("nif", JavaType.STRING));
    builder.addMethod(getSetterMethod("nif", JavaType.STRING));
    builder.addMethod(getGetterMethod("oid", JavaType.STRING));
    builder.addMethod(getSetterMethod("oid", JavaType.STRING));
    builder.addMethod(getGetterMethod("razonSocial", JavaType.STRING));
    builder.addMethod(getSetterMethod("razonSocial", JavaType.STRING));
    builder.addMethod(getGetterMethod("representante", JavaType.STRING));
    builder.addMethod(getSetterMethod("representante", JavaType.STRING));
    builder.addMethod(getGetterMethod("serialNumber", JavaType.STRING));
    builder.addMethod(getSetterMethod("serialNumber", JavaType.STRING));
    builder.addMethod(getGetterMethod("subjectDN", JavaType.STRING));
    builder.addMethod(getSetterMethod("subjectDN", JavaType.STRING));
    builder.addMethod(getGetterMethod("tipoAut", JavaType.STRING));
    builder.addMethod(getSetterMethod("tipoAut", JavaType.STRING));
    builder.addMethod(getGetterMethod("tipoCertificado", JavaType.STRING));
    builder.addMethod(getSetterMethod("tipoCertificado", JavaType.STRING));

    // Create a representation of the desired output ITD
    itdTypeDetails = builder.build();//from  www  . jav  a  2s .c o  m
}

From source file:de.micromata.tpsb.doc.parser.japa.ParserUtil.java

public static boolean ignoreMethod(FileInfo fi, MethodInfo mi) {
    if (TpsbEnvUtils.getAnnotation(fi, TpsbIgnore.class.getSimpleName()) != null) {
        return true;
    }/* ww w  . j a va 2 s .c om*/
    if (TpsbEnvUtils.getAnnotation(mi, TpsbIgnore.class.getSimpleName()) != null) {
        return true;
    }
    if ((mi.getModifier() & Modifier.STATIC) == Modifier.STATIC) {
        return true;
    }
    if ((mi.getModifier() & Modifier.PUBLIC) != Modifier.PUBLIC) {
        return true;
    }
    return false;
}