Example usage for java.lang.reflect Field getDeclaringClass

List of usage examples for java.lang.reflect Field getDeclaringClass

Introduction

In this page you can find the example usage for java.lang.reflect Field getDeclaringClass.

Prototype

@Override
public Class<?> getDeclaringClass() 

Source Link

Document

Returns the Class object representing the class or interface that declares the field represented by this Field object.

Usage

From source file:org.jboss.jaxb.intros.IntroductionsAnnotationReader.java

private FieldIntroConfig getFieldIntroConfig(Field field) {
    ClassIntroConfig classIntroConfig = getClassIntroConfig(field.getDeclaringClass());

    if (classIntroConfig != null) {
        String fieldName = field.getName();

        for (FieldIntroConfig fieldIntro : classIntroConfig.getField()) {
            if (fieldIntro.getName().equals(fieldName)) {
                return fieldIntro;
            } else if (isRegexMatch(fieldName, fieldIntro.getName())) {
                return fieldIntro;
            }/*from ww  w  .j  a v a2s.  c o  m*/
        }
    }

    return null;
}

From source file:de.ks.flatadocdb.metamodel.Parser.java

protected MethodHandle getGetter(Field f) {
    try {/*from   w w w .  j a  v a2  s.  c o m*/
        f.setAccessible(true);
        return MethodHandles.lookup().unreflectGetter(f);
    } catch (IllegalAccessException e) {
        throw new ParseException(
                "Could not extract getter handle for " + f + " on " + f.getDeclaringClass().getName(), e);
    }
}

From source file:de.ks.flatadocdb.metamodel.Parser.java

protected MethodHandle getSetter(Field f) {
    try {//from   w  ww . ja  v a 2  s  .c o m
        f.setAccessible(true);
        return MethodHandles.lookup().unreflectSetter(f);
    } catch (IllegalAccessException e) {
        throw new ParseException(
                "Could not extract setter handle for " + f + " on " + f.getDeclaringClass().getName(), e);
    }
}

From source file:org.carrot2.util.attribute.AttributeDescriptor.java

/**
 * /*from  w w w. ja va 2 s  .co  m*/
 */
AttributeDescriptor(Field field, Object defaultValue, List<Annotation> constraints,
        AttributeMetadata metadata) {
    this.attributeField = field;
    this.attributeDeclaringClassString = field.getDeclaringClass().getName();

    this.key = BindableUtils.getKey(field);
    this.type = ClassUtils.primitiveToWrapper(field.getType());
    this.defaultValue = defaultValue;
    this.constraints = constraints;
    this.metadata = metadata;

    this.inputAttribute = field.getAnnotation(Input.class) != null;
    this.outputAttribute = field.getAnnotation(Output.class) != null;
    this.requiredAttribute = field.getAnnotation(Required.class) != null;

    prepareForSerialization();
}

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  www . j a  v  a 2  s . com
 *
 * @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.sonatype.nexus.mock.SeleniumTest.java

private void cleanFields() throws IllegalArgumentException, IllegalAccessException {
    List<Field> fields = getFields(getClass());
    for (Field field : fields) {
        if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
            continue;
        }//  w  w w.  ja  va2 s. co  m

        field.setAccessible(true);
        if (field.getDeclaringClass().isPrimitive()) {
            field.set(this, 0);
        } else {
            field.set(this, null);
        }
    }
}

From source file:org.scub.foundation.incubator.framework.core.implementations.utils.AbstractValidator.java

/**
 * Get the attribut name with it's class name and package for the given field.
 * @param field the field/*from  w  w w  .  j a va  2  s . c o m*/
 * @return the atribut name (package.class.attributName)
 */
protected String getAttributName(Field field) {
    return field.getDeclaringClass().getSimpleName() + DOT + field.getName();
}

From source file:richtercloud.reflection.form.builder.jpa.JPAStringFieldHandler.java

@Override
public Pair<JComponent, ComponentHandler<?>> handle0(Field field, Object instance,
        final FieldUpdateListener<FieldUpdateEvent<String>> updateListener,
        JPAReflectionFormBuilder reflectionFormBuilder)
        throws IllegalArgumentException, IllegalAccessException, FieldHandlingException {
    Type fieldType = field.getType();
    String fieldValue = (String) field.get(instance);
    return this.jPAStringTypeHandler.handle(fieldType, fieldValue, field.getName(), field.getDeclaringClass(),
            updateListener, reflectionFormBuilder);
}

From source file:by.creepid.docsreporter.context.meta.ImagesMetadataFiller.java

@Override
public void fillMetadata(FieldsMetadata metadataToFill, Class<?> modelClass, String modelName,
        Map<String, Class<?>> iterationNames) {
    Map<String, Field> fields = FieldHelper.getAnnotatedTypeArgumentFields(modelClass, modelName,
            imageAnnotation, true);//w w w. j av a  2  s  .  com
    for (Field field : fields.values()) {

        String name = field.getName();
        if (field.getType() != byte[].class) {
            throw new IllegalStateException("Image field [" + name + "] must have byte array type!");
        }

        Image imageAnnot = (Image) field.getAnnotation(imageAnnotation);

        List<String> aliases = getAliases(field.getDeclaringClass(), iterationNames);
        if (!aliases.isEmpty()) {
            for (String alias : aliases) {

                String[] bookmarks = imageAnnot.bookmarks();
                for (String bookmark : bookmarks) {

                    metadataToFill.addFieldAsImage(bookmark, FieldHelper.getFieldPath(alias, field.getName()));
                }
            }
        } else {
            String[] bookmarks = imageAnnot.bookmarks();
            for (String bookmark : bookmarks) {

                metadataToFill.addFieldAsImage(bookmark,
                        FieldHelper.getFieldPath(field.getDeclaringClass().getSimpleName(), field.getName()),
                        behaviour);
            }
        }
    }

    Map<String, Field> fieldMap = FieldHelper.getAnnotatedDeclaredFields(modelClass, modelName, imageAnnotation,
            true);
    Set<Map.Entry<String, Field>> entries = fieldMap.entrySet();
    for (Map.Entry<String, Field> entry : entries) {
        Image imageAnnot = (Image) entry.getValue().getAnnotation(imageAnnotation);

        String[] bookmarks = imageAnnot.bookmarks();
        for (String bookmark : bookmarks) {
            metadataToFill.addFieldAsImage(bookmark, entry.getKey(), behaviour);
        }

    }
}

From source file:org.javelin.sws.ext.bind.internal.metadata.PropertyCallback.java

@Override
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
    log.trace("- Analyzing field: {}.{}", field.getDeclaringClass().getSimpleName(), field.getName());
    String fieldName = field.getName();
    // metadata for a field
    ReflectionUtils.makeAccessible(field);
    PropertyMetadata<T, ?> metadata = PropertyMetadata.newPropertyMetadata(this.clazz, field.getType(),
            fieldName, field, PropertyKind.FIELD);
    this.doWithPropertySafe(metadata);
}