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:com.robertsmieja.test.utils.junit.GettersAndSettersUtils.java

static Method getSetterForField(Field field) {
    return MethodUtils.getAccessibleMethod(field.getDeclaringClass(),
            accessorMethodNameForField(GettersAndSettersTests.SET_METHOD_PREFIX, field), field.getType());
}

From source file:com.robertsmieja.test.utils.junit.GettersAndSettersUtils.java

static ImmutablePair<Method, Method> getGetterAndSetterForField(Field field) {
    Method getter = MethodUtils.getAccessibleMethod(field.getDeclaringClass(),
            accessorMethodNameForField(GettersAndSettersTests.IS_METHOD_PREFIX, field));
    if (getter == null) {
        getter = MethodUtils.getAccessibleMethod(field.getDeclaringClass(),
                accessorMethodNameForField(GettersAndSettersTests.GET_METHOD_PREFIX, field));
    }//from  ww w.  ja  v a2s. com
    if (getter == null) {
        failToFindMethodForField(field,
                accessorMethodNameForField(GettersAndSettersTests.GET_METHOD_PREFIX, field));
    }
    Method setter = getSetterForField(field);
    if (setter == null) {
        failToFindMethodForField(field,
                accessorMethodNameForField(GettersAndSettersTests.SET_METHOD_PREFIX, field));
    }
    return new ImmutablePair<>(getter, setter);
}

From source file:IntrospectionUtil.java

public static boolean containsSameFieldName(Field field, Class c, boolean checkPackage) {
    if (checkPackage) {
        if (!c.getPackage().equals(field.getDeclaringClass().getPackage()))
            return false;
    }/*from w  w  w  . j  av  a 2s.  co m*/

    boolean sameName = false;
    Field[] fields = c.getDeclaredFields();
    for (int i = 0; i < fields.length && !sameName; i++) {
        if (fields[i].getName().equals(field.getName()))
            sameName = true;
    }
    return sameName;
}

From source file:Main.java

public static String getNamespace(Field field, XmlAttribute xmlAttribute) {
    String namespace = xmlAttribute.namespace();
    if ("##default".equals(namespace)) {
        namespace = null;//from w  w  w.  ja  v  a 2s.co m
    }

    if (namespace == null) {
        namespace = getNamespace(field.getDeclaringClass());
    }

    return namespace;
}

From source file:com.espertech.esper.event.vaevent.PropertyUtility.java

private static PropertyAccessException getAccessExceptionField(Field field, Exception e) {
    Class declaring = field.getDeclaringClass();
    String message = "Failed to obtain field value for field " + field.getName() + " on class "
            + JavaClassHelper.getClassNameFullyQualPretty(declaring) + ": " + e.getMessage();
    throw new PropertyAccessException(message, e);
}

From source file:com.espertech.esper.event.vaevent.PropertyUtility.java

public static PropertyAccessException getMismatchException(Field field, Object object, ClassCastException e) {
    return getMismatchException(field.getDeclaringClass(), object, e);
}

From source file:ch.ralscha.extdirectspring.generator.association.AbstractAssociation.java

private static String getWarningText(Field field, String type, String propertyName) {
    String warning = "Field ";
    warning += field.getDeclaringClass().getName();
    warning += ".";
    warning += field.getName();/*from   w  w w.ja  v  a 2 s  . co m*/
    return warning + ": A '" + type + "' association does not support property '" + propertyName
            + "'. Property will be ignored.";
}

From source file:ReflectionUtils.java

/**
 * ,DeclaredField.//from  ww w .j av a 2  s . c om
 */
protected static void makeAccessible(final Field field) {
    if (!Modifier.isPublic(field.getModifiers())
            || !Modifier.isPublic(field.getDeclaringClass().getModifiers())) {
        field.setAccessible(true);
    }
}

From source file:com.kangyonggan.cms.util.Reflections.java

/**
 * ?private/protected???public?????JDKSecurityManager
 *///from ww  w . j a  v a 2 s  .c o m
public static void makeAccessible(Field field) {
    boolean temp = (!Modifier.isPublic(field.getModifiers())
            || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
            || Modifier.isFinal(field.getModifiers())) && !field.isAccessible();
    if (temp) {
        field.setAccessible(true);
    }
}

From source file:$.Reflections.java

/**
     * ?private/protected???public?????JDKSecurityManager
     *///  w ww .  j  a v  a2s .c o  m
    public static void makeAccessible(Field field) {
        if ((!Modifier.isPublic(field.getModifiers())
                || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
                || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
            field.setAccessible(true);
        }
    }