private ArrayList<RuntimeConstructorInfo> populateConstructors(final Filter filter) { final Type<?> reflectedType = getReflectedType(); final ArrayList<RuntimeConstructorInfo> list = new ArrayList<>(); if (reflectedType.isGenericParameter()) { return list; } for (final ConstructorInfo constructor : reflectedType.getDeclaredConstructors()) { final String name = constructor.getName(); if (!filter.match(name)) { continue; } final int modifiers = constructor.getModifiers(); assert constructor.getDeclaringType() != Type.NullType; final boolean isPublic = Modifier.isPublic(modifiers); final boolean isStatic = false; final boolean isInherited = false; final Set<BindingFlags> bindingFlags = Type.filterPreCalculate(isPublic, isInherited, isStatic); final RuntimeConstructorInfo runtimeConstructorInfo = new RuntimeConstructorInfo( constructor.getRawConstructor(), _typeCache, modifiers, bindingFlags, constructor.getParameters() ); list.add(runtimeConstructorInfo); } return list; }
@Override public boolean isEquivalentTo(final MemberInfo m) { if (m == this) { return true; } if ((m instanceof RuntimeConstructorInfo)) { final RuntimeConstructorInfo other = (RuntimeConstructorInfo) m; if (other._reflectedTypeCache == _reflectedTypeCache && other._rawConstructor == _rawConstructor) { return true; } } return super.isEquivalentTo(m); } }
@Override public StringBuilder appendErasedDescription(final StringBuilder sb) { final Constructor<?> rawConstructor = getRawConstructor(); final TypeList parameterTypes = Type.list(rawConstructor.getParameterTypes()); StringBuilder s = PrimitiveTypes.Void.appendBriefDescription(sb); s.append(' '); s.append(getName()); s.append('('); for (int i = 0, n = parameterTypes.size(); i < n; ++i) { if (i != 0) { s.append(", "); } s = parameterTypes.get(i).appendErasedDescription(s); } s.append(')'); return s; }
@Override public StringBuilder appendDescription(final StringBuilder sb) { StringBuilder s = PrimitiveTypes.Void.appendBriefDescription(sb); s.append(' '); s.append(getName()); s.append('('); final ParameterList parameters = getParameters(); for (int i = 0, n = parameters.size(); i < n; ++i) { final ParameterInfo p = parameters.get(i); if (i != 0) { s.append(", "); } s = p.getParameterType().appendBriefDescription(s); } s.append(')'); final TypeList thrownTypes = getThrownTypes(); if (!thrownTypes.isEmpty()) { s.append(" throws "); for (int i = 0, n = thrownTypes.size(); i < n; ++i) { final Type t = thrownTypes.get(i); if (i != 0) { s.append(", "); } s = t.appendBriefDescription(s); } } return s; }
public ConstructorInfo visitConstructor(final Type<?> declaringType, final ConstructorInfo constructor, final TypeBindings bindings) { final ParameterList parameters = constructor.getParameters(); final TypeList thrown = constructor.getThrownTypes(); final Type<?>[] parameterTypes = new Type<?>[parameters.size()]; final Type<?>[] thrownTypes = new Type<?>[thrown.size()]; if (!TypeUtils.areEquivalent(constructor.getDeclaringType(), declaringType)) { return new ReflectedConstructor( declaringType, constructor.getRawConstructor(), constructor.getParameters(), thrown ); constructor.getRawConstructor(), new ParameterList(newParameters), new TypeList(thrownTypes)
@Override public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) { return getRawConstructor().getAnnotation(annotationClass); }
@Override public StringBuilder appendBriefDescription(final StringBuilder sb) { StringBuilder s = PrimitiveTypes.Void.appendBriefDescription(sb); s.append(' '); s.append(getName()); s.append('('); final ParameterList parameters = getParameters(); for (int i = 0, n = parameters.size(); i < n; ++i) { final ParameterInfo p = parameters.get(i); if (i != 0) { s.append(", "); } final Type parameterType = p.getParameterType(); if (parameterType.isGenericParameter()) { s.append(parameterType.getName()); } else { s = parameterType.appendSimpleDescription(s); } } s.append(')'); return s; } }
public ConstructorBuilder defineDefaultConstructor(final int modifiers) { verifyNotGeneric(); verifyNotCreated(); if (isInterface()) { throw Error.interfacesCannotDefineConstructors(); } final ConstructorInfo baseConstructor = _baseType.getConstructor(BindingFlags.AllExact); if (baseConstructor == null || baseConstructor.isPrivate()) { throw Error.baseTypeHasNoDefaultConstructor(_baseType); } final ConstructorBuilder constructor = new ConstructorBuilder( modifiers & Modifier.constructorModifiers(), baseConstructor.getParameters().getParameterTypes(), TypeList.empty(), this ); final CodeGenerator code = constructor.getCodeGenerator(); code.emitThis(); for (final ParameterInfo parameter : baseConstructor.getParameters()) { code.emitLoadArgument(parameter.getPosition()); } code.call(baseConstructor); code.emitReturn(); constructor.returnCodeGenerator = false; constructorBuilders.add(constructor); _constructors = new ConstructorList(ArrayUtilities.append(_constructors.toArray(), constructor)); return constructor; }
constructor.getParameters().getParameterTypes(), constructor ); constructor.getRawConstructor().setAccessible(true);
@Override public ParameterList getParameters() { verifyTypeCreated(); return generatedConstructor.getParameters(); }
public T newInstance(final Object... arguments) { if (Helper.isReifiable(this)) { try { final Type<?>[] argumentTypes; if (ArrayUtilities.isNullOrEmpty(arguments)) { argumentTypes = EmptyArrayCache.fromElementType(Type.class); } else { argumentTypes = new Type<?>[arguments.length]; } for (int i = 0, n = arguments.length; i < n; i++) { final Object argument = arguments[i]; argumentTypes[i] = argument != null ? getType(argument) : Type.NullType; } final ConstructorInfo constructor = getConstructor(argumentTypes); if (constructor != null) { return (T) constructor.invoke(arguments); } throw Error.couldNotResolveMatchingConstructor(); } catch (Throwable t) { throw Error.typeInstantiationFailed(this, t); } } throw Error.typeCannotBeInstantiated(this); }
@Override public StringBuilder appendDescription(final StringBuilder sb) { StringBuilder s = PrimitiveTypes.Void.appendBriefDescription(sb); s.append(' '); s.append(getName()); s.append('('); final ParameterList parameters = getParameters(); for (int i = 0, n = parameters.size(); i < n; ++i) { final ParameterInfo p = parameters.get(i); if (i != 0) { s.append(", "); } s = p.getParameterType().appendBriefDescription(s); } s.append(')'); final TypeList thrownTypes = getThrownTypes(); if (!thrownTypes.isEmpty()) { s.append(" throws "); for (int i = 0, n = thrownTypes.size(); i < n; ++i) { final Type t = thrownTypes.get(i); if (i != 0) { s.append(", "); } s = t.appendBriefDescription(s); } } return s; }
public ConstructorInfo visitConstructor(final Type<?> declaringType, final ConstructorInfo constructor, final TypeBindings bindings) { final ParameterList parameters = constructor.getParameters(); final TypeList thrown = constructor.getThrownTypes(); final Type<?>[] parameterTypes = new Type<?>[parameters.size()]; final Type<?>[] thrownTypes = new Type<?>[thrown.size()]; final Type oldDeclaringType = constructor.getDeclaringType(); if (!TypeUtils.areEquivalent(constructor.getDeclaringType(), declaringType)) { return new ReflectedConstructor( actualDeclaringType, constructor.getRawConstructor(), constructor.getParameters(), thrown ); constructor.getRawConstructor(), new ParameterList(newParameters), new TypeList(thrownTypes)
@Override public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) { return getRawConstructor().getAnnotation(annotationClass); }
@Override public StringBuilder appendErasedDescription(final StringBuilder sb) { final Constructor<?> rawConstructor = getRawConstructor(); final TypeList parameterTypes = Type.list(rawConstructor.getParameterTypes()); StringBuilder s = PrimitiveTypes.Void.appendBriefDescription(sb); s.append(' '); s.append(getName()); s.append('('); for (int i = 0, n = parameterTypes.size(); i < n; ++i) { if (i != 0) { s.append(", "); } s = parameterTypes.get(i).appendErasedDescription(s); } s.append(')'); return s; }
@Override public StringBuilder appendBriefDescription(final StringBuilder sb) { StringBuilder s = PrimitiveTypes.Void.appendBriefDescription(sb); s.append(' '); s.append(getName()); s.append('('); final ParameterList parameters = getParameters(); for (int i = 0, n = parameters.size(); i < n; ++i) { final ParameterInfo p = parameters.get(i); if (i != 0) { s.append(", "); } final Type parameterType = p.getParameterType(); if (parameterType.isGenericParameter()) { s.append(parameterType.getName()); } else { s = parameterType.appendSimpleDescription(s); } } s.append(')'); return s; } }
public ConstructorBuilder defineDefaultConstructor(final int modifiers) { verifyNotGeneric(); verifyNotCreated(); if (isInterface()) { throw Error.interfacesCannotDefineConstructors(); } final ConstructorInfo baseConstructor = _baseType.getConstructor(BindingFlags.AllExact); if (baseConstructor == null || baseConstructor.isPrivate()) { throw Error.baseTypeHasNoDefaultConstructor(_baseType); } final ConstructorBuilder constructor = new ConstructorBuilder( modifiers & Modifier.constructorModifiers(), baseConstructor.getParameters().getParameterTypes(), TypeList.empty(), this ); final CodeGenerator code = constructor.getCodeGenerator(); code.emitThis(); for (final ParameterInfo parameter : baseConstructor.getParameters()) { code.emitLoadArgument(parameter.getPosition()); } code.call(baseConstructor); code.emitReturn(); constructor.returnCodeGenerator = false; constructorBuilders.add(constructor); _constructors = new ConstructorList(ArrayUtilities.append(_constructors.toArray(), constructor)); return constructor; }
constructor.getParameters().getParameterTypes(), constructor ); constructor.getRawConstructor().setAccessible(true);
@Override public ParameterList getParameters() { verifyTypeCreated(); return generatedConstructor.getParameters(); }
public T newInstance(final Object... arguments) { if (Helper.isReifiable(this)) { try { final Type<?>[] argumentTypes; if (ArrayUtilities.isNullOrEmpty(arguments)) { argumentTypes = EmptyArrayCache.fromElementType(Type.class); } else { argumentTypes = new Type<?>[arguments.length]; } for (int i = 0, n = arguments.length; i < n; i++) { final Object argument = arguments[i]; argumentTypes[i] = argument != null ? getType(argument) : Type.NullType; } final ConstructorInfo constructor = getConstructor(argumentTypes); if (constructor != null) { return (T) constructor.invoke(arguments); } throw Error.couldNotResolveMatchingConstructor(); } catch (Throwable t) { throw Error.typeInstantiationFailed(this, t); } } throw Error.typeCannotBeInstantiated(this); }