java.lang.reflect.Field#getClass ( )源码实例Demo

下面列出了java.lang.reflect.Field#getClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: influxdb-java   文件: InfluxDBResultMapper.java
<T> boolean fieldValueModified(final Class<?> fieldType, final Field field, final T object, final Object value,
                               final TimeUnit precision)
  throws IllegalArgumentException, IllegalAccessException {
  if (String.class.isAssignableFrom(fieldType)) {
    field.set(object, String.valueOf(value));
    return true;
  }
  if (Instant.class.isAssignableFrom(fieldType)) {
    Instant instant;
    if (value instanceof String) {
      instant = Instant.from(RFC3339_FORMATTER.parse(String.valueOf(value)));
    } else if (value instanceof Long) {
      instant = Instant.ofEpochMilli(toMillis((long) value, precision));
    } else if (value instanceof Double) {
      instant = Instant.ofEpochMilli(toMillis(((Double) value).longValue(), precision));
    } else if (value instanceof Integer) {
      instant = Instant.ofEpochMilli(toMillis(((Integer) value).longValue(), precision));
    } else {
      throw new InfluxDBMapperException("Unsupported type " + field.getClass() + " for field " + field.getName());
    }
    field.set(object, instant);
    return true;
  }
  return false;
}
 
源代码2 项目: rice   文件: XmlObjectSerializerServiceImpl.java
/**
 * @see com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider#visitSerializableFields(java.lang.Object, com.thoughtworks.xstream.converters.reflection.ReflectionProvider.Visitor)
 */
@Override
public void visitSerializableFields(Object object, Visitor visitor) {
    for (Iterator iterator = fieldDictionary.serializableFieldsFor(object.getClass()); iterator.hasNext();) {
        Field field = (Field) iterator.next();
        if (!fieldModifiersSupported(field)) {
            continue;
        }
        validateFieldAccess(field);
        if (ignoreField(field)) {
            continue;
        }
        Object value = null;
        try {
            value = field.get(object);
            if (value != null && lda.isProxied(value)) {
                value = lda.resolveProxy(value);
            }
        } catch (Exception e) {
            throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName() + " on " + object, e);
        }
        visitor.visit(field.getName(), field.getType(), field.getDeclaringClass(), value);
    }
}
 
源代码3 项目: jdk1.8-source-analysis   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码4 项目: dragonwell8_jdk   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码5 项目: TencentKona-8   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码6 项目: jdk8u60   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码7 项目: JDKSourceCode1.8   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码10 项目: Java8CN   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码11 项目: hottub   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码12 项目: openjdk-8-source   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码13 项目: openjdk-8   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码14 项目: jdk8u_jdk   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码15 项目: jdk8u-jdk   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码16 项目: jdk-1.7-annotated   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码17 项目: jdk8u-dev-jdk   文件: MemberName.java
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
    fld.getClass();  // NPE check
    // fill in vmtarget, vmindex while we have fld in hand:
    MethodHandleNatives.init(this, fld);
    assert(isResolved() && this.clazz != null);
    this.name = fld.getName();
    this.type = fld.getType();
    assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
    byte refKind = this.getReferenceKind();
    assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
    if (makeSetter) {
        changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
    }
}
 
源代码18 项目: JSoap   文件: TheSoapClass.java
@Override
public void getAttributeInfo(int index, AttributeInfo attributeInfo) {

    Field f = attributes_map.get(index);

    if (f.getType().equals(String.class))
        attributeInfo.type = AttributeInfo.STRING_CLASS;
    else
        attributeInfo.type = f.getClass();

    String prpname = f.getAnnotation(JSoapAttribute.class).name();
    if (prpname.equals("JSOAP_DEFAULT_ATTRIBUTE_NAME"))
        attributeInfo.name = f.getName();
    else
        attributeInfo.name = f.getAnnotation(JSoapAttribute.class).name();

    String prpns = f.getAnnotation(JSoapAttribute.class).namespace();
    if (prpns.equals("JSOAP_DEFAULT_ATTRIBUTE_NAMESPACE")) {
        if (this.getClass().getAnnotation(JSoapClass.class) != null) {
            String ns = this.getClass().getAnnotation(JSoapClass.class).namespace();
            if (ns==null)
                Log.e("JSoap", "Missing namespace in field " + f.getName() + " in class " + this.getClass() + ". Either declare it at the field SoapRequestAttribute annotation or at the class SoapRequestClass annotation");
            else
                attributeInfo.namespace = ns;
        }
        else {
            Log.e("JSoap", "Missing namespace in field " + f.getName() + " in class " + this.getClass() + ". Either declare it at the field SoapRequestAttribute annotation or at the class SoapRequestClass annotation");
        }
    }

}
 
源代码19 项目: JSoap   文件: TheSoapClass.java
@Override
public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
    if (fields_map != null) {
        Field f = fields_map.get(i);
        if (f.getType().equals(String.class))
            propertyInfo.type = PropertyInfo.STRING_CLASS;
        else
            propertyInfo.type = f.getClass();

        String prpname = f.getAnnotation(JSoapReqField.class).fieldName();
        if (prpname.equals("JSOAP_DEFAULT_FIELDNAME"))
            propertyInfo.name = f.getName();
        else
            propertyInfo.name = f.getAnnotation(JSoapReqField.class).fieldName();


        String prpns = f.getAnnotation(JSoapReqField.class).namespace();
        if (prpns.equals("JSOAP_DEFAULT_NAMESPACE")) {
            if (this.getClass().getAnnotation(JSoapClass.class) != null) {
                String ns = this.getClass().getAnnotation(JSoapClass.class).namespace();
                if (ns==null)
                    Log.e("JSoap", "Missing namespace in field " + f.getName() + " in class " + this.getClass() + ". Either declare it at the field SoapRequestElement annotation or at the class SoapRequestClass annotation");
                else
                    propertyInfo.namespace = ns;
            }
            else {
                Log.e("JSoap", "Missing namespace in field " + f.getName() + " in class " + this.getClass() + ". Either declare it at the field SoapRequestElement annotation or at the class SoapRequestClass annotation");
            }
        }
        else {
            propertyInfo.namespace = prpns;
        }
    }
}
 
/**
 *
 * @param componentClass
 */
public DataTypeDefinitionImpl(final Class<?> componentClass) {
    this.clazz = componentClass;
    this.name = componentClass.getName();
    this.simpleName = componentClass.getSimpleName();
    // given this class extract the property elements
    final Field[] fields = componentClass.getDeclaredFields();

    for (final Field f : fields) {
        final Property propAnnotation = f.getAnnotation(Property.class);
        if (propAnnotation != null) {
            final TypeSchema ts = TypeSchema.typeConvert(f.getType());

            // array of strings, "a","b","c","d" to become map of {a:b}, {c:d}
            final String[] userSupplied = propAnnotation.schema();
            for (int i = 0; i < userSupplied.length; i += 2) {
                final String userKey = userSupplied[i];
                Object userValue;
                switch (userKey.toLowerCase()) {
                case "title":
                case "pattern":
                    userValue = userSupplied[i + 1];
                    break;
                case "uniqueitems":
                    userValue = Boolean.parseBoolean(userSupplied[i + 1]);
                    break;
                case "required":
                case "enum":
                    userValue = Stream.of(userSupplied[i + 1].split(",")).map(String::trim).toArray(String[]::new);
                    break;
                default:
                    userValue = Integer.parseInt(userSupplied[i + 1]);
                    break;
                }
                ts.put(userKey, userValue);
            }

            final PropertyDefinition propDef = new PropertyDefinitionImpl(f.getName(), f.getClass(), ts, f);
            this.properties.put(f.getName(), propDef);
        }
    }

}