本文整理匯總了Java中java.lang.reflect.Field.isSynthetic方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.isSynthetic方法的具體用法?Java Field.isSynthetic怎麽用?Java Field.isSynthetic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Field
的用法示例。
在下文中一共展示了Field.isSynthetic方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findAnnotatedFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Collection<Field> findAnnotatedFields(Class<?> type, Class<? extends Annotation> annotation)
{
List<Field> result = new ArrayList<>();
// gather all publicly available fields
// this returns everything, even if it's declared in a parent
for (Field field : type.getFields()) {
if (field.isSynthetic() || isStatic(field.getModifiers())) {
continue;
}
if (field.isAnnotationPresent(annotation)) {
result.add(field);
}
}
return result;
}
示例2: getAllFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Geef alle velden van een klasse (inclusief velden uit super klassen, exclusief
* java.lang.Object).
* @param clazz klasse
* @return lijst van alle velden
*/
public static Field[] getAllFields(final Class<?> clazz) {
final java.util.List<Field> result = new ArrayList<>();
Class<?> theClazz = clazz;
while (theClazz != null && !Object.class.equals(theClazz)) {
for (final Field field : theClazz.getDeclaredFields()) {
if (!field.isSynthetic()) {
result.add(field);
}
}
theClazz = theClazz.getSuperclass();
}
return result.toArray(new Field[]{});
}
示例3: findClassField
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Tries to find a class fields. Supports inheritance and doesn't return synthetic fields.
*
* @param beanClass class to be searched for
* @param fieldName field name
* @return a list of found fields
*/
public static Field findClassField(Class<?> beanClass, String fieldName) {
Class<?> currentClass = beanClass;
while (currentClass != null && currentClass != Object.class) {
for (Field field : currentClass.getDeclaredFields()) {
if (field.isSynthetic()) {
continue;
}
if (field.getName().equals(fieldName)) {
return field;
}
}
currentClass = currentClass.getSuperclass();
}
return null;
}
示例4: validateClass
import java.lang.reflect.Field; //導入方法依賴的package包/類
private void validateClass(Class<?> source, RuleSourceValidationProblemCollector problems) {
int modifiers = source.getModifiers();
if (Modifier.isInterface(modifiers)) {
problems.add("Must be a class, not an interface");
}
if (source.getEnclosingClass() != null) {
if (Modifier.isStatic(modifiers)) {
if (Modifier.isPrivate(modifiers)) {
problems.add("Class cannot be private");
}
} else {
problems.add("Enclosed classes must be static and non private");
}
}
Constructor<?>[] constructors = source.getDeclaredConstructors();
for (Constructor<?> constructor : constructors) {
if (constructor.getParameterTypes().length > 0) {
problems.add("Cannot declare a constructor that takes arguments");
break;
}
}
Field[] fields = source.getDeclaredFields();
for (Field field : fields) {
int fieldModifiers = field.getModifiers();
if (!field.isSynthetic() && !(Modifier.isStatic(fieldModifiers) && Modifier.isFinal(fieldModifiers))) {
problems.add(field, "Fields must be static final.");
}
}
}
示例5: ensureNoInstanceScopedFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void ensureNoInstanceScopedFields(StructBindingValidationProblemCollector problems, Class<?> typeClass) {
List<Field> declaredFields = Arrays.asList(typeClass.getDeclaredFields());
for (Field field : declaredFields) {
int fieldModifiers = field.getModifiers();
if (!field.isSynthetic() && !(Modifier.isStatic(fieldModifiers) && Modifier.isFinal(fieldModifiers))) {
problems.add(field, "Fields must be static final.");
}
}
}
示例6: filterSynthetics
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void filterSynthetics(List<Field> fields) {
if (fields == null || fields.isEmpty()) return;
Iterator<Field> iterator = fields.iterator();
while (iterator.hasNext()) {
Field f = iterator.next();
if (f.isSynthetic()) iterator.remove();
}
}
示例7: relevantFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
static ImmutableSet<Field> relevantFields(Class<?> cls) {
ImmutableSet.Builder<Field> builder = ImmutableSet.builder();
for (Field field : cls.getDeclaredFields()) {
/*
* Coverage mode generates synthetic fields. If we ever add private
* fields, they will cause similar problems, and we may want to switch
* this check to isAccessible().
*/
if (!field.isSynthetic() && field.getType() == String.class) {
builder.add(field);
}
}
return builder.build();
}
示例8: isHiddenField
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Is this field to be hidden from the graph?
*/
private static boolean isHiddenField(Field field) {
if (field.isSynthetic() || has(field, Hidden.class) || isStatic(field.getModifiers())) {
return true;
}
return SYSTEM_PROPERTIES.contains(propertyKey(field)) ||
SYSTEM_CLASSES.contains(field.getDeclaringClass()) ||
isFunctional(field.getType());
}
示例9: registerField
import java.lang.reflect.Field; //導入方法依賴的package包/類
private void registerField(Map<String, Getter> getters, Map<String, Setter> setters, Field field) {
if(Modifier.isTransient(field.getModifiers()) ||
Modifier.isStatic(field.getModifiers()) ||
field.isSynthetic() ||
field.isEnumConstant()) return;
final String name = serializedName(field);
final boolean gettable = !getters.containsKey(name);
final boolean settable = !setters.containsKey(name);
if(gettable || settable) {
if(logger.isLoggable(Level.FINE)) {
String access;
if(gettable && settable) {
access = "get/set";
} else if(gettable) {
access = "get";
} else {
access = "set";
}
logger.fine(" " + name + " -- " + access + " --> " + field);
}
if(gettable) {
getters.put(name, new FieldGetter(this, field));
}
if(settable) {
setters.put(name, new FieldSetter(this, field));
}
}
}
示例10: excludeField
import java.lang.reflect.Field; //導入方法依賴的package包/類
public boolean excludeField(Field field, boolean serialize) {
if ((this.modifiers & field.getModifiers()) != 0) {
return true;
}
if (this.version != IGNORE_VERSIONS && !isValidVersion((Since) field.getAnnotation(Since
.class), (Until) field.getAnnotation(Until.class))) {
return true;
}
if (field.isSynthetic()) {
return true;
}
if (this.requireExpose) {
Expose annotation = (Expose) field.getAnnotation(Expose.class);
if (annotation == null || (serialize ? !annotation.serialize() : !annotation
.deserialize())) {
return true;
}
}
if (!this.serializeInnerClasses && isInnerClass(field.getType())) {
return true;
}
if (isAnonymousOrLocal(field.getType())) {
return true;
}
List<ExclusionStrategy> list = serialize ? this.serializationStrategies : this
.deserializationStrategies;
if (!list.isEmpty()) {
FieldAttributes fieldAttributes = new FieldAttributes(field);
for (ExclusionStrategy exclusionStrategy : list) {
if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
return true;
}
}
}
return false;
}
示例11: resetCounters
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static void resetCounters() throws Exception {
Class<?> cl = SplitLogCounters.class;
for (Field fld : cl.getDeclaredFields()) {
/* Guard against source instrumentation. */
if ((!fld.isSynthetic()) && (AtomicLong.class.isAssignableFrom(fld.getType()))) {
((AtomicLong)fld.get(null)).set(0);
}
}
}
示例12: isPublicInstanceField
import java.lang.reflect.Field; //導入方法依賴的package包/類
protected static boolean isPublicInstanceField(Field field) {
return Modifier.isPublic(field.getModifiers())
&& !Modifier.isStatic(field.getModifiers())
&& !Modifier.isFinal(field.getModifiers())
&& !field.isSynthetic();
}
示例13: isPublicInstanceField
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static boolean isPublicInstanceField(Field field) {
return Modifier.isPublic(field.getModifiers())
&& !Modifier.isStatic(field.getModifiers())
&& !Modifier.isFinal(field.getModifiers())
&& !field.isSynthetic();
}
示例14: saveFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
static void saveFields( IJsonIO obj, Class cls, Bindings bindings )
{
Class superclass = cls.getSuperclass();
if( superclass != null )
{
saveFields( obj, superclass, bindings );
}
Field[] fields = cls.getDeclaredFields();
for( Field f : fields )
{
if( f.isSynthetic() || Modifier.isStatic( f.getModifiers() ) || Modifier.isTransient( f.getModifiers() ) )
{
continue;
}
f.setAccessible( true );
try
{
Object value = f.get( obj );
if( isSimpleType( value ) )
{
bindings.put( f.getName(), value );
}
else if( value instanceof Enum )
{
bindings.put( f.getName(), ((Enum)value).name() );
}
else if( value instanceof Boolean )
{
bindings.put( f.getName(), (Boolean)value ? 1 : 0 );
}
else if( value instanceof List )
{
if( !((List)value).isEmpty() )
{
if( isSimpleType( ((List)value).get( 0 ) ) )
{
bindings.put( f.getName(), value );
}
else
{
writeList( f.getName(), (List)value, bindings );
}
}
else
{
bindings.put( f.getName(), value );
}
}
else if( value instanceof IJsonIO )
{
write( f.getName(), (IJsonIO)value, bindings );
}
else
{
throw new UnsupportedOperationException( "Type: " + value.getClass() + " does not implement " + IJsonIO.class.getName() );
}
}
catch( IllegalAccessException e )
{
throw new RuntimeException( e );
}
}
}
示例15: excludeField
import java.lang.reflect.Field; //導入方法依賴的package包/類
public boolean excludeField(Field field, boolean serialize) {
if ((modifiers & field.getModifiers()) != 0) {
return true;
}
if (version != Excluder.IGNORE_VERSIONS
&& !isValidVersion(field.getAnnotation(Since.class), field.getAnnotation(Until.class))) {
return true;
}
if (field.isSynthetic()) {
return true;
}
if (requireExpose) {
Expose annotation = field.getAnnotation(Expose.class);
if (annotation == null || (serialize ? !annotation.serialize() : !annotation.deserialize())) {
return true;
}
}
if (!serializeInnerClasses && isInnerClass(field.getType())) {
return true;
}
if (isAnonymousOrLocal(field.getType())) {
return true;
}
List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
if (!list.isEmpty()) {
FieldAttributes fieldAttributes = new FieldAttributes(field);
for (ExclusionStrategy exclusionStrategy : list) {
if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
return true;
}
}
}
return false;
}