Example usage for java.lang.reflect Modifier isStatic

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

Introduction

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

Prototype

public static boolean isStatic(int mod) 

Source Link

Document

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

Usage

From source file:com.fluidops.iwb.api.ProviderServiceImpl.java

protected void collectUserObjects(Object config, List<User> users) throws IOException {
    if (config == null)
        return;/*from w  w  w .j av a  2 s.co m*/

    if (config instanceof User)
        users.add((User) config);

    for (Field f : config.getClass().getFields()) {
        if (Modifier.isTransient(f.getModifiers()))
            continue;
        if (Modifier.isStatic(f.getModifiers()))
            continue;

        try {
            Object kid = f.get(config);
            if (kid instanceof Object[])
                for (Object item : (Object[]) kid)
                    collectUserObjects(item, users);
            else if (kid instanceof Collection)
                for (Object item : (Collection) kid)
                    collectUserObjects(item, users);
            else
                collectUserObjects(kid, users);
        } catch (Exception e) {
            throw new IOException(
                    "Error saving config object. Could not check for User data. Make sure config objects are simple pojos with public fields",
                    e);
        }
    }
}

From source file:name.yumaa.ChromeLogger4J.java

/**
 * Returns a nicely formatted key of the field or method name
 * @param mod    .getModifiers()//from w  w w .  j  a  v  a 2  s  .c om
 * @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:org.teavm.flavour.json.emit.ClassInformationProvider.java

private void scanCreators(ClassInformation information, ReflectClass<?> cls) {
    ReflectMethod foundCreator = null;// w  w w .  j a v a 2s  .c o  m
    for (ReflectMethod method : cls.getDeclaredMethods()) {
        if (method.getAnnotation(JsonCreator.class) != null) {
            if (foundCreator != null) {
                diagnostics.error(new SourceLocation(foundCreator),
                        "Duplicate creators declared: " + "{{m0}} and {{m1}}", foundCreator, method);
                break;
            }
            foundCreator = method;
            if (!method.getName().equals("<init>") && Modifier.isStatic(method.getModifiers())) {
                diagnostics.error(new SourceLocation(method),
                        "Creator should be either constructor " + " or static: {{m0}}", method);
                continue;
            }
            information.constructor = method;
            for (int i = 0; i < method.getParameterCount(); ++i) {
                PropertyInformation property = addParameter(information, method, i,
                        method.getParameterAnnotations(i), method.getParameterType(i));
                information.constructorArgs.add(property);
            }
        }
    }
    if (information.constructor == null) {
        ReflectMethod defaultCtor = cls.getDeclaredMethod("<init>");
        if (defaultCtor != null) {
            information.constructor = defaultCtor;
        }
    }
}

From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java

protected boolean doSkip(Field field) {
    return Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())
            || Modifier.isFinal(field.getModifiers()) || Modifier.isProtected(field.getModifiers())
            || Modifier.isPrivate(field.getModifiers());
}

From source file:adalid.core.Operation.java

private void finaliseFields() {
    String name;//w w  w.j  a  va2 s.  c o  m
    Class<?> type;
    int modifiers;
    boolean restricted;
    Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class };
    Object o;
    int depth = depth();
    int round = round();
    for (Class<?> c : classes) {
        for (Field field : XS1.getFields(getClass(), Operation.class)) { // getClass().getDeclaredFields()
            field.setAccessible(true);
            logger.trace(field);
            name = field.getName();
            type = field.getType();
            if (!c.isAssignableFrom(type)) {
                continue;
            }
            modifiers = field.getModifiers();
            restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers);
            if (restricted) {
                continue;
            }
            String errmsg = "failed to initialize field \"" + field + "\" at " + this;
            try {
                o = field.get(this);
                if (o == null) {
                    logger.debug(message(type, name, o, depth, round));
                } else if (o instanceof Parameter) {
                    finaliseParameter(field, (Parameter) o);
                } else if (o instanceof Expression) {
                    finaliseExpression(field, (Expression) o);
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                logger.error(errmsg, ThrowableUtils.getCause(ex));
                TLC.getProject().getParser().increaseErrorCount();
            }
        }
    }
}

From source file:de.codesourcery.springmass.springmass.SimulationParamsBuilder.java

private boolean isPartOfPublicInterface(Method m) {
    final int mods = m.getModifiers();
    if (Modifier.isStatic(mods) || Modifier.isAbstract(mods) || Modifier.isNative(mods)
            || !Modifier.isPublic(mods)) {
        return false;
    }/*from w  w w.  ja va2s.  c om*/
    return true;
}

From source file:it.unibo.alchemist.language.protelis.util.ProtelisLoader.java

private static MethodCall parseMethod(final JvmOperation jvmOp, final List<Expression> args,
        final Map<FasterString, FunctionDefinition> nameToFun,
        final Map<FunctionDef, FunctionDefinition> funToFun, final AtomicInteger id) {
    final boolean ztatic = jvmOp.isStatic();
    final List<AnnotatedTree<?>> arguments = parseArgs(args, nameToFun, funToFun, id);
    final String classname = jvmOp.getDeclaringType().getQualifiedName();
    try {/*from   ww w . j  ava 2s  . c om*/
        final Class<?> clazz = Class.forName(classname);
        /*
         * TODO: Check for return type and params: if param is Field and
         * return type is not then L.warn()
         */
        List<Method> tempList = new ArrayList<>();
        for (Method m : clazz.getMethods()) {
            if (ztatic) {
                if (Modifier.isStatic(m.getModifiers())) {
                    tempList.add(m);
                }
            }
        }
        /*
         * Same number of arguments
         */
        final int parameterCount = jvmOp.getParameters().size();
        List<Method> tempList2 = new ArrayList<>();
        for (Method m : tempList) {
            // TODO: Workaround for different Method API
            if (m.getParameterTypes().length == parameterCount) {
                tempList2.add(m);
            }
        }
        /*
         * Same name
         */
        final String methodName = jvmOp.getSimpleName();
        List<Method> res = new ArrayList<>();
        for (Method m : tempList2) {
            if (m.getName().equals(methodName)) {
                res.add(m);
            }
        }
        /*
         * There should be only one left - otherwise we have overloading,
         * and to properly deal with that we need type checking. The
         * following collection operation is for debug and warning purposes,
         * and should be removed as soon as we have a proper way to deal
         * with overloading in place. TODO
         */
        if (res.size() > 1) {
            final StringBuilder sb = new StringBuilder(64);
            sb.append("Method ");
            sb.append(jvmOp.getQualifiedName());
            sb.append('/');
            sb.append(parameterCount);
            sb.append(" is overloaded by:\n");
            for (Method m : res) {
                sb.append(m.toString());
                sb.append('\n'); // NOPMD
            }
            sb.append("Protelis can not (yet) properly deal with that.");
            L.warn(sb.toString());
        }
        if (res.isEmpty()) {
            throw new IllegalStateException("Can not bind any method that satisfies the name "
                    + jvmOp.getQualifiedName() + "/" + parameterCount + ".");
        }
        return new MethodCall(res.get(0), arguments, ztatic);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Class " + classname + " could not be found in classpath.");
    } catch (SecurityException e) {
        throw new IllegalStateException(
                "Class " + classname + " could not be loaded due to security permissions.");
    } catch (Error e) {
        throw new IllegalStateException("An error occured while loading class " + classname + ".");
    }

}

From source file:ch.flashcard.HibernateDetachUtility.java

private static void nullOutFieldsByFieldAccess(Object object, Map<Integer, Object> checkedObjects,
        Map<Integer, List<Object>> checkedObjectCollisionMap, int depth, SerializationType serializationType)
        throws Exception {

    Class tmpClass = object.getClass();
    List<Field> fieldsToClean = new ArrayList<Field>();
    while (tmpClass != null && tmpClass != Object.class) {
        Field[] declaredFields = tmpClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            // do not process static final or transient fields since they won't be serialized anyway
            int modifiers = declaredField.getModifiers();
            if (!((Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers))
                    || Modifier.isTransient(modifiers))) {
                fieldsToClean.add(declaredField);
            }//from www  .j ava  2  s . co  m
        }
        tmpClass = tmpClass.getSuperclass();
    }

    nullOutFieldsByFieldAccess(object, fieldsToClean, checkedObjects, checkedObjectCollisionMap, depth,
            serializationType);
}

From source file:net.minecraftforge.fml.common.FMLModContainer.java

private void parseSimpleFieldAnnotation(SetMultimap<String, ASMData> annotations, String annotationClassName,
        Function<ModContainer, Object> retriever) throws IllegalAccessException {
    String[] annName = annotationClassName.split("\\.");
    String annotationName = annName[annName.length - 1];
    for (ASMData targets : annotations.get(annotationClassName)) {
        String targetMod = (String) targets.getAnnotationInfo().get("value");
        Field f = null;//from  ww w. j a v  a2s.c o  m
        Object injectedMod = null;
        ModContainer mc = this;
        boolean isStatic = false;
        Class<?> clz = modInstance.getClass();
        if (!Strings.isNullOrEmpty(targetMod)) {
            if (Loader.isModLoaded(targetMod)) {
                mc = Loader.instance().getIndexedModList().get(targetMod);
            } else {
                mc = null;
            }
        }
        if (mc != null) {
            try {
                clz = Class.forName(targets.getClassName(), true, Loader.instance().getModClassLoader());
                f = clz.getDeclaredField(targets.getObjectName());
                f.setAccessible(true);
                isStatic = Modifier.isStatic(f.getModifiers());
                injectedMod = retriever.apply(mc);
            } catch (Exception e) {
                Throwables.propagateIfPossible(e);
                FMLLog.log(getModId(), Level.WARN, e, "Attempting to load @%s in class %s for %s and failing",
                        annotationName, targets.getClassName(), mc.getModId());
            }
        }
        if (f != null) {
            Object target = null;
            if (!isStatic) {
                target = modInstance;
                if (!modInstance.getClass().equals(clz)) {
                    FMLLog.log(getModId(), Level.WARN,
                            "Unable to inject @%s in non-static field %s.%s for %s as it is NOT the primary mod instance",
                            annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId());
                    continue;
                }
            }
            f.set(target, injectedMod);
        }
    }
}

From source file:com.microsoft.tfs.core.clients.build.internal.soapextensions.BuildEnumerationHelper.java

@SuppressWarnings("rawtypes")
public static String[] getDisplayTextValues(final Class enumType) {
    final List<String> displayValues = new ArrayList<String>();

    // Look for public static final fields in class that are same type as
    // the passed class.
    final Field[] fields = enumType.getFields();
    for (int i = 0; i < fields.length; i++) {
        if (fields[i].getType().equals(enumType) && Modifier.isPublic(fields[i].getModifiers())
                && Modifier.isFinal(fields[i].getModifiers()) && Modifier.isStatic(fields[i].getModifiers())) {
            try {
                displayValues.add(getDisplayText(fields[i].get(null)));
            } catch (final IllegalAccessException e) {
                throw new BuildException(
                        MessageFormat.format("IllegalAccessException calculating display values for {0}", //$NON-NLS-1$
                                enumType.getName()),
                        e);//from   w  ww.j  a  v a  2  s.  c o  m
            }
        }
    }
    return displayValues.toArray(new String[displayValues.size()]);
}