static MethodBase findMostDerivedNewSlotMethod(final MethodBase[] match, final int cMatches) { int deepestHierarchy = 0; MethodBase methodWithDeepestHierarchy = null; for (int i = 0; i < cMatches; i++) { // Calculate the depth of the hierarchy of the declaring type of the // current method. final int currentHierarchyDepth = getHierarchyDepth(match[i].getDeclaringType()); // The two methods have the same name, signature, and hierarchy depth. // This can only happen if at least one is vararg or generic. if (currentHierarchyDepth == deepestHierarchy) { throw Error.ambiguousMatch(); } // Check to see if this method is on the most derived class. if (currentHierarchyDepth > deepestHierarchy) { deepestHierarchy = currentHierarchyDepth; methodWithDeepestHierarchy = match[i]; } } return methodWithDeepestHierarchy; }
private static <T> Type<T> makeCompoundTypeCore(final Type<T> baseType, final TypeList interfaces) { if (baseType.isGenericParameter()) { throw Error.compoundTypeMayNotHaveGenericParameterBound(); } for (int i = 0, n = interfaces.size(); i < n; i++) { final Type type = interfaces.get(i); if (type.isGenericParameter()) { throw Error.compoundTypeMayNotHaveGenericParameterBound(); } if (!type.isInterface()) { throw Error.compoundTypeMayOnlyHaveOneClassBound(); } } return new CompoundType<>(interfaces, baseType); }
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); }
throw Error.couldNotResolveType(sb); throw Error.invalidSignatureNonGenericTypeTypeArguments(resolvedType); throw Error.invalidSignatureUnexpectedToken(s, i); throw Error.couldNotResolveType(sb); throw Error.invalidSignatureUnexpectedEnd(s, i);
private TypeVariable<?> resolveTypeVariable() { for (final TypeVariable typeVariable : _declaringType.getErasedClass().getTypeParameters()) { if (_name.equals(typeVariable.getName())) { return typeVariable; } } throw Error.couldNotResolveType(_name); }
throw Error.invalidSignatureExpectedTypeArgument(s, i); throw Error.invalidSignatureExpectedTypeArgument(s, position.getValue()); default: throw Error.invalidSignatureUnexpectedToken(s, i);
private static void parseTypeParameters( final String s, final MutableInteger position, final Type<?> resolvedType, final Type<?>[] typeArguments) { int i = position.getValue(); assert s.charAt(i) == '<'; position.increment(); for (int j = 0; j < typeArguments.length; j++) { typeArguments[j] = parseTypeArgument(s, position, resolvedType, j); } i = position.getValue(); if (s.charAt(i) != '>') { throw Error.invalidSignatureExpectedEndOfTypeArguments(s, i); } position.increment(); }
public MethodInfo findBaseMethod(final Type<?> relativeTo) { VerifyArgument.notNull(relativeTo, "relativeTo"); final Type<?> declaringType = getDeclaringType(); if (!relativeTo.isAssignableFrom(declaringType)) { throw Error.invalidAncestorType(relativeTo, declaringType); } if (isStatic() || isPrivate()) { return null; } final ParameterList parameters = getParameters(); return relativeTo.getMethod( getName(), BindingFlags.AllInstance, getCallingConvention(), parameters.getParameterTypes().toArray(new Type[parameters.size()]) ); }
private TypeBindings(final TypeList genericParameters, final TypeList boundTypes) { _genericParameters = genericParameters; _boundTypes = boundTypes; final int parameterCount = _genericParameters.size(); if (parameterCount != boundTypes.size()) { throw Error.incorrectNumberOfTypeArguments(); } for (int i = 0; i < parameterCount; i++) { if (!genericParameters.get(i).isGenericParameter()) { throw new IllegalArgumentException("All types in the 'genericParameters' list must be generic parameters types."); } } int hash = 1; for (final Type boundType : boundTypes) { if (boundType != null) { hash = hash * 31 + boundType.hashCode(); } } _hashCode = hash; }
throw Error.couldNotResolveType(sb); throw Error.invalidSignatureNonGenericTypeTypeArguments(resolvedType); throw Error.invalidSignatureUnexpectedToken(s, i); throw Error.couldNotResolveType(sb); throw Error.invalidSignatureUnexpectedEnd(s, i);
@SuppressWarnings("unchecked") Class<T> getErasedClass() { if (_erasedClass == null) { final String fullName = getFullName(); try { _erasedClass = (Class<T>)Class.forName(fullName); } catch (ClassNotFoundException e) { throw Error.couldNotResolveType(fullName); } } return _erasedClass; }
throw Error.invalidSignatureExpectedTypeArgument(s, i); throw Error.invalidSignatureExpectedTypeArgument(s, position.getValue()); default: throw Error.invalidSignatureUnexpectedToken(s, i);
private static void parseTypeParameters( final String s, final MutableInteger position, final Type<?> resolvedType, final Type<?>[] typeArguments) { int i = position.getValue(); assert s.charAt(i) == '<'; position.increment(); for (int j = 0; j < typeArguments.length; j++) { typeArguments[j] = parseTypeArgument(s, position, resolvedType, j); } i = position.getValue(); if (s.charAt(i) != '>') { throw Error.invalidSignatureExpectedEndOfTypeArguments(s, i); } position.increment(); }
public MethodInfo findBaseMethod(final Type<?> relativeTo) { VerifyArgument.notNull(relativeTo, "relativeTo"); final Type<?> declaringType = getDeclaringType(); if (!relativeTo.isAssignableFrom(declaringType)) { throw Error.invalidAncestorType(relativeTo, declaringType); } if (isStatic() || isPrivate() || declaringType.isInterface()) { return null; } final ParameterList parameters = getParameters(); return relativeTo.getMethod( getName(), BindingFlags.AllInstance, getCallingConvention(), parameters.getParameterTypes().toArray(new Type[parameters.size()]) ); }
private TypeBindings(final TypeList genericParameters, final TypeList boundTypes) { _genericParameters = genericParameters; _boundTypes = boundTypes; final int parameterCount = _genericParameters.size(); if (parameterCount != boundTypes.size()) { throw Error.incorrectNumberOfTypeArguments(); } for (int i = 0; i < parameterCount; i++) { if (!genericParameters.get(i).isGenericParameter()) { throw new IllegalArgumentException("All types in the 'genericParameters' list must be generic parameters types."); } } int hash = 1; for (final Type boundType : boundTypes) { if (boundType != null) { hash = hash * 31 + boundType.hashCode(); } } _hashCode = hash; }
throw Error.couldNotResolveType(sb); throw Error.invalidSignatureNonGenericTypeTypeArguments(resolvedType); throw Error.invalidSignatureUnexpectedToken(s, i); throw Error.couldNotResolveType(sb); throw Error.invalidSignatureUnexpectedEnd(s, i);
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); }
static MethodBase findMostDerivedNewSlotMethod(final MethodBase[] match, final int cMatches) { int deepestHierarchy = 0; MethodBase methodWithDeepestHierarchy = null; for (int i = 0; i < cMatches; i++) { // Calculate the depth of the hierarchy of the declaring type of the // current method. final int currentHierarchyDepth = getHierarchyDepth(match[i].getDeclaringType()); // The two methods have the same name, signature, and hierarchy depth. // This can only happen if at least one is vararg or generic. if (currentHierarchyDepth == deepestHierarchy) { throw Error.ambiguousMatch(); } // Check to see if this method is on the most derived class. if (currentHierarchyDepth > deepestHierarchy) { deepestHierarchy = currentHierarchyDepth; methodWithDeepestHierarchy = match[i]; } } return methodWithDeepestHierarchy; }
private TypeVariable<?> resolveTypeVariable() { for (final TypeVariable typeVariable : _declaringType.getErasedClass().getTypeParameters()) { if (_name.equals(typeVariable.getName())) { return typeVariable; } } throw Error.couldNotResolveType(_name); }
private static <T> Type<T> makeCompoundTypeCore(final Type<T> baseType, final TypeList interfaces) { if (baseType.isGenericParameter()) { throw Error.compoundTypeMayNotHaveGenericParameterBound(); } for (int i = 0, n = interfaces.size(); i < n; i++) { final Type type = interfaces.get(i); if (type.isGenericParameter()) { throw Error.compoundTypeMayNotHaveGenericParameterBound(); } if (!type.isInterface()) { throw Error.compoundTypeMayOnlyHaveOneClassBound(); } } return new CompoundType<>(interfaces, baseType); }