Java Code Examples for java.lang.reflect.Constructor#getModifiers()
The following examples show how to use
java.lang.reflect.Constructor#getModifiers() .
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 check out the related API usage on the sidebar.
Example 1
Source File: ClassBuilder.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @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 2
Source File: ProxyFactory.java From HotswapAgent with GNU General Public License v2.0 | 6 votes |
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 3
Source File: ReflectionFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 4
Source File: ClassUtil.java From flex-blazeds with Apache License 2.0 | 6 votes |
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 5
Source File: ObjectStreamClass.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 6
Source File: ObjectStreamClass.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * 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 7
Source File: ObjectStreamClass.java From Java8CN with Apache License 2.0 | 5 votes |
/** * 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
Source File: JavaAdapterBytecodeGenerator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 9
Source File: ObjectStreamClass.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * 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
Source File: ObjectStreamClass.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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
Source File: ObjectStreamClass.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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 12
Source File: ObjectStreamClass.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 13
Source File: ObjectStreamClass.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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
Source File: ObjectStreamClass.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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
Source File: JavaAdapterBytecodeGenerator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 16
Source File: JavaAdapterBytecodeGenerator.java From hottub with GNU General Public License v2.0 | 5 votes |
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 17
Source File: ObjectStreamClass.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 File: ObjectStreamClass.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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
Source File: ObjectStreamClass.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * 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 20
Source File: JavaConstructor.java From HtmlNative with Apache License 2.0 | 4 votes |
private JavaConstructor(Constructor c) { super( c.getParameterTypes(), c.getModifiers() ); this.constructor = c; }