Java Code Examples for java.lang.reflect.Constructor#getModifiers()

The following examples show how to use java.lang.reflect.Constructor#getModifiers() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void makeConstructors(String thisClassName, ClassFile cf,
        ConstPool cp, String classname) throws CannotCompileException
{
    Constructor<?>[] cons = SecurityActions.getDeclaredConstructors(superClass);
    // legacy: if we are not caching then we need to initialise the default handler
    boolean doHandlerInit = !factoryUseCache;
    for (int i = 0; i < cons.length; i++) {
        Constructor<?> c = cons[i];
        int mod = c.getModifiers();
        if (!Modifier.isFinal(mod) && !Modifier.isPrivate(mod)
                && isVisible(mod, basename, c)) {
            MethodInfo m = makeConstructor(thisClassName, c, cp, superClass, doHandlerInit);
            cf.addMethod(m);
        }
    }
}
 
Example 2
Source Project: flex-blazeds   File: ClassUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean hasValidDefaultConstructor(Class cls)
{
    try
    {
        if (cls != null)
        {
            Constructor c = cls.getConstructor();
            int mod = c.getModifiers();
            return Modifier.isPublic(mod);
        }
    }
    catch (Throwable t)
    {
        return false;
    }

    return false;
}
 
Example 3
/**
 * 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)) {
        Class<?> prev = initCl;
        if ((initCl = initCl.getSuperclass()) == null ||
            (!disableSerialConstructorChecks && !superHasAccessibleConstructor(prev))) {
            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;
    }
}
 
Example 4
/**
 * 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;
    }
}
 
Example 5
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);
}
 
Example 6
/**
 * @return The class to build
 * @throws IOException If failed to generate class
 * @throws ClassNotFoundException If failed to load class
 */

public Class build() throws IOException, ClassNotFoundException {
    addField(FUNC_REFS, Modifier.PRIVATE|Modifier.TRANSIENT, ScriptContext.Func[].class);
    if(!isInterface){
        for (Constructor<?> constructor : getConstructorsToOverwrite(superType)) {
            if (constructor.getModifiers() == Modifier.FINAL) {
                continue;
            }
            TypeId<?>[] types = getTypeIds(constructor.getParameterTypes());
            MethodId<?, ?> method = type.getConstructor(types);
            Code constructorCode = maker.declare(method, PUBLIC);
            Local<?> thisRef = constructorCode.getThis(type);
            Local<?>[] params = new Local[types.length];
            for (int i = 0; i < params.length; ++i) {
                params[i] = constructorCode.getParameter(i, types[i]);
            }
            MethodId superConstructor = TypeId.get(superType).getConstructor(types);
            constructorCode.invokeDirect(superConstructor, null, thisRef, params);
            constructorCode.returnVoid();
        }
    }
    ClassLoader loader = maker.generateAndLoad(getClass().getClassLoader(), null);
    return loader.loadClass(qualifyName(type.getName()));
}
 
Example 7
Source Project: Bytecoder   File: ObjectStreamClass.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 8
/**
 * 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;
    }
}
 
Example 9
/**
 * 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;
    }
}
 
Example 10
/**
 * 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;
    }
}
 
Example 11
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());
    }
}
 
Example 12
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());
    }
}
 
Example 13
Source Project: Java8CN   File: ObjectStreamClass.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 14
/**
 * 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;
    }
}
 
Example 15
/**
 * 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;
    }
}
 
Example 16
/**
 * 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;
    }
}
 
Example 17
/**
 * 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;
    }
}
 
Example 18
Source Project: JDKSourceCode1.8   File: ObjectStreamClass.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 19
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;
}
 
Example 20
Source Project: HtmlNative   File: JavaConstructor.java    License: Apache License 2.0 4 votes vote down vote up
private JavaConstructor(Constructor c) {
	super( c.getParameterTypes(), c.getModifiers() );
	this.constructor = c;
}