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


Java Constructor.getModifiers方法代碼示例

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


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

示例1: addEditorToCache

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
private static void addEditorToCache(Class propertyType, PropertyEditor editor, String key) {
    if (editor == null) {
        addEditorClassToCache(propertyType, null, key);
    } else {
        // Caching the class for editor instance is a bit tricky - the instance
        // is created by PropertyEditorManager, but we may not be able to re-create
        // it just from a class. We assume it is possible if the class has a no-arg
        // public constructor. Otherwise we don't cache the property editor class.
        Class editorClass = editor.getClass();
        try {
            Constructor ctor = editorClass.getConstructor();
            if (ctor != null && (ctor.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC) {
                addEditorClassToCache(propertyType, editorClass, key);
            }
        } catch (NoSuchMethodException ex) {} // ignore
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:FormPropertyEditorManager.java

示例2: getSerializableConstructor

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/**
 * Returns subclass-accessible no-arg constructor of first non-serializable
 * superclass, or null if none found.  Access checks are disabled on the
 * returned constructor (if any).
 */
private static Constructor getSerializableConstructor(Class<?> cl) {
    Class<?> initCl = cl;
    while (Serializable.class.isAssignableFrom(initCl)) {
        if ((initCl = initCl.getSuperclass()) == null) {
            return null;
        }
    }
    try {
        Constructor cons = initCl.getDeclaredConstructor(new Class<?>[0]);
        int mods = cons.getModifiers();
        if ((mods & Modifier.PRIVATE) != 0 ||
            ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
             !packageEquals(cl, initCl)))
        {
            return null;
        }
        cons = bridge.newConstructorForSerialization(cl, cons);
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:ObjectStreamClass.java

示例3: getSerializableConstructor

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/**
 * Returns subclass-accessible no-arg constructor of first non-serializable
 * superclass, or null if none found.  Access checks are disabled on the
 * returned constructor (if any).
 */
private static Constructor<?> getSerializableConstructor(Class<?> cl) {
    Class<?> initCl = cl;
    while (Serializable.class.isAssignableFrom(initCl)) {
        if ((initCl = initCl.getSuperclass()) == null) {
            return null;
        }
    }
    try {
        Constructor<?> cons = initCl.getDeclaredConstructor((Class<?>[]) null);
        int mods = cons.getModifiers();
        if ((mods & Modifier.PRIVATE) != 0 ||
            ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
             !packageEquals(cl, initCl)))
        {
            return null;
        }
        cons = reflFactory.newConstructorForSerialization(cl, cons);
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:ObjectStreamClass.java

示例4: newConstructorForSerialization

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/**
 * Returns an accessible no-arg constructor for a class.
 * The no-arg constructor is found searching the class and its supertypes.
 *
 * @param cl the class to instantiate
 * @return a no-arg constructor for the class or {@code null} if
 *     the class or supertypes do not have a suitable no-arg constructor
 */
public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
    Class<?> initCl = cl;
    while (Serializable.class.isAssignableFrom(initCl)) {
        if ((initCl = initCl.getSuperclass()) == null) {
            return null;
        }
    }
    Constructor<?> constructorToCall;
    try {
        constructorToCall = initCl.getDeclaredConstructor();
        int mods = constructorToCall.getModifiers();
        if ((mods & Modifier.PRIVATE) != 0 ||
                ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
                        !packageEquals(cl, initCl))) {
            return null;
        }
    } catch (NoSuchMethodException ex) {
        return null;
    }
    return generateConstructor(cl, constructorToCall);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:30,代碼來源:ReflectionFactory.java

示例5: newConstructorForSerialization

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
    Class<?> initCl = cl;
    while (Serializable.class.isAssignableFrom(initCl)) {
        if ((initCl = initCl.getSuperclass()) == null) {
            return null;
        }
    }
    Constructor<?> constructorToCall;
    try {
        constructorToCall = initCl.getDeclaredConstructor();
        int mods = constructorToCall.getModifiers();
        if ((mods & Modifier.PRIVATE) != 0 ||
                ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
                        !packageEquals(cl, initCl))) {
            return null;
        }
    } catch (NoSuchMethodException ex) {
        return null;
    }
    return generateConstructor(cl, constructorToCall);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ReflectionFactory.java

示例6: getExternalizableConstructor

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/**
 * Returns public no-arg constructor of given class, or null if none found.
 * Access checks are disabled on the returned constructor (if any), since
 * the defining class may still be non-public.
 */
private static Constructor getExternalizableConstructor(Class<?> cl) {
    try {
        Constructor cons = cl.getDeclaredConstructor(new Class<?>[0]);
        cons.setAccessible(true);
        return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
            cons : null;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:16,代碼來源:ObjectStreamClass.java

示例7: getExternalizableConstructor

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/**
 * Returns public no-arg constructor of given class, or null if none found.
 * Access checks are disabled on the returned constructor (if any), since
 * the defining class may still be non-public.
 */
private static Constructor<?> getExternalizableConstructor(Class<?> cl) {
    try {
        Constructor<?> cons = cl.getDeclaredConstructor((Class<?>[]) null);
        cons.setAccessible(true);
        return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
            cons : null;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:16,代碼來源:ObjectStreamClass.java

示例8: generateConstructors

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
private void generateConstructors() throws AdaptationException {
    boolean gotCtor = false;
    for (final Constructor<?> ctor: superClass.getDeclaredConstructors()) {
        final int modifier = ctor.getModifiers();
        if((modifier & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0 && !isCallerSensitive(ctor)) {
            generateConstructors(ctor);
            gotCtor = true;
        }
    }
    if(!gotCtor) {
        throw new AdaptationException(ERROR_NO_ACCESSIBLE_CONSTRUCTOR, superClass.getCanonicalName());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:JavaAdapterBytecodeGenerator.java

示例9: generateConstructors

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
private boolean generateConstructors() throws AdaptationException {
    boolean gotCtor = false;
    boolean canBeAutoConverted = false;
    for (final Constructor<?> ctor: superClass.getDeclaredConstructors()) {
        final int modifier = ctor.getModifiers();
        if((modifier & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0 && !isCallerSensitive(ctor)) {
            canBeAutoConverted = generateConstructors(ctor) | canBeAutoConverted;
            gotCtor = true;
        }
    }
    if(!gotCtor) {
        throw new AdaptationException(ERROR_NO_ACCESSIBLE_CONSTRUCTOR, superClass.getCanonicalName());
    }
    return canBeAutoConverted;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:JavaAdapterBytecodeGenerator.java

示例10: JavaConstructor

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
private JavaConstructor(Constructor c) {
	super( c.getParameterTypes(), c.getModifiers() );
	this.constructor = c;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:5,代碼來源:JavaConstructor.java

示例11: call

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
@SuppressWarnings({"ResultOfMethodCallIgnored", "unused"})
void call(Constructor<?> constructor) {
    constructor.getModifiers();
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:5,代碼來源:ShouldAccessClassesThatTest.java


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