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:org.apache.syncope.client.console.panels.RelationshipTypesPanel.java

@Override
protected List<IColumn<RelationshipTypeTO, String>> getColumns() {

    final List<IColumn<RelationshipTypeTO, String>> columns = new ArrayList<>();

    for (Field field : RelationshipTypeTO.class.getDeclaredFields()) {
        if (field != null && !Modifier.isStatic(field.getModifiers())) {
            final String fieldName = field.getName();
            if (field.getType().isArray() || Collection.class.isAssignableFrom(field.getType())
                    || Map.class.isAssignableFrom(field.getType())) {

                columns.add(new PropertyColumn<>(new ResourceModel(field.getName()), field.getName()));
            } else if (field.getType().equals(boolean.class) || field.getType().equals(Boolean.class)) {
                columns.add(new BooleanPropertyColumn<>(new ResourceModel(field.getName()), field.getName(),
                        field.getName()));
            } else {
                columns.add(new PropertyColumn<RelationshipTypeTO, String>(new ResourceModel(field.getName()),
                        field.getName(), field.getName()) {

                    private static final long serialVersionUID = -6902459669035442212L;

                    @Override/*from  w  ww . j  a  va2 s.  c  o m*/
                    public String getCssClass() {
                        String css = super.getCssClass();
                        if ("key".equals(fieldName)) {
                            css = StringUtils.isBlank(css) ? "col-xs-1" : css + " col-xs-1";
                        }
                        return css;
                    }
                });
            }
        }
    }

    return columns;
}

From source file:de.ks.flatadocdb.defaults.ReflectionLuceneDocumentExtractor.java

protected boolean filterField(Field f) {
    boolean noStatic = !Modifier.isStatic(f.getModifiers());
    if (noStatic) {
        Class<?> type = f.getType();

        boolean validType = isValidBaseType(type);

        Type genericType = f.getGenericType();
        if (!validType && Collection.class.isAssignableFrom(type) && genericType instanceof ParameterizedType) {
            Type[] actualTypeArguments = ((ParameterizedType) genericType).getActualTypeArguments();
            if (actualTypeArguments.length == 1 && actualTypeArguments[0] instanceof Class) {
                validType = isValidBaseType((Class<?>) actualTypeArguments[0]);
            }/*from w w w.java2s  . c  o  m*/
        }
        if (!validType && TypeUtils.isArrayType(type)) {
            Type arrayComponentType = TypeUtils.getArrayComponentType(type);
            if (arrayComponentType instanceof Class) {
                validType = isValidBaseType((Class<?>) arrayComponentType);
            }
        }
        return validType;
    }
    return false;
}

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

/**
 * Equals/*from  w w  w . j av  a 2s  .co m*/
 * @param idfields ?fields
 * @param overwirte ?
 * @param doSuperMethod ?
 * @return
 */
public boolean createHashCodeMethod(List<JavaField> idfields, boolean overwirte, String doSuperMethod) {
    JavaMethod hashCode = new JavaMethod("hashCode");
    hashCode.setCheckReturn(false);
    hashCode.setReturnType(int.class);
    if (methods.containsKey(hashCode.getKey())) {//?
        if (!overwirte) {
            return false;
        }
    }
    hashCode.addContent("return new HashCodeBuilder()");
    //
    for (int i = 0; i < idfields.size(); i++) {
        JavaField field = idfields.get(i);
        String name = field.getName();
        if (Modifier.isAbstract(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        hashCode.addContent(".append(" + name + ")");
    }
    if (StringUtils.isNotEmpty(doSuperMethod)) {
        hashCode.addContent(".append(super." + doSuperMethod + "())");
    }
    hashCode.addContent(".toHashCode();");
    addMethod(hashCode);
    addImport(HashCodeBuilder.class);
    return true;
}

From source file:com.zuoxiaolong.niubi.job.persistent.BaseDaoImpl.java

private <T> List<Object> generateValueListAndSetSql(Class<T> clazz, T entity, StringBuffer sqlBuffer,
        boolean useLike) {
    List<Object> valueList = new ArrayList<>();
    if (entity != null) {
        Field[] fields = ReflectHelper.getAllFields(entity);
        for (int i = 0, index = 0; i < fields.length; i++) {
            Field field = fields[i];
            int modifiers = field.getModifiers();
            if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || Modifier.isFinal(modifiers)
                    || ObjectHelper.isTransientId(clazz, field)) {
                continue;
            }//from  w w w  .  ja  v a2  s.co m
            Object value = ReflectHelper.getFieldValueWithGetterMethod(entity, entity.getClass(),
                    field.getName());
            if (ObjectHelper.isEmpty(value)) {
                continue;
            }
            if (field.getType() == String.class && useLike) {
                sqlBuffer.append("and " + field.getName() + " like ?" + index++ + " ");
                valueList.add("%" + value + "%");
            } else {
                sqlBuffer.append("and " + field.getName() + "=?" + index++ + " ");
                valueList.add(value);
            }
        }
    }
    return valueList;
}

From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java

@Test
public void checkImplementedMethods() {
    Class<?> bukkitEvent = eventImpl.getSuperclass();
    for (Method method : bukkitEvent.getMethods()) {
        int modifiers = method.getModifiers();
        if (Modifier.isStatic(modifiers) || isDefault(method) || method.getDeclaringClass() == Event.class
                || method.getDeclaringClass() == Object.class || method.getName().equals("getHandlers")
                || method.getName().startsWith("_INVALID_")) {
            continue;
        }/*from   w w w .j a  v  a2s.  c  o  m*/

        try {
            eventImpl.getDeclaredMethod(method.getName(), method.getParameterTypes());
        } catch (NoSuchMethodException e) {
            fail(eventImpl.getSimpleName() + ": should override method " + method);
        }
    }
}

From source file:cn.webwheel.ActionSetter.java

public static String isSetter(Method method) {
    if (Modifier.isStatic(method.getModifiers()))
        return null;
    String name = method.getName();
    if (!name.startsWith("set"))
        return null;
    if (name.length() < 4)
        return null;
    if (method.getParameterTypes().length != 1)
        return null;
    name = name.substring(3);//from w  ww.  j ava  2  s. c o  m
    if (name.length() > 1 && name.equals(name.toUpperCase()))
        return name;
    return name.substring(0, 1).toLowerCase() + name.substring(1);
}

From source file:com.chinamobile.bcbsp.util.ObjectSizer.java

/**
 * Calculate the size of the object takes up space.
 * This object is an array or object./*from  ww  w  .jav a  2  s .c o  m*/
 *
 * @param object An object
 * @return The size of the object takes up space
 */
@SuppressWarnings("unchecked")
private int calculate(Object object) {
    if (object == null) {
        return 0;
    }
    Ref r = new Ref(object);
    if (dedup.contains(r)) {
        return 0;
    }
    dedup.add(r);
    int varSize = 0;
    int objSize = 0;
    for (Class clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
        if (clazz.isArray()) {
            varSize += emptyArrayVarSize;
            Class<?> componentType = clazz.getComponentType();
            if (componentType.isPrimitive()) {
                varSize += lengthOfPrimitiveArray(object) * sizeofPrimitiveClass(componentType);
                return occupationSize(emptyObjectSize, varSize, 0);
            }

            Object[] array = (Object[]) object;
            varSize += nullReferenceSize * array.length;
            for (Object o : array) {
                objSize += calculate(o);
            }
            return occupationSize(emptyObjectSize, varSize, objSize);
        }

        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            if (clazz != field.getDeclaringClass()) {
                continue;
            }
            Class<?> type = field.getType();
            if (type.isPrimitive()) {
                varSize += sizeofPrimitiveClass(type);
            } else {
                varSize += nullReferenceSize;
                try {
                    field.setAccessible(true);
                    objSize += calculate(field.get(object));
                } catch (Exception e) {
                    LOG.error("[calculate]", e);
                    objSize += occupyofConstructor(object, field);
                }
            }
        }
    }
    return occupationSize(emptyObjectSize, varSize, objSize);
}

From source file:org.apache.pulsar.common.configuration.PulsarConfigurationLoader.java

/**
 * Converts a PulsarConfiguration object to a ServiceConfiguration object.
 *
 * @param conf/*w  ww.  j  a  v  a2 s.  com*/
 * @param ignoreNonExistMember
 * @return
 * @throws IllegalArgumentException
 *             if conf has the field whose name is not contained in ServiceConfiguration and ignoreNonExistMember is false.
 * @throws RuntimeException
 */
public static ServiceConfiguration convertFrom(PulsarConfiguration conf, boolean ignoreNonExistMember)
        throws RuntimeException {
    try {
        final ServiceConfiguration convertedConf = ServiceConfiguration.class.newInstance();
        Field[] confFields = conf.getClass().getDeclaredFields();
        Arrays.stream(confFields).forEach(confField -> {
            try {
                Field convertedConfField = ServiceConfiguration.class.getDeclaredField(confField.getName());
                confField.setAccessible(true);
                if (!Modifier.isStatic(convertedConfField.getModifiers())) {
                    convertedConfField.setAccessible(true);
                    convertedConfField.set(convertedConf, confField.get(conf));
                }
            } catch (NoSuchFieldException e) {
                if (!ignoreNonExistMember) {
                    throw new IllegalArgumentException(
                            "Exception caused while converting configuration: " + e.getMessage());
                }
            } catch (IllegalAccessException e) {
                throw new RuntimeException(
                        "Exception caused while converting configuration: " + e.getMessage());
            }
        });
        return convertedConf;
    } catch (InstantiationException e) {
        throw new RuntimeException("Exception caused while converting configuration: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Exception caused while converting configuration: " + e.getMessage());
    }
}

From source file:com.amalto.core.metadata.ClassRepository.java

private TypeMetadata loadClass(Class clazz) {
    String typeName = getTypeName(clazz);
    if (getType(typeName) != null) { // If already defined return it.
        return getType(typeName);
    } else if (getNonInstantiableType(StringUtils.EMPTY, typeName) != null) {
        return getNonInstantiableType(StringUtils.EMPTY, typeName);
    }//from w  w w  .j  a va 2  s .com
    entityToJavaClass.put(typeName, clazz);
    if (Map.class.isAssignableFrom(clazz)) {
        return MAP_TYPE;
    }
    if (ArrayListHolder.class.equals(clazz)) {
        typeName = typeName + listCounter++;
    }
    boolean isEntity = typeStack.isEmpty();
    ComplexTypeMetadata classType = new ComplexTypeMetadataImpl(StringUtils.EMPTY, typeName, isEntity);
    addTypeMetadata(classType);
    typeStack.push(classType);
    String keyFieldName = ""; //$NON-NLS-1$
    if (isEntity && ObjectPOJO.class.isAssignableFrom(clazz)) {
        SimpleTypeFieldMetadata keyField = new SimpleTypeFieldMetadata(typeStack.peek(), true, false, true,
                "unique-id", //$NON-NLS-1$
                STRING, Collections.<String>emptyList(), Collections.<String>emptyList(),
                Collections.<String>emptyList(), StringUtils.EMPTY);
        keyField.setData(LINK, "PK/unique-id"); //$NON-NLS-1$
        classType.addField(keyField);
    } else if (isEntity) {
        keyFieldName = "unique-id"; //$NON-NLS-1$
    }
    // Class is abstract / interface: load sub classes
    if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
        Iterable<Class> subClasses = getSubclasses(clazz);
        ComplexTypeMetadata superType = typeStack.peek();
        if (superType.isInstantiable()) {
            typeStack.clear();
        }
        for (Class subClass : subClasses) {
            TypeMetadata typeMetadata = loadClass(subClass);
            typeMetadata.setInstantiable(superType.isInstantiable());
            typeMetadata.addSuperType(superType);
        }
        if (superType.isInstantiable()) {
            typeStack.push(superType);
        }
    }
    // Analyze methods
    Method[] classMethods = getMethods(clazz);
    for (Method declaredMethod : classMethods) {
        if (!Modifier.isStatic(declaredMethod.getModifiers())) {
            if (isBeanMethod(declaredMethod) && isClassMethod(clazz, declaredMethod)) {
                String fieldName = getName(declaredMethod);
                if (typeStack.peek().hasField(fieldName)) {
                    continue; // TODO Avoid override of fields (like PK)
                }
                Class<?> returnType = declaredMethod.getReturnType();
                FieldMetadata newField;
                boolean isMany = false;
                boolean isKey = keyFieldName.equals(fieldName);
                if (Iterable.class.isAssignableFrom(returnType)) {
                    returnType = listItemType != null ? listItemType
                            : getListItemClass(declaredMethod, returnType);
                    listItemType = null;
                    isMany = true;
                } else if (ArrayListHolder.class.isAssignableFrom(returnType)) {
                    listItemType = getListItemClass(declaredMethod, returnType);
                    isMany = false;
                } else if (Map.class.isAssignableFrom(returnType)) {
                    isMany = true;
                } else if (returnType.isArray()) {
                    isMany = true;
                    returnType = ((Class) returnType.getComponentType());
                } else if (returnType.getName().startsWith("org.w3c.")) { //$NON-NLS-1$
                    // TODO Serialized XML to string column
                    continue;
                } else if (Class.class.equals(returnType)) {
                    continue;
                } else if (returnType.getPackage() != null
                        && returnType.getPackage().getName().startsWith("java.io")) { //$NON-NLS-1$
                    continue;
                }
                if (returnType.isPrimitive() || returnType.getName().startsWith(JAVA_LANG_PREFIX)) {
                    String fieldTypeName = returnType.getName().toLowerCase();
                    if (fieldTypeName.startsWith(JAVA_LANG_PREFIX)) {
                        fieldTypeName = StringUtils.substringAfter(fieldTypeName, JAVA_LANG_PREFIX);
                    }
                    TypeMetadata fieldType;
                    if (Types.BYTE.equals(fieldTypeName) && isMany) {
                        fieldType = new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI,
                                Types.BASE64_BINARY);
                    } else {
                        fieldType = new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, fieldTypeName);
                    }
                    newField = new SimpleTypeFieldMetadata(typeStack.peek(), isKey, isMany, isKey, fieldName,
                            fieldType, Collections.<String>emptyList(), Collections.<String>emptyList(),
                            Collections.<String>emptyList(), StringUtils.EMPTY);
                    LongString annotation = declaredMethod.getAnnotation(LongString.class);
                    if (Types.STRING.equals(fieldTypeName) && annotation != null) {
                        fieldType.setData(MetadataRepository.DATA_MAX_LENGTH,
                                String.valueOf(Integer.MAX_VALUE));
                        if (annotation.preferLongVarchar()) {
                            fieldType.setData(LongString.PREFER_LONGVARCHAR, Boolean.TRUE);
                        }
                    }
                } else {
                    ComplexTypeMetadata fieldType;
                    if (Map.class.isAssignableFrom(returnType)) {
                        fieldType = MAP_TYPE;
                    } else {
                        fieldType = (ComplexTypeMetadata) loadClass(returnType);
                    }
                    if (!isEntity || !fieldType.isInstantiable()) {
                        newField = new ContainedTypeFieldMetadata(typeStack.peek(), isMany, false, fieldName,
                                new SoftTypeRef(this, StringUtils.EMPTY, fieldType.getName(), false),
                                Collections.<String>emptyList(), Collections.<String>emptyList(),
                                Collections.<String>emptyList(), StringUtils.EMPTY);
                    } else {
                        newField = new ReferenceFieldMetadata(typeStack.peek(), false, isMany, false, fieldName,
                                fieldType, fieldType.getField("unique-id"), //$NON-NLS-1$
                                Collections.<FieldMetadata>emptyList(), StringUtils.EMPTY, true, false, STRING,
                                Collections.<String>emptyList(), Collections.<String>emptyList(),
                                Collections.<String>emptyList(), StringUtils.EMPTY, StringUtils.EMPTY);
                    }
                }
                typeStack.peek().addField(newField);
            }
        }
    }

    typeStack.peek().addField(new SimpleTypeFieldMetadata(typeStack.peek(), false, false, false, "digest", //$NON-NLS-1$
            new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING),
            Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(),
            StringUtils.EMPTY));

    return typeStack.pop();
}