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:com.comphenix.protocol.wrappers.WrappedDataWatcher.java

@SuppressWarnings("unchecked")
private Map<Integer, Object> getMap() {
    if (MAP_FIELD == null) {
        FuzzyReflection fuzzy = FuzzyReflection.fromClass(handleType, true);
        MAP_FIELD = Accessors.getFieldAccessor(fuzzy.getField(
                FuzzyFieldContract.newBuilder().banModifier(Modifier.STATIC).typeDerivedOf(Map.class).build()));
    }/*w  ww  .  ja  v  a2 s . c  om*/

    if (MAP_FIELD == null) {
        throw new FieldAccessException("Could not find index <-> Item map.");
    }

    return (Map<Integer, Object>) MAP_FIELD.get(handle);
}

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

/**
 * Checks if the methods is a test method ==&gt; Either starts with test or has an annotation @Test
 * //w ww  .  jav a 2  s .  c  o m
 * @param n the methoddeclaration which is to test if it is a test
 * @return true if it is a test method TODO consider check if the test method is void, etc and with no args?
 */
protected boolean isTest(MethodDeclaration n) {
    if ((n.getModifiers() & Modifier.PUBLIC) != Modifier.PUBLIC) {
        return false;
    }
    if ((n.getModifiers() & Modifier.STATIC) == Modifier.STATIC) {
        return false;
    }
    if (n.getName().startsWith("test")) {
        return true;
    }
    if (n.getAnnotations() == null) {
        return false;
    }

    for (AnnotationExpr ae : n.getAnnotations()) {
        if (ae.getName().getName().equals("Test")) {
            return true;
        }
        if (ae.getName().getName().equals("TpsbMetaMethod") == true) {
            return true;
        }
    }

    return false;
}

From source file:org.xmlsh.util.JavaUtils.java

public static Method getBestMatch(Method[] methods, String methodName, List<XValue> args, boolean bStatic)
        throws CoreException {

    Method best = null;//ww w . j  a  v a  2  s  .co  m
    int bestConversions = 0;

    for (Method m : methods) {
        int conversions = 0;
        if (m.getName().equals(methodName)) {
            boolean isStatic = (m.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
            if (bStatic && !isStatic)
                continue;

            Class<?>[] params = m.getParameterTypes();
            if (params.length == args.size()) {
                int i = 0;
                for (XValue arg : args) {
                    int conversion = arg.canConvert(params[i]);
                    if (conversion < 0)
                        break;
                    i++;
                    conversions += conversion;
                }
                if (i == params.length) {

                    if (best == null || conversions < bestConversions) {
                        best = m;
                        bestConversions = conversions;
                    }
                }

            }

        }

    }
    return best;

}

From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditUserServiceMetadata.java

/**
 * @return the getUserName method definition
 *//*from  w w  w . j  av a2 s. c  o  m*/
private MethodMetadata getUserMethod() {
    // method name
    JavaSymbolName methodName = GET_USER_METHOD;

    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    // Check if a method exist in type
    final MethodMetadata method = helper.methodExists(methodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

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

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

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildGetUserMethodBody(bodyBuilder);

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

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

From source file:org.agiso.core.lang.util.ObjectUtils.java

/**
 * Metoda generujca reprezentacj acuchow obiektu. Przeglda wszystkie
 * pola obiektu i pobiera ich reprezentacj acuchow. Na tej podstawie
 * generuje acuch wynikowy./*from   w  ww.  j  a  va 2 s.  c  om*/
 * 
 * @param clazz
 * @param object
 */
private static void toStringObject(Class<?> clazz, Object object) {
    StringBuffer buffer = (StringBuffer) ThreadUtils.getAttribute(TOSTRING_TCBUFF);

    String hexHash = Integer.toHexString(System.identityHashCode(object));
    if (0 == buffer.length()) {
        buffer.append(clazz.getSimpleName()).append('@').append(hexHash).append(TOSTRING_PREFIX);
    }

    @SuppressWarnings("unchecked")
    Set<String> converted = (Set<String>) ThreadUtils.getAttribute(TOSTRING_TCATTR);
    converted.add(object.getClass().getCanonicalName() + "@" + hexHash);

    // Rekurencyjne przegldanie wszystkich klas nadrzdnych:
    Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        toStringObject(superClass, object);
    }

    String hyphen = "";
    if (TOSTRING_PREFIX.charAt(0) != buffer.charAt(buffer.length() - 1)) {
        hyphen = TOSTRING_HYPHEN;
    }

    for (Field field : clazz.getDeclaredFields()) {
        try {
            field.setAccessible(true);
            if (field.isAnnotationPresent(InToString.class)) {
                InToString inToString = field.getAnnotation(InToString.class);
                if (!inToString.ignore()) {
                    String name = inToString.name();
                    buffer.append(hyphen).append((name.length() > 0) ? name : field.getName())
                            .append(TOSTRING_COLON);
                    toStringField(field.get(object));
                    hyphen = TOSTRING_HYPHEN;
                }
            } else if ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0) {
                buffer.append(hyphen).append(field.getName()).append(TOSTRING_COLON);
                toStringField(field.get(object));
                hyphen = TOSTRING_HYPHEN;
            }
        } catch (Exception e) {
            // TODO: Zaimplementowa logowanie wyjtku
            e.printStackTrace();
        }
    }
}

From source file:de.matzefratze123.heavyspleef.core.flag.FlagRegistry.java

public void registerFlag(Class<? extends AbstractFlag<?>> clazz) {
    Validate.notNull(clazz, "clazz cannot be null");
    Validate.isTrue(!registeredFlagsMap.containsValue(clazz), "Cannot register flag twice");

    /* Check if the class provides the required Flag annotation */
    Validate.isTrue(clazz.isAnnotationPresent(Flag.class),
            "Flag-Class must be annotated with the @Flag annotation");

    Flag flagAnnotation = clazz.getAnnotation(Flag.class);
    String name = flagAnnotation.name();

    Validate.isTrue(!name.isEmpty(),/* w  w  w  . ja  v  a 2s  . c  o  m*/
            "name() of annotation of flag for class " + clazz.getCanonicalName() + " cannot be empty");

    /* Generate a path */
    StringBuilder pathBuilder = new StringBuilder();
    Flag parentFlagData = flagAnnotation;

    do {
        pathBuilder.insert(0, parentFlagData.name());

        Class<? extends AbstractFlag<?>> parentFlagClass = parentFlagData.parent();
        parentFlagData = parentFlagClass.getAnnotation(Flag.class);

        if (parentFlagData != null && parentFlagClass != NullFlag.class) {
            pathBuilder.insert(0, FLAG_PATH_SEPERATOR);
        }
    } while (parentFlagData != null);

    String path = pathBuilder.toString();

    /* Check for name collides */
    for (String flagPath : registeredFlagsMap.primaryKeySet()) {
        if (flagPath.equalsIgnoreCase(path)) {
            throw new IllegalArgumentException(
                    "Flag " + clazz.getName() + " collides with " + registeredFlagsMap.get(flagPath).getName());
        }
    }

    /* Check if the class can be instantiated */
    try {
        Constructor<? extends AbstractFlag<?>> constructor = clazz.getDeclaredConstructor();

        //Make the constructor accessible for future uses
        constructor.setAccessible(true);
    } catch (NoSuchMethodException | SecurityException e) {
        throw new IllegalArgumentException("Flag-Class must provide an empty constructor");
    }

    HookManager hookManager = heavySpleef.getHookManager();
    boolean allHooksPresent = true;
    for (HookReference ref : flagAnnotation.depend()) {
        if (!hookManager.getHook(ref).isProvided()) {
            allHooksPresent = false;
        }
    }

    if (allHooksPresent) {
        for (Method method : clazz.getDeclaredMethods()) {
            if (!method.isAnnotationPresent(FlagInit.class)) {
                continue;
            }

            if ((method.getModifiers() & Modifier.STATIC) == 0) {
                throw new IllegalArgumentException("Flag initialization method " + method.getName()
                        + " in type " + clazz.getCanonicalName() + " is not declared as static");
            }

            queuedInitMethods.add(method);
        }

        if (flagAnnotation.hasCommands()) {
            CommandManager manager = heavySpleef.getCommandManager();
            manager.registerSpleefCommands(clazz);
        }
    }

    registeredFlagsMap.put(path, flagAnnotation, clazz);
}

From source file:org.exem.flamingo.shared.util.el.ELServiceImpl.java

public static Method findMethod(String className, String methodName) throws ServiceException {
    Method method = null;//  www .java2 s .com
    try {
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
        for (Method m : clazz.getMethods()) {
            if (m.getName().equals(methodName)) {
                method = m;
                break;
            }
        }
        if (method == null) {
            // throw new ServiceException(ErrorCode.E0111, className, methodName);
        }
        if ((method.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) != (Modifier.PUBLIC
                | Modifier.STATIC)) {
            // throw new ServiceException(ErrorCode.E0112, className, methodName);
        }
    } catch (ClassNotFoundException ex) {
        // throw new ServiceException(ErrorCode.E0113, className);
    }
    return method;
}

From source file:org.openflamingo.uploader.el.ELService.java

public static Method findMethod(String className, String methodName) throws SystemException {
    Method method = null;// w  w w . j ava 2 s.  com
    try {
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
        for (Method m : clazz.getMethods()) {
            if (m.getName().equals(methodName)) {
                method = m;
                break;
            }
        }
        if (method == null) {
            // throw new SystemException(ErrorCode.E0111, className, methodName);
        }
        if ((method.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) != (Modifier.PUBLIC
                | Modifier.STATIC)) {
            // throw new SystemException(ErrorCode.E0112, className, methodName);
        }
    } catch (ClassNotFoundException ex) {
        // throw new SystemException(ErrorCode.E0113, className);
    }
    return method;
}

From source file:org.exem.flamingo.shared.util.el.ELServiceImpl.java

public static Object findConstant(String className, String constantName) throws ServiceException {
    try {// w ww.  jav  a2 s . c  o m
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
        Field field = clazz.getField(constantName);
        if ((field.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) != (Modifier.PUBLIC
                | Modifier.STATIC)) {
            // throw new ServiceException(ErrorCode.E0114, className, constantName);
        }
        return field.get(null);
    } catch (Exception ex) {
        throw new ServiceException(ex);
    }
}

From source file:org.gvnix.addon.jpa.addon.geo.providers.hibernatespatial.GvNIXEntityMapLayerMetadata.java

/**
 * Create a method to filter by two or more geometry fields from an entity
 * /*  ww  w . j  av  a2s . com*/
 * @param entity
 * @param finders
 * @param plural
 * @param geoFieldNames
 * @return
 */
private MethodMetadata getfindAllTheEntityByFilters(JavaType entity, String finders[], 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
    StringBuilder methodNameBuilder = new StringBuilder(String.format("findAll%sBy", plural));
    for (String field : finders) {
        methodNameBuilder.append(StringUtils.capitalize(field).concat("Or"));
    }
    JavaSymbolName methodName = new JavaSymbolName(
            methodNameBuilder.substring(0, methodNameBuilder.length() - 2));

    // 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();
    buildfindAllTheEntityByGeoFiltersMethodBody(entity, plural, finders, 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
}