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.microsoft.tfs.client.common.ui.framework.layout.GridDataBuilder.java

/**
 * Performs a copy operation on the specified {@link GridData}, returning a
 * new {@link GridData} instance that has all fields set to the same value
 * as the input {@link GridData}./*w  ww.jav  a  2s.co  m*/
 *
 * @param in
 *        an input {@link GridData} (must not be <code>null</code>)
 * @return a copy of the input
 */
private static GridData copy(final GridData in) {
    final GridData out = new GridData();

    /*
     * The copy is done reflectively instead of directly. The GridData class
     * has added lots of fields in different versions of Eclipse since 3.0 -
     * this is the easiest way to get compatibility with all those versions.
     */

    /*
     * PERF: consider caching the final Field[] array.
     */

    final Field[] fields = GridData.class.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        if (Modifier.isStatic(fields[i].getModifiers()) || Modifier.isFinal(fields[i].getModifiers())) {
            /*
             * skip static and final fields
             */
            continue;
        }

        fields[i].setAccessible(true);
        try {
            final Object valueToCopy = fields[i].get(in);
            fields[i].set(out, valueToCopy);
        } catch (final IllegalArgumentException e) {
            final String messageFormat = "field [{0}]: {1}"; //$NON-NLS-1$
            final String message = MessageFormat.format(messageFormat, fields[i].getName(), e.getMessage());
            throw new RuntimeException(message, e);
        } catch (final IllegalAccessException e) {
            final String messageFormat = "field [{0}]: {1}"; //$NON-NLS-1$
            final String message = MessageFormat.format(messageFormat, fields[i].getName(), e.getMessage());
            throw new RuntimeException(message, e);
        }
    }

    return out;
}

From source file:com.yiji.openapi.sdk.util.Reflections.java

public static Set<String> getFieldNames(Class<?> pojoClass) {
    Set<String> propertyNames = new HashSet<String>();
    Class<?> clazz = pojoClass;
    do {//from  ww w  .  j av  a 2 s.c o m
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (!Modifier.isStatic(field.getModifiers())) {
                propertyNames.add(field.getName());

            }
        }
        clazz = clazz.getSuperclass();
    } while (clazz != null && !clazz.getSimpleName().equalsIgnoreCase("Object"));
    return propertyNames;
}

From source file:com.unovo.frame.utils.SharedPreferencesHelper.java

private static boolean isContSupport(Field field) {
    return (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())
            || Modifier.isAbstract(field.getModifiers()));
}

From source file:org.apache.openaz.xacml.std.json.JSONRequest.java

/**
 * Use reflection to load the map with all the names of all DataTypes, both the long name and the
 * shorthand, and point each name to the appropriate Identifier. The shorthand map is used differently in
 * JSONRequest than in JSONResponse, so there are similarities and differences in the implementation. This
 * is done once the first time a Request is processed.
 *//*from   w w w  .  j av  a 2s.  co  m*/
private static void initShorthandMap() throws JSONStructureException {
    Field[] declaredFields = XACML3.class.getDeclaredFields();
    shorthandMap = new HashMap<String, Identifier>();
    for (Field field : declaredFields) {
        if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith("ID_DATATYPE")
                && Modifier.isPublic(field.getModifiers())) {
            try {
                Identifier id = (Identifier) field.get(null);
                String longName = id.stringValue();
                // most names start with 'http://www.w3.org/2001/XMLSchema#'
                int sharpIndex = longName.lastIndexOf("#");
                if (sharpIndex <= 0) {
                    // some names start with 'urn:oasis:names:tc:xacml:1.0:data-type:'
                    // or urn:oasis:names:tc:xacml:2.0:data-type:
                    if (longName.contains(":data-type:")) {
                        sharpIndex = longName.lastIndexOf(":");
                    } else {
                        continue;
                    }
                }
                String shortName = longName.substring(sharpIndex + 1);
                // put both the full name and the short name in the table
                shorthandMap.put(longName, id);
                shorthandMap.put(shortName, id);
            } catch (Exception e) {
                throw new JSONStructureException("Error loading ID Table, e=" + e);
            }
        }
    }
}

From source file:gumga.framework.presentation.api.CSVGeneratorAPI.java

public static List<Field> getAllAtributes(Class clazz) {
    List<Field> fields = new ArrayList<>();
    Class superClass = clazz.getSuperclass();
    if (superClass != null && !superClass.equals(Object.class)) {
        fields.addAll(getAllAtributes(clazz.getSuperclass()));
    }/*w  w w  .  ja  v a 2 s  .  c o  m*/
    for (Field f : clazz.getDeclaredFields()) {
        if (!Modifier.isStatic(f.getModifiers())) {
            fields.add(f);
        }
    }
    return fields;
}

From source file:org.teavm.flavour.json.emit.ClassInformationProvider.java

private void scanGetters(ClassInformation information, ReflectClass<?> cls) {
    for (ReflectMethod method : cls.getDeclaredMethods()) {
        if (Modifier.isStatic(method.getModifiers())) {
            continue;
        }/*w w w.j av a 2s .c  om*/
        if (isGetterName(method.getName()) && method.getParameterCount() == 0
                && method.getReturnType() != context.findClass(void.class)) {
            if (hasExplicitPropertyDeclaration(method)
                    || information.getterVisibility.match(method.getModifiers())) {
                String propertyName = decapitalize(method.getName().substring(3));
                addGetter(information, propertyName, method);
            }
        } else if (isBooleanName(method.getName()) && method.getParameterCount() == 0
                && method.getReturnType() == context.findClass(boolean.class)) {
            if (hasExplicitPropertyDeclaration(method)
                    || information.isGetterVisibility.match(method.getModifiers())) {
                String propertyName = decapitalize(method.getName().substring(2));
                addGetter(information, propertyName, method);
            }
        }
    }
}

From source file:com.jwebmp.core.htmlbuilder.javascript.JavaScriptPart.java

/**
 * Renders the fields (getDeclaredFields()) as a map of html attributes
 *
 * @return//from   ww  w .j  a  v a2  s  .  co m
 */
public Map<String, String> toAttributes() {
    Map<String, String> map = new LinkedHashMap<>();

    Field[] fields = getClass().getDeclaredFields();
    for (Field field : fields) {
        if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        field.setAccessible(true);
        try {
            Object result = field.get(this);
            if (result != null) {
                if (JavaScriptPart.class.isAssignableFrom(result.getClass())) {
                    map.put(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, field.getName()),
                            ((JavaScriptPart) result).toString(true));
                } else {
                    map.put(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, field.getName()),
                            result.toString());
                }
            }
        } catch (Exception e) {
            JavaScriptPart.log.log(Level.WARNING, "Cant format as attributes", e);
        }
    }
    return map;
}

From source file:lapin.load.Loader.java

static private Object _impSubrs(Object pkgname, Class clazz, Symbol indicator, Object export, Env env)
        throws IllegalAccessException {
    Lisp lisp = env.lisp();//ww w.j av  a 2 s  .co  m
    Field[] fields = clazz.getFields();
    Class subrClass = Subr.class;
    for (int i = 0; i < fields.length; i++) {
        Field f = fields[i];
        int m = f.getModifiers();
        if (!Modifier.isStatic(m))
            continue;
        if (!subrClass.isAssignableFrom(f.getType()))
            continue;
        Subr subr = Data.subr(f.get(null));
        Symbol sym = Data.symbol(lisp.getObarray().intern(pkgname, subr.name()).nth(0));
        if (!Data.isNot(export))
            lisp.getObarray().exp(pkgname, sym);
        Object old = lisp.getProp(sym, indicator, Symbols.NIL);
        if (!Data.isNot(old))
            throw new LispException(
                    "conflict detected while importing subrs " + "defined in ~S: name=~S indicator=~S",
                    Lists.list(clazz, sym, indicator));
        lisp.setProp(sym, indicator, subr);
        if (subr instanceof Prop)
            lisp.setProp((Prop) subr, SysSymbols.SUBR_FIELD, f);
    }
    return Symbols.T;
}