当前位置: 首页>>代码示例>>Java>>正文


Java Field.getModifiers方法代码示例

本文整理汇总了Java中java.lang.reflect.Field.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java Field.getModifiers方法的具体用法?Java Field.getModifiers怎么用?Java Field.getModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Field的用法示例。


在下文中一共展示了Field.getModifiers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStatments

import java.lang.reflect.Field; //导入方法依赖的package包/类
protected static Map<String, SQLStmt> getStatments(Procedure proc) {
    Class<? extends Procedure> c = proc.getClass();
    Map<String, SQLStmt> stmts = new HashMap<String, SQLStmt>();
    for (Field f : c.getDeclaredFields()) {
        int modifiers = f.getModifiers();
        if (Modifier.isTransient(modifiers) == false &&
            Modifier.isPublic(modifiers) == true &&
            Modifier.isStatic(modifiers) == false) {
            try {
                Object o = f.get(proc);
                if (o instanceof SQLStmt) {
                    stmts.put(f.getName(), (SQLStmt)o);
                }
            } catch (Exception ex) {
                throw new RuntimeException("Failed to retrieve " + f + " from " + c.getSimpleName(), ex);
            }
        }
    } // FOR
    return (stmts);
}
 
开发者ID:faclc4,项目名称:HTAPBench,代码行数:21,代码来源:Procedure.java

示例2: write

import java.lang.reflect.Field; //导入方法依赖的package包/类
public void write(Object object) throws IllegalArgumentException, IllegalAccessException {

		alreadyWritten.clear();
		alreadyWritten.put(object, object);

		Class<?> clazz = object.getClass();
		while (clazz != Object.class) {
			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				field.setAccessible(true);
				int modifiers = field.getModifiers();
				if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || Modifier.isVolatile(modifiers)) {
					// Skip
					continue;
				}
				if (field.isSynthetic()) {
					// Skip
					continue;
				}

				writeProperty(field.getName(), field.get(object));
			}

			clazz = clazz.getSuperclass();
		}
	}
 
开发者ID:Puppygames,项目名称:thjson,代码行数:27,代码来源:POJOtoTHJSONConverter.java

示例3: buildAndBind

import java.lang.reflect.Field; //导入方法依赖的package包/类
protected <T> void buildAndBind(Class<?> currentClazz, String path, List<Component> components,
		Set<Class<?>> nestedClasses) {
	List<Field> fields = getFieldsInDeclareOrder(currentClazz);

	for (Field field : fields) {
		if ((field.getModifiers() & Modifier.STATIC) != 0) {
			continue;
		}
		if (boundProperties.containsKey(path + field.getName())) {
			// property already bound, skip
			continue;
		}
		if (nestedClasses.contains(field.getType())) {
			buildAndBind(field.getType(), path + field.getName() + ".", components,
					nestedClasses);
		} else {
			components.add(createAndBind(field, path));
		}
	}
}
 
开发者ID:ljessendk,项目名称:easybinder,代码行数:21,代码来源:AutoBinder.java

示例4: validate

import java.lang.reflect.Field; //导入方法依赖的package包/类
private void validate(Object object, Class<?> clazz) throws Exception {
    for (Field field : FieldUtils.getAllFields(clazz)) {
        int modifiers = field.getModifiers();

        // Ignore static fields
        if (Modifier.isStatic(modifiers)) {
            continue;
        }

        assertTrue("Field is private", Modifier.isPrivate(modifiers));
        assertTrue("Field is final", Modifier.isFinal(modifiers));

        Method getter = clazz.getMethod(getterName(field.getName()));
        assertNotNull("Getter exists", getter);
        assertTrue("Getter is public", Modifier.isPublic(getter.getModifiers()));
    }

    // Check that hashCode, toString and equals are defined
    assertNotNull(clazz.getDeclaredMethod("hashCode").invoke(object));
    assertNotNull(clazz.getDeclaredMethod("toString").invoke(object));
    assertTrue((Boolean) clazz.getDeclaredMethod("equals", Object.class).invoke(object, object));
}
 
开发者ID:carlanton,项目名称:mpd-tools,代码行数:23,代码来源:DataTypeTest.java

示例5: HackedField

import java.lang.reflect.Field; //导入方法依赖的package包/类
/** @param modifiers the modifiers this field must have */
HackedField(final Class<C> clazz, final String name, int modifiers) throws HackAssertionException {
	Field field = null;
	try {
		if (clazz == null) return;
		field = clazz.getDeclaredField(name);
		if (modifiers > 0 && (field.getModifiers() & modifiers) != modifiers)
			fail(new HackAssertionException(field + " does not match modifiers: " + modifiers));
		field.setAccessible(true);
	} catch (final NoSuchFieldException e) {
		HackAssertionException hae = new HackAssertionException(e);
		hae.setHackedClass(clazz);
		hae.setHackedFieldName(name);
		fail(hae);
	} finally { mField = field; }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:17,代码来源:Hack.java

示例6: HackedField

import java.lang.reflect.Field; //导入方法依赖的package包/类
/**
 * @param modifiers the modifiers this field must have
 */
HackedField(final Class<C> clazz, final String name, int modifiers) throws HackAssertionException {
  Field field = null;
  try {
    if (clazz == null) {
      return;
    }
    field = clazz.getDeclaredField(name);
    if (modifiers > 0 && (field.getModifiers() & modifiers) != modifiers) {
      fail(new HackAssertionException(field + " does not match modifiers: " + modifiers));
    }
    field.setAccessible(true);
  } catch (final NoSuchFieldException e) {
    HackAssertionException hae = new HackAssertionException(e);
    hae.setHackedClass(clazz);
    hae.setHackedFieldName(name);
    fail(hae);
  } finally {
    mField = field;
  }
}
 
开发者ID:erguotou520,项目名称:weex-uikit,代码行数:24,代码来源:WXHack.java

示例7: ListenerSet

import java.lang.reflect.Field; //导入方法依赖的package包/类
public ListenerSet() {
    eventTypes = new Vector<>();
    try {
        Class<?> eventClass = Class.forName("java.awt.AWTEvent");
        Field[] fields = eventClass.getFields();
        theWholeMask = 0;
        long eventMask;
        for (Field field : fields) {
            if ((field.getModifiers()
                    & (Modifier.PUBLIC | Modifier.STATIC)) != 0
                    && field.getType().equals(Long.TYPE)
                    && field.getName().endsWith("_EVENT_MASK")) {
                eventMask = (Long) field.get(null);
                eventTypes.add(new EventType(eventMask));
                theWholeMask = theWholeMask | eventMask;
            }
        }
    } catch (ClassNotFoundException | IllegalAccessException e) {
        JemmyProperties.getCurrentOutput().printStackTrace(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:EventTool.java

示例8: getDeclaredSUID

import java.lang.reflect.Field; //导入方法依赖的package包/类
/**
 * Returns explicit serial version UID value declared by given class, or
 * null if none.
 */
private static Long getDeclaredSUID(Class<?> cl) {
    try {
        Field f = cl.getDeclaredField("serialVersionUID");
        int mask = Modifier.STATIC | Modifier.FINAL;
        if ((f.getModifiers() & mask) == mask) {
            f.setAccessible(true);
            return Long.valueOf(f.getLong(null));
        }
    } catch (Exception ex) {
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:ObjectStreamClass.java

示例9: ClassFormat

import java.lang.reflect.Field; //导入方法依赖的package包/类
public ClassFormat(Class<?> type) {
    this.name = type.getSimpleName();

    int approxSize = 0;

    LinkedList<FieldFormat> fields = new LinkedList<>();

    do {
        Field[] declaredFields = type.getDeclaredFields();

        if (declaredFields.length > 0) {
            List<FieldFormat> typeFields = new ArrayList<>(declaredFields.length);

            for (Field field : declaredFields) {
                if (!field.isSynthetic()) {
                    int mod = field.getModifiers();

                    if (!Modifier.isStatic(mod) && field.getAnnotation(ToStringIgnore.class) == null) {
                        field.setAccessible(true);

                        typeFields.add(new FieldFormat(field));

                        // This is really approximate.
                        approxSize += field.getName().length() * 2;
                    }
                }
            }

            if (!typeFields.isEmpty()) {
                fields.addAll(0, typeFields);
            }
        }

        type = type.getSuperclass();
    }
    while (type != null && type != Object.class);

    this.fields = fields;
    this.approxSize = approxSize;
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:41,代码来源:ToString.java

示例10: matchInheritance

import java.lang.reflect.Field; //导入方法依赖的package包/类
public static boolean matchInheritance(final Field subclassField, final Field superclassField) {
	if (Modifier.isStatic(superclassField.getModifiers()) || subclassField.equals(superclassField)) {
		return false;
	}

	final Package subclassPackage = superclassField.getDeclaringClass().getPackage();
	final Package superclassPackage = superclassField.getDeclaringClass().getPackage();
	final int superFieldModifiers = superclassField.getModifiers();

	return isAccessable(subclassPackage, superclassPackage, superFieldModifiers);
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:12,代码来源:Reflections.java

示例11: toString

import java.lang.reflect.Field; //导入方法依赖的package包/类
@Override
public String toString() {
	final Class<?> thisClass = getClass();
	final Map<String,Object> values = new Object2ObjectOpenHashMap<>();
	for (final Field f : thisClass.getDeclaredFields()) {
		if ((f.getModifiers() & Modifier.PUBLIC) == 0 || (f.getModifiers() & Modifier.STATIC) != 0) continue;
		try {
			values.put(f.getName(), f.get(this));
		} catch (final IllegalAccessException e) {
			values.put(f.getName(), "<THIS SHOULD NOT HAPPEN>");
		}
	}
	return values.toString();
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:15,代码来源:StartupConfiguration.java

示例12: save

import java.lang.reflect.Field; //导入方法依赖的package包/类
/**
 * Save current settings to configuration.
 */
public void save() {
	try {
		if (!confFile.exists() && !confFile.createNewFile()) {
			// Return if config file cannot be found and cannot be created.
			return;
		}
		JsonObject json = Json.object();
		for (Field field : this.getClass().getDeclaredFields()) {
			// Skip private and static fields.
			int mod = field.getModifiers();
			if (Modifier.isPrivate(mod) || Modifier.isStatic(mod)) {
				continue;
			}
			// Access via reflection, add value to json object.
			field.setAccessible(true);
			String name = field.getName();
			Object value = field.get(this);
			if (value instanceof Boolean) {
				json.set(name, (boolean) value);
			} else if (value instanceof Integer) {
				json.set(name, (int) value);
			} else if (value instanceof String) {
				json.set(name, (String) value);
			} else {
				JsonValue converted = convert(field.getType(), value);
				if (converted != null) {
					json.set(name, converted);
				}
			}
		}
		// Write json to file
		StringWriter w = new StringWriter();
		json.writeTo(w, WriterConfig.PRETTY_PRINT);
		Files.writeFile(confFile.getAbsolutePath(), w.toString());
	} catch (Exception e) {
		Recaf.INSTANCE.logging.error(e);
	}
}
 
开发者ID:Col-E,项目名称:Recaf,代码行数:42,代码来源:Config.java

示例13: CASUpdater

import java.lang.reflect.Field; //导入方法依赖的package包/类
CASUpdater(final Class<T> tclass, final String fieldName,
           final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:AtomicLongFieldUpdater.java

示例14: AtomicReferenceFieldUpdaterImpl

import java.lang.reflect.Field; //导入方法依赖的package包/类
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();
    if (vclass.isPrimitive())
        throw new IllegalArgumentException("Must be reference type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.vclass = vclass;
    this.offset = U.objectFieldOffset(field);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:54,代码来源:AtomicReferenceFieldUpdater.java

示例15: computeStructuralUID

import java.lang.reflect.Field; //导入方法依赖的package包/类
public static long computeStructuralUID(boolean hasWriteObject, Class<?> cl) {
    ByteArrayOutputStream devnull = new ByteArrayOutputStream(512);

    long h = 0;
    try {

        if ((!java.io.Serializable.class.isAssignableFrom(cl)) ||
            (cl.isInterface())){
            return 0;
        }

        if (java.io.Externalizable.class.isAssignableFrom(cl)) {
            return 1;
        }

        MessageDigest md = MessageDigest.getInstance("SHA");
        DigestOutputStream mdo = new DigestOutputStream(devnull, md);
        DataOutputStream data = new DataOutputStream(mdo);

        //In the old case, for the caller class, the write Method wasn't considered
        // for rep-id calculations correctly, but for parent classes it was taken
        // into account.  That is the reason there is the klude of getting the write
        // Object method in there

        // Get SUID of parent
        Class<?> parent = cl.getSuperclass();
        if ((parent != null) && (parent != java.lang.Object.class)) {
            boolean hasWriteObjectFlag = false;
            Class [] args = {java.io.ObjectOutputStream.class};
            Method hasWriteObjectMethod = ObjectStreamClassUtil_1_3.getDeclaredMethod(parent, "writeObject", args,
                   Modifier.PRIVATE, Modifier.STATIC);
            if (hasWriteObjectMethod != null)
                hasWriteObjectFlag = true;
            data.writeLong(ObjectStreamClassUtil_1_3.computeStructuralUID(hasWriteObjectFlag, parent));
        }

        if (hasWriteObject)
            data.writeInt(2);
        else
            data.writeInt(1);

        /* Sort the field names to get a deterministic order */
        Field[] field = ObjectStreamClassUtil_1_3.getDeclaredFields(cl);
        Arrays.sort(field, compareMemberByName);

        for (int i = 0; i < field.length; i++) {
            Field f = field[i];

                            /* Include in the hash all fields except those that are
                             * transient or static.
                             */
            int m = f.getModifiers();
            if (Modifier.isTransient(m) || Modifier.isStatic(m))
                continue;

            data.writeUTF(f.getName());
            data.writeUTF(getSignature(f.getType()));
        }

        /* Compute the hash value for this class.
         * Use only the first 64 bits of the hash.
         */
        data.flush();
        byte hasharray[] = md.digest();
        int minimum = Math.min(8, hasharray.length);
        for (int i = minimum; i > 0; i--) {
            h += (long)(hasharray[i] & 255) << (i * 8);
        }
    } catch (IOException ignore) {
        /* can't happen, but be deterministic anyway. */
        h = -1;
    } catch (NoSuchAlgorithmException complain) {
        throw new SecurityException(complain.getMessage());
    }
    return h;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:ObjectStreamClassUtil_1_3.java


注:本文中的java.lang.reflect.Field.getModifiers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。