当前位置: 首页>>代码示例>>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;未经允许,请勿转载。