当前位置: 首页>>代码示例>>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;未经允许,请勿转载。