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


Java Modifier.classModifiers方法代碼示例

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


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

示例1: getModifiersTest

import java.lang.reflect.Modifier; //導入方法依賴的package包/類
@Test
public void getModifiersTest() {
    for (Class<?> c : classes) {
        ResolvedJavaType type = metaAccess.lookupJavaType(c);
        int mask = Modifier.classModifiers() & ~Modifier.STATIC;
        int expected = c.getModifiers() & mask;
        int actual = type.getModifiers() & mask;
        Class<?> elementalType = c;
        while (elementalType.isArray()) {
            elementalType = elementalType.getComponentType();
        }
        if (elementalType.isMemberClass()) {
            // member class get their modifiers from the inner-class attribute in the JVM and
            // from the classfile header in jvmci
            expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
            actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
        }
        assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:TestResolvedJavaType.java

示例2: toGenericString

import java.lang.reflect.Modifier; //導入方法依賴的package包/類
/**
 * Returns a string describing this {@code Class}, including
 * information about modifiers and type parameters.
 *
 * The string is formatted as a list of type modifiers, if any,
 * followed by the kind of type (empty string for primitive types
 * and {@code class}, {@code enum}, {@code interface}, or
 * <code>&#64;</code>{@code interface}, as appropriate), followed
 * by the type's name, followed by an angle-bracketed
 * comma-separated list of the type's type parameters, if any.
 *
 * A space is used to separate modifiers from one another and to
 * separate any modifiers from the kind of type. The modifiers
 * occur in canonical order. If there are no type parameters, the
 * type parameter list is elided.
 *
 * <p>Note that since information about the runtime representation
 * of a type is being generated, modifiers not present on the
 * originating source code or illegal on the originating source
 * code may be present.
 *
 * @return a string describing this {@code Class}, including
 * information about modifiers and type parameters
 *
 * @since 1.8
 */
public String toGenericString() {
    if (isPrimitive()) {
        return toString();
    } else {
        StringBuilder sb = new StringBuilder();

        // Class modifiers are a superset of interface modifiers
        int modifiers = getModifiers() & Modifier.classModifiers();
        if (modifiers != 0) {
            sb.append(Modifier.toString(modifiers));
            sb.append(' ');
        }

        if (isAnnotation()) {
            sb.append('@');
        }
        if (isInterface()) { // Note: all annotation types are interfaces
            sb.append("interface");
        } else {
            if (isEnum())
                sb.append("enum");
            else
                sb.append("class");
        }
        sb.append(' ');
        sb.append(getName());

        TypeVariable<?>[] typeparms = getTypeParameters();
        if (typeparms.length > 0) {
            boolean first = true;
            sb.append('<');
            for(TypeVariable<?> typeparm: typeparms) {
                if (!first)
                    sb.append(',');
                sb.append(typeparm.getTypeName());
                first = false;
            }
            sb.append('>');
        }

        return sb.toString();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:70,代碼來源:Class.java


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