當前位置: 首頁>>代碼示例>>Java>>正文


Java Field.getDeclaringClass方法代碼示例

本文整理匯總了Java中java.lang.reflect.Field.getDeclaringClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.getDeclaringClass方法的具體用法?Java Field.getDeclaringClass怎麽用?Java Field.getDeclaringClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Field的用法示例。


在下文中一共展示了Field.getDeclaringClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: printNewField

import java.lang.reflect.Field; //導入方法依賴的package包/類
final void printNewField(Field field) {
    if (!mvoMeta_.isNewField(field)) {
        throw new IllegalArgumentException();
    }

    mvoMeta_.registerField(field, null);

    Class<? extends MVO> declaringClass = (Class<? extends MVO>) field.getDeclaringClass();
    if (mvoMeta_.isNewClass(declaringClass)) {
        printNewClass(declaringClass);
    }

    int classId = mvoMeta_.getClassId(declaringClass);
    int fieldId = mvoMeta_.getFieldId(field);
    loggingStream_.println
            (concat
                    (EntryType.FIELD_ID.id, hexInt(fieldId), hexInt(classId), field.getName()));
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:19,代碼來源:JournalWriter.java

示例2: findSetMethod

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Returns set method of the field if any public set method found.
 *
 * @param field field
 * @return set method.
 */
public static Optional<Method> findSetMethod(final Field field) {

  AssertHelper.notNull(field);

  Class<?> declaringClass = field.getDeclaringClass();

  Method[] methods = declaringClass.getMethods();
  String capitalizedFieldName = StringHelper.capitalizeFirstLetter(field.getName());

  Optional<Method> optionalMethod = Arrays.stream(methods)
      .filter(m ->
          m.getName().equals("set" + capitalizedFieldName)
              && m.getParameterCount() == 1
              && Arrays.stream(m.getParameterTypes()).anyMatch(p -> p.equals(field.getType())
              || PrimitiveHelper.getOppositeClass(p).equals(field.getType())))
      .findFirst();

  return optionalMethod;
}
 
開發者ID:mental-party,項目名稱:meparty,代碼行數:26,代碼來源:FieldUtil.java

示例3: findField

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Finds public field (static or non-static)
 * that is declared in public class.
 *
 * @param type  the class that can have field
 * @param name  the name of field to find
 * @return object that represents found field
 * @throws NoSuchFieldException if field is not found
 * @see Class#getField
 */
public static Field findField(Class<?> type, String name) throws NoSuchFieldException {
    if (name == null) {
        throw new IllegalArgumentException("Field name is not set");
    }
    if (!FinderUtils.isExported(type)) {
        throw new NoSuchFieldException("Field '" + name + "' is not accessible");
    }
    Field field = type.getField(name);
    if (!Modifier.isPublic(field.getModifiers())) {
        throw new NoSuchFieldException("Field '" + name + "' is not public");
    }
    type = field.getDeclaringClass();
    if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
        throw new NoSuchFieldException("Field '" + name + "' is not accessible");
    }
    return field;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:FieldFinder.java

示例4: getHideField

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Field getHideField(final Field superclassField, final Class<?> subclass) {
	final Class<?> superclass = superclassField.getDeclaringClass();
	Class<?> currentClass = subclass;

	if (!superclass.isAssignableFrom(subclass)) {
		throw new RuntimeException("Class[" + subclass + "] is not superclass" + " of class[" + subclass + "]");
	}

	while (!currentClass.equals(superclass)) {
		try {
			final Field m = currentClass.getDeclaredField(superclassField.getName());

			if (matchInheritance(m, superclassField)) {
				return m;
			}
		} catch (final Exception ex) {
		}

		currentClass = currentClass.getSuperclass();
	}

	return superclassField;
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:24,代碼來源:Reflections.java

示例5: getFields

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Returns the fields for the class facet.
 * @return the fields for the class facet.
 */
Collection<Field> getFields() {
    if(isRestricted) {
        // NOTE: we can't do anything here. Unlike with methods in AccessibleMethodsLookup, we can't just return
        // the fields from a public superclass, because this class might define same-named fields which will shadow
        // the superclass fields, and we have no way to know if they do, since we're denied invocation of
        // getFields(). Therefore, the only correct course of action is to not expose any public fields from a class
        // defined in a restricted package.
        return Collections.emptySet();
    }

    final Field[] fields = clazz.getFields();
    final Collection<Field> cfields = new ArrayList<>(fields.length);
    for(final Field field: fields) {
        final boolean isStatic = Modifier.isStatic(field.getModifiers());
        if(isStatic && clazz != field.getDeclaringClass()) {
            // ignore inherited static fields
            continue;
        }

        if(instance != isStatic && isAccessible(field)) {
            cfields.add(field);
        }
    }
    return cfields;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:FacetIntrospector.java

示例6: setupLabels

import java.lang.reflect.Field; //導入方法依賴的package包/類
@SuppressWarnings("nls")
public void setupLabels(Section section)
{
	for( Field field : componentLabels.keySet() )
	{
		try
		{
			AbstractRenderedComponent<?> comp = (AbstractRenderedComponent<?>) field.get(section);
			comp.setLabel(componentLabels.get(field));
		}
		catch( Exception e )
		{
			throw new RuntimeException(field.getName() + " on " + field.getDeclaringClass()
				+ " has @PlugKey but probably missing @Component?", e);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:AnnotatedPlugResourceScanner.java

示例7: writeFields

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Writes fields using the specified writer.
 *
 * @param object The object that owns the field.
 * @param fields The fields to be written.
 * @param writer The writer to use for writing the fields.
 * @param context The serialization context.
 */
protected void writeFields(
    T object,
    Field[] fields,
    Writer writer,
    Context context
)
{
    NamingStrategy namingStrategy = context.getNamingStrategy();

    for (Field field : fields) {
        String name = namingStrategy.getFieldName(field);
        Class<?> declaringClass = field.getDeclaringClass();
        String fieldClass = namingStrategy.getClassName(declaringClass);

        writer.writeProperty(name, fieldClass, getModifiers(field));
        context.write(ReflectionUtils.getValue(object, field), writer);
    }
}
 
開發者ID:marcospassos,項目名稱:java-php-serializer,代碼行數:27,代碼來源:ObjectAdapter.java

示例8: getInstance

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Maakt een nieuw BmrFieldMetaInfo object voor het gegeven veld.
 *
 * @param field het veld waarvan de meta informatie moet worden gemaakt
 * @return BrmFieldMetaInfo
 */
public static BmrFieldMetaInfo getInstance(final Field field) {
    final Map<String, Class<?>> elementNaamTypeMap = new LinkedHashMap<>();
    final XmlChild xmlChildAnnotatie = field.getAnnotation(XmlChild.class);
    final String xmlChildNaam = xmlChildAnnotatie != null ? xmlChildAnnotatie.naam() : "";
    final int xmlChildVolgorde = xmlChildAnnotatie != null ? xmlChildAnnotatie.volgorde() : 0;
    initialiseerElementNaamTypeMapping(elementNaamTypeMap, field, xmlChildNaam);
    return new BmrFieldMetaInfo(field.getDeclaringClass(), field, findGetterMethode(field), elementNaamTypeMap, xmlChildVolgorde);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:15,代碼來源:BmrFieldMetaInfo.java

示例9: DependencyDescriptor

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Create a new descriptor for a field.
 * @param field the field to wrap
 * @param required whether the dependency is required
 * @param eager whether this dependency is 'eager' in the sense of
 * eagerly resolving potential target beans for type matching
 */
public DependencyDescriptor(Field field, boolean required, boolean eager) {
	Assert.notNull(field, "Field must not be null");
	this.field = field;
	this.declaringClass = field.getDeclaringClass();
	this.fieldName = field.getName();
	this.required = required;
	this.eager = eager;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:DependencyDescriptor.java

示例10: instantiate

import java.lang.reflect.Field; //導入方法依賴的package包/類
protected Expression instantiate(Object oldInstance, Encoder out) {
    Field f = (Field)oldInstance;
    return new Expression(oldInstance,
            f.getDeclaringClass(),
            "getField",
            new Object[]{f.getName()});
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:MetaData.java

示例11: invoke

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Set the corresponding field based on the entered string value
 *
 * @param instance object
 * @param strVal   input value
 * @param field    input field
 * @throws IntrospectionException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 */
public static void invoke(Object instance, String strVal, Field field)
		throws IntrospectionException, InvocationTargetException, IllegalAccessException {

	if (strVal == null) strVal = "";

	Object val = parser.parse(strVal, field.getType());

	PropertyDescriptor pd = new PropertyDescriptor(field.getName(), field.getDeclaringClass());
	Method m = pd.getWriteMethod();// get write method
	m.invoke(instance, val);
}
 
開發者ID:ICT-BDA,項目名稱:EasyML,代碼行數:22,代碼來源:BaseDao.java

示例12: findField

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Finds public field (static or non-static)
 * that is declared in public class.
 *
 * @param type  the class that can have field
 * @param name  the name of field to find
 * @return object that represents found field
 * @throws NoSuchFieldException if field is not found
 * @see Class#getField
 */
public static Field findField(Class<?> type, String name) throws NoSuchFieldException {
    if (name == null) {
        throw new IllegalArgumentException("Field name is not set");
    }
    Field field = type.getField(name);
    if (!Modifier.isPublic(field.getModifiers())) {
        throw new NoSuchFieldException("Field '" + name + "' is not public");
    }
    type = field.getDeclaringClass();
    if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
        throw new NoSuchFieldException("Field '" + name + "' is not accessible");
    }
    return field;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:FieldFinder.java

示例13: nextChild

import java.lang.reflect.Field; //導入方法依賴的package包/類
Pair<Object, Field> nextChild() throws IllegalAccessException
{
    //If the last child returned was a key from a map, the value from that entry is stashed
    //so it can be returned next
    if (mapEntryValue != null)
    {
        Pair<Object, Field> retval = Pair.create(mapEntryValue, field);
        mapEntryValue = null;
        return retval;
    }

    //If o is a ConcurrentMap, BlockingQueue, or Object[], then an iterator will be stored to return the elements
    if (collectionIterator != null)
    {
        if (!collectionIterator.hasNext())
            return null;
        Object nextItem = null;
        //Find the next non-null element to traverse since returning null will cause the visitor to stop
        while (collectionIterator.hasNext() && (nextItem = collectionIterator.next()) == null){}
        if (nextItem != null)
        {
            if (isMapIterator & nextItem instanceof Map.Entry)
            {
                Map.Entry entry = (Map.Entry)nextItem;
                mapEntryValue = entry.getValue();
                return Pair.create(entry.getKey(), field);
            }
            return Pair.create(nextItem, field);
        }
        else
        {
            return null;
        }
    }

    //Basic traversal of an object by its member fields
    //Don't return null values as that indicates no more objects
    while (true)
    {
        Field nextField = nextField();
        if (nextField == null)
            return null;

        //A weak reference isn't strongly reachable
        //subclasses of WeakReference contain strong references in their fields, so those need to be traversed
        //The weak reference fields are in the common Reference class base so filter those out
        if (o instanceof WeakReference & nextField.getDeclaringClass() == Reference.class)
            continue;

        Object nextObject = nextField.get(o);
        if (nextObject != null)
            return Pair.create(nextField.get(o), nextField);
    }
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:55,代碼來源:Ref.java

示例14: FieldInfo

import java.lang.reflect.Field; //導入方法依賴的package包/類
public FieldInfo(String name, Method method, Field field, Class<?> clazz, Type type, int ordinal, int serialzeFeatures) {
    Class<?> fieldClass;
    Type fieldType;
    Type genericFieldType;
    this.ordinal = 0;
    this.getOnly = false;
    this.name = name;
    this.method = method;
    this.field = field;
    this.ordinal = ordinal;
    this.serialzeFeatures = serialzeFeatures;
    if (method != null) {
        TypeUtils.setAccessible(method);
    }
    if (field != null) {
        TypeUtils.setAccessible(field);
    }
    if (method != null) {
        if (method.getParameterTypes().length == 1) {
            fieldClass = method.getParameterTypes()[0];
            fieldType = method.getGenericParameterTypes()[0];
        } else {
            fieldClass = method.getReturnType();
            fieldType = method.getGenericReturnType();
            this.getOnly = true;
        }
        this.declaringClass = method.getDeclaringClass();
    } else {
        fieldClass = field.getType();
        fieldType = field.getGenericType();
        this.declaringClass = field.getDeclaringClass();
    }
    if (clazz != null && fieldClass == Object.class && (fieldType instanceof TypeVariable)) {
        genericFieldType = getInheritGenericType(clazz, (TypeVariable) fieldType);
        if (genericFieldType != null) {
            this.fieldClass = TypeUtils.getClass(genericFieldType);
            this.fieldType = genericFieldType;
            return;
        }
    }
    genericFieldType = getFieldType(clazz, type, fieldType);
    if (genericFieldType != fieldType) {
        if (genericFieldType instanceof ParameterizedType) {
            fieldClass = TypeUtils.getClass(genericFieldType);
        } else if (genericFieldType instanceof Class) {
            fieldClass = TypeUtils.getClass(genericFieldType);
        }
    }
    this.fieldType = genericFieldType;
    this.fieldClass = fieldClass;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:52,代碼來源:FieldInfo.java

示例15: getDeclaringClassForField

import java.lang.reflect.Field; //導入方法依賴的package包/類
public Class getDeclaringClassForField(Field field) {
    return field.getDeclaringClass();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:4,代碼來源:ReflectionNavigator.java


注:本文中的java.lang.reflect.Field.getDeclaringClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。