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.genome.tpsb.CommonTestBuilder.java

/**
 * Copy this to test context./*from   w  w w  .  j  a  v  a  2 s  .  c o m*/
 */
@TpsbIgnore
protected void copyThisToTestContext() {
    testContext.putAll(PrivateBeanUtils.getAllFields(this, 0, Modifier.STATIC | Modifier.TRANSIENT));
    testContext.put("builder", this);
}

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

@Test
public void defaultAccessMethodsWithStaticNativeOnly() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withAccess(AccessType.DEFAULT);
    memberCriteria.withModifiers(Modifier.STATIC | Modifier.NATIVE);
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        int modifiers = member.getModifiers();
        assertFalse(Modifier.isPublic(modifiers));
        assertFalse(Modifier.isProtected(modifiers));
        assertFalse(Modifier.isPrivate(modifiers));
        assertTrue(Modifier.isStatic(modifiers));
        assertTrue(Modifier.isNative(modifiers));
    }//from w  w  w  .  jav  a2  s. c o  m
}

From source file:com.serli.chell.framework.form.FormStructure.java

private static boolean isFormField(Field field, Class<?> fieldType) {
    return ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0) && (fieldType.equals(String.class)
            || fieldType.equals(String[].class) && !field.isAnnotationPresent(HtmlTransient.class));
}

From source file:info.raack.appliancedetection.evaluation.web.EvaluationController.java

@RequestMapping(value = "/evaluationgroup/{id}", method = RequestMethod.GET)
public void getEvaluationGroupData(@PathVariable("id") int simulationGroupId, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

    EvaluationGroup evaluationGroup = simulationService.getEvaluationGroup(simulationGroupId);

    if (evaluationGroup == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;/*from w  w w .j a  v a 2  s  .  co m*/
    }

    String dataJS = new GsonBuilder().excludeFieldsWithModifiers(Modifier.STATIC)
            .setExclusionStrategies(new ExclusionStrategy() {

                // skip logger
                public boolean shouldSkipClass(Class<?> clazz) {
                    return clazz.equals(Logger.class);
                }

                public boolean shouldSkipField(FieldAttributes fieldAttributes) {
                    // skip everything in evaluation except overallEnergyError or simulation
                    return (!(fieldAttributes.getName().equals("stateTransitionPrecision")
                            || fieldAttributes.getName().equals("stateTransitionRecall")
                            || fieldAttributes.getName().equals("stateTransitionAccuracy")
                            || fieldAttributes.getName().equals("overallAccuracy")
                            || fieldAttributes.getName().equals("overallEnergyError")
                            || fieldAttributes.getName().equals("simulation"))
                            && fieldAttributes.getDeclaringClass() == Evaluation.class) ||
                    // skip everything in simulation except id and durationInSeconds
                    (!(fieldAttributes.getName().equals("id")
                            || fieldAttributes.getName().equals("durationInSeconds"))
                            && fieldAttributes.getDeclaringClass() == Simulation.class);
                }
            }).create().toJson(evaluationGroup);

    response.getWriter().write(dataJS);
    response.setContentType("application/json");
}

From source file:org.structr.core.entity.SchemaMethod.java

private boolean getSignature(final Class type, final String methodName, final ActionEntry entry) {

    // superclass is AbstractNode
    for (final Method method : type.getMethods()) {

        if (methodName.equals(method.getName()) && (method.getModifiers() & Modifier.STATIC) == 0) {

            final Type[] parameterTypes = method.getGenericParameterTypes();
            final Type returnType = method.getGenericReturnType();
            final List<Type> types = new LinkedList<>();

            // compile list of types to check for generic type parameter
            types.addAll(Arrays.asList(parameterTypes));
            types.add(returnType);/*  w  w  w  . j  av  a 2  s  . c o m*/

            final String genericTypeParameter = getGenericMethodParameter(types, method);

            // check for generic return type, and if the method defines its own generic type
            if (returnType instanceof TypeVariable
                    && ((TypeVariable) returnType).getGenericDeclaration().equals(method)) {

                // method defines its own generic type
                entry.setReturnType(genericTypeParameter + returnType.getTypeName());

            } else {

                // non-generic return type
                final Class returnClass = method.getReturnType();
                if (returnClass.isArray()) {

                    entry.setReturnType(genericTypeParameter + returnClass.getComponentType().getName() + "[]");

                } else {

                    entry.setReturnType(genericTypeParameter + method.getReturnType().getName());
                }
            }

            for (final Parameter parameter : method.getParameters()) {

                String typeName = parameter.getParameterizedType().getTypeName();
                String name = parameter.getType().getSimpleName();

                if (typeName.contains("$")) {
                    typeName = typeName.replace("$", ".");
                }

                entry.addParameter(typeName, parameter.getName());
            }

            for (final Class exception : method.getExceptionTypes()) {
                entry.addException(exception.getName());
            }

            entry.setOverrides(getProperty(overridesExisting));
            entry.setCallSuper(getProperty(callSuper));

            // success
            return true;
        }
    }

    return false;
}

From source file:org.kuali.rice.krad.uif.util.CloneUtils.java

public static Field[] getFields(Class<?> c, boolean includeStatic, boolean includeTransient) {
    String cacheKey = c.getName() + ":" + includeStatic;
    Field[] array = fieldCache.get(cacheKey);

    if (array == null) {
        ArrayList<Field> fields = new ArrayList<Field>();

        List<Class<?>> classes = getClassHierarchy(c, false);

        // Reverse order so we make sure we maintain consistent order
        Collections.reverse(classes);

        for (Class<?> clazz : classes) {
            Field[] allFields = clazz.getDeclaredFields();
            for (Field f : allFields) {
                if ((!includeTransient) && ((f.getModifiers() & Modifier.TRANSIENT) == Modifier.TRANSIENT)) {
                    continue;
                } else if (f.isSynthetic()) {
                    // Synthetic fields are bad!!!
                    continue;
                }//  www.ja  va  2  s  .  c  o  m
                boolean isStatic = (f.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
                if ((isStatic) && (!includeStatic)) {
                    continue;
                }
                if (f.getName().equalsIgnoreCase("serialVersionUID")) {
                    continue;
                }
                f.setAccessible(true);
                fields.add(f);
            }
        }

        array = fields.toArray(new Field[fields.size()]);
        fieldCache.put(cacheKey, array);
    }
    return array;
}

From source file:org.codehaus.groovy.grails.compiler.injection.test.TestMixinTransformation.java

protected FieldNode addTestRuleMixinFieldIfNonExistent(ClassNode classNode, ClassNode fieldType,
        String fieldName, boolean implementsClassRuleFactory, boolean implementsRuleFactory) {
    if (classNode != null && classNode.getField(fieldName) == null) {
        FieldNode mixinInstanceFieldNode = classNode.addField(fieldName,
                Modifier.PRIVATE | (implementsClassRuleFactory ? Modifier.STATIC : 0), fieldType,
                new ConstructorCallExpression(fieldType, MethodCallExpression.NO_ARGUMENTS));

        String ruleFieldNameBase = fieldName;

        boolean spockTest = isSpockTest(classNode);
        if (implementsClassRuleFactory) {
            FieldNode staticRuleFieldNode = classNode.addField(ruleFieldNameBase + "StaticClassRule",
                    Modifier.PRIVATE | Modifier.STATIC, ClassHelper.make(TestRule.class),
                    new MethodCallExpression(new FieldExpression(mixinInstanceFieldNode), "newClassRule",
                            new ClassExpression(classNode)));
            AnnotationNode classRuleAnnotation = new AnnotationNode(ClassHelper.make(ClassRule.class));
            if (spockTest) {
                // @ClassRule must be added to @Shared field in spock
                FieldNode spockSharedRuleFieldNode = classNode.addField(ruleFieldNameBase + "SharedClassRule",
                        Modifier.PUBLIC, ClassHelper.make(TestRule.class),
                        new FieldExpression(staticRuleFieldNode));
                spockSharedRuleFieldNode.addAnnotation(classRuleAnnotation);
                spockSharedRuleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Shared.class)));
                if (spockTest) {
                    addSpockFieldMetadata(spockSharedRuleFieldNode, 0);
                }//from   w ww  .  j  a v  a  2s .c o m
            } else {
                staticRuleFieldNode.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
                staticRuleFieldNode.addAnnotation(classRuleAnnotation);
            }
        }
        if (implementsRuleFactory) {
            FieldNode ruleFieldNode = classNode.addField(ruleFieldNameBase + "Rule", Modifier.PUBLIC,
                    ClassHelper.make(TestRule.class),
                    new MethodCallExpression(new FieldExpression(mixinInstanceFieldNode), "newRule",
                            new VariableExpression("this")));
            ruleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Rule.class)));
            if (spockTest) {
                addSpockFieldMetadata(ruleFieldNode, 0);
            }
        }
        return mixinInstanceFieldNode;
    }
    return null;
}

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

/**
 * Validates methods of the class.//  w w w .  ja  va  2 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:org.gvnix.addon.jpa.addon.geo.providers.hibernatespatial.GvNIXEntityMapLayerMetadata.java

/**
 * Create a method to filter by a single geometry field
 * /*from w  ww. j  av a2 s . c  om*/
 * @param entity
 * @param finder
 * @param plural
 * @param geoFieldNames
 * @return
 */
private MethodMetadata getfindAllTheEntityByGeomFilter(JavaType entity, String finder, String plural,
        Map<JavaSymbolName, AnnotationAttributeValue<Integer>> geoFields) {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    // Adding parameter types
    parameterTypes.add(AnnotatedJavaType
            .convertFromJavaType(new JavaType("org.gvnix.jpa.geo.hibernatespatial.util.GeometryFilter")));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(
            new JavaType("java.lang.Class", 0, DataType.TYPE, null, Arrays.asList(new JavaType("T")))));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(new JavaType(MAP.getFullyQualifiedTypeName(), 0,
            DataType.TYPE, null, Arrays.asList(JavaType.STRING, JavaType.OBJECT))));

    // Getting method name
    JavaSymbolName methodName = new JavaSymbolName(
            String.format("findAll%sBy%s", plural, StringUtils.capitalize(finder)));

    // Check if a method with the same signature already exists in the
    // target type

    final MethodMetadata method = methodExists(methodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

    // Define method annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();

    parameterNames.add(new JavaSymbolName("geomFilter"));
    parameterNames.add(new JavaSymbolName("klass"));
    parameterNames.add(new JavaSymbolName("hints"));

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildfindAllTheEntityByGeomFilterMethodBody(entity, plural, finder, bodyBuilder, geoFields);

    // Return type
    JavaType responseEntityJavaType = new JavaType("java.util.List", 0, DataType.TYPE, null,
            Arrays.asList(new JavaType("T")));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC,
            methodName, responseEntityJavaType, parameterTypes, parameterNames, bodyBuilder);

    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);
    methodBuilder.setGenericDefinition("T");

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:com.izforge.izpack.util.SelfModifier.java

/**
 * Check the method for the required properties (public, static, params:(String[])).
 *
 * @param method the method//www  .  j av a 2s  . c  o  m
 * @throws NullPointerException     if <code>method</code> is null
 * @throws IllegalArgumentException if <code>method</code> is not public, static, and take a
 *                                  String array as it's only argument, or of it's declaring class is not public.
 * @throws SecurityException        if access to the method is denied
 */
private void initMethod(Method method) {
    int mod = method.getModifiers();
    if ((mod & Modifier.PUBLIC) == 0 || (mod & Modifier.STATIC) == 0) {
        throw new IllegalArgumentException("Method not public and static");
    }

    Class[] params = method.getParameterTypes();
    if (params.length != 1 || !params[0].isArray()
            || !"java.lang.String".equals(params[0].getComponentType().getName())) {
        throw new IllegalArgumentException("Method must accept String array");
    }

    Class clazz = method.getDeclaringClass();
    mod = clazz.getModifiers();
    if ((mod & Modifier.PUBLIC) == 0 || (mod & Modifier.INTERFACE) != 0) {
        throw new IllegalArgumentException("Method must be in a public class");
    }

    this.method = method;
}