/// <sumary> /// Creates a GenericTypeVar object as in a type reference (usage), from a java reflection Type /// object. /// <sumary> public static GenericTypeVar GetGenericTypeVarRef(Type type, List <GenericTypeVar> scope) { GenericTypeVar g = new GenericTypeVar(); g.scope = scope; // case 1: arg is a concrete class if (!type.IsGenericParameter && !type.GetTypeInfo().IsGenericType) { g.classDescriptor = ClassDescriptor.GetClassDescriptor(type); return(g); } else if (type.IsGenericParameter)// case 2: arg is another generic type var { String argName = type.Name; if (argName != null && scope != null) { foreach (GenericTypeVar var in scope) { if (argName.Equals(var.Name)) { g.name = var.Name; g.referredGenericTypeVar = var; break; } } } } // case 3: arg is parameterized CheckTypeParameterizedTypeImpl(g, type); g.scope = null; return(g); }
private void DeriveGenericTypeVariables() { //FieldInfo field = fieldDescriptor.Field; Type genericType = Field.FieldType; List <GenericTypeVar> derivedGenericTypeVars = new List <GenericTypeVar>(); if (genericType.IsGenericParameter) { GenericTypeVar g = GenericTypeVar.GetGenericTypeVarRef(genericType, GetGenericTypeVarsContext()); derivedGenericTypeVars.Add(g); } else { TypeInfo typeInfo = genericType.GetTypeInfo(); if (typeInfo.IsGenericType) { Type[] types = typeInfo.GenericTypeArguments; if (types == null | types.Length <= 0) { return; } foreach (Type t in types) { GenericTypeVar g = GenericTypeVar.GetGenericTypeVarRef(t, GetGenericTypeVarsContext()); derivedGenericTypeVars.Add(g); } } } SetGenericTypeVars(derivedGenericTypeVars); }
public void AddGenericTypeVarArg(GenericTypeVar arg) { if (genericTypeVarArgs == null) { genericTypeVarArgs = new List <GenericTypeVar>(); } genericTypeVarArgs.Add(arg); }
public void AddContraintGenericTypeVarArg(GenericTypeVar g) { if (constraintGenericTypeVarArgs == null) { constraintGenericTypeVarArgs = new List <GenericTypeVar>(); } constraintGenericTypeVarArgs.Add(g); }
public override string ToString() { { StringBuilder sb = new StringBuilder(); if (IsDef()) { sb.Append(name); if (constraintGenericTypeVar != null) { sb.Append(" : ").Append(constraintGenericTypeVar.name); } else if (constraintClassDescriptor != null) { sb.Append(" : ").Append(constraintClassDescriptor.DescribedClassSimpleName); if (constraintGenericTypeVarArgs != null && constraintGenericTypeVarArgs.Count > 0) { sb.Append("<"); for (int i = 0; i < constraintGenericTypeVarArgs.Count; ++i) { GenericTypeVar g = constraintGenericTypeVarArgs[i]; sb.Append(i == 0 ? "" : ",").Append(g.ToString()); } sb.Append(">"); } } } else { if (name != null || referredGenericTypeVar != null) { sb.Append(name); } else if (classDescriptor != null) { sb.Append(classDescriptor.DescribedClassSimpleName); if (genericTypeVarArgs != null && genericTypeVarArgs.Count > 0) { sb.Append("<"); for (int i = 0; i < genericTypeVarArgs.Count; ++i) { GenericTypeVar g = genericTypeVarArgs[i]; sb.Append(i == 0 ? "" : ",").Append(g.ToString()); } sb.Append(">"); } } } return(sb.ToString()); } }
/// <summary> /// Creates a GenericTypeVar object as the definition of a new generic type var, from a java /// reflection TypeVariable object. /// /// <param name='typeVariable'></param> /// <param name='scope'>the scope of current generic type vars; used to resolve generic type var names.</param> /// </summary> public static GenericTypeVar GetGenericTypeVarDef(Type typeVariable, List <GenericTypeVar> scope) { GenericTypeVar g = new GenericTypeVar(); g.scope = scope; g.name = typeVariable.Name; // resolve constraints ResolveGenericTypeVarDefinitionConstraints(g, typeVariable.GetTypeInfo().GetGenericParameterConstraints()); g.scope = null; return(g); }
private void DeriveGenericTypeVariables() { if (_describedClass != null) // for generated descriptors, describedClass == null { Type[] typeVariables = _describedClass.GetTypeInfo().GenericTypeArguments; if (typeVariables.Length > 0) { foreach (Type typeVariable in typeVariables) { GenericTypeVar g = GenericTypeVar.GetGenericTypeVarDef(typeVariable, this.genericTypeVars); this.genericTypeVars.Add(g); } } } }
public static void CheckTypeParameterizedTypeImpl(GenericTypeVar g, Type type) { TypeInfo typeInfo = type.GetTypeInfo(); if (typeInfo.IsGenericType) { g.ClassDescriptor = ClassDescriptor.GetClassDescriptor(type); Type[] types = typeInfo.GenericTypeArguments; foreach (Type t in types) { g.AddGenericTypeVarArg(GenericTypeVar.GetGenericTypeVarRef(t, g.Scope)); } } }
public static void CheckBoundParameterizedTypeImpl(GenericTypeVar g, Type bound) { TypeInfo typeInfo = bound.GetTypeInfo(); if (typeInfo.IsGenericType) { g.ConstraintClassDescriptor = ClassDescriptor.GetClassDescriptor(bound); Type[] types = typeInfo.GenericTypeArguments; foreach (Type type in types) { g.AddContraintGenericTypeVarArg(GenericTypeVar.GetGenericTypeVarRef(type, g.Scope)); } } }
public static List <GenericTypeVar> GetGenericTypeVars(Type parameterizedType, List <GenericTypeVar> scope) { Type[] types = parameterizedType.GenericTypeArguments; if (types.Length <= 0) { return(null); } List <GenericTypeVar> returnValue = new List <GenericTypeVar>(); foreach (Type t in types) { GenericTypeVar g = GenericTypeVar.GetGenericTypeVarRef(t, scope); returnValue.Add(g); } return(returnValue); }
/// <sumary> /// Resolves constraints on the definition of a generic type var. /// <sumary> public static void ResolveGenericTypeVarDefinitionConstraints(GenericTypeVar g, Type[] bounds) { if (bounds == null) { return; } Type bound = bounds[0]; // case 1: constraint is a concrete class if (!bound.IsGenericParameter) { if (typeof(Object) != bound) { g.constraintClassDescriptor = ClassDescriptor.GetClassDescriptor(bound); } } else // case 2: constraint is another generic type var { // look up the scope to find the bound generic type var (must have been defined) String boundName = bound.Name; if (boundName != null && g.scope != null) { foreach (GenericTypeVar var in g.scope) { if (boundName.Equals(var.Name)) { g.constraintGenericTypeVar = var; break; } } } } // case 3: constraint is parameterized -- the most complicated case CheckBoundParameterizedTypeImpl(g, bound); }
public static void CheckTypeParameterizedTypeImpl(GenericTypeVar g, Type type) { TypeInfo typeInfo = type.GetTypeInfo(); if (typeInfo.IsGenericType) { g.ClassDescriptor = ClassDescriptor.GetClassDescriptor(type); Type[] types = typeInfo.GenericTypeArguments; foreach (Type t in types) { g.AddGenericTypeVarArg(GenericTypeVar.GetGenericTypeVarRef(t, g.Scope)); } } }
public static void CheckBoundParameterizedTypeImpl(GenericTypeVar g, Type bound) { TypeInfo typeInfo = bound.GetTypeInfo(); if (typeInfo.IsGenericType) { g.ConstraintClassDescriptor = ClassDescriptor.GetClassDescriptor(bound); Type[] types = typeInfo.GenericTypeArguments; foreach (Type type in types) { g.AddContraintGenericTypeVarArg(GenericTypeVar.GetGenericTypeVarRef(type, g.Scope)); } } }
public void AddGenericTypeVarArg(GenericTypeVar arg) { if (genericTypeVarArgs == null) genericTypeVarArgs = new List<GenericTypeVar>(); genericTypeVarArgs.Add(arg); }
public void AddContraintGenericTypeVarArg(GenericTypeVar g) { if (constraintGenericTypeVarArgs == null) constraintGenericTypeVarArgs = new List<GenericTypeVar>(); constraintGenericTypeVarArgs.Add(g); }
/// <sumary> /// Resolves constraints on a generic type var that is used in a type reference (usage). /// <sumary> public static void ResolveGenericTypeVarReferenceConstraints(GenericTypeVar g, Type[] bounds) { if (bounds == null) return; Type bound = bounds[0]; // case 1: constraint is a concrete class if (!bound.IsGenericParameter) { if (typeof(Object) != bound) g.ClassDescriptor = ClassDescriptor.GetClassDescriptor(bound); } else // case 2: constraint is another generic type var { String boundName = bound.Name; if (boundName != null && g.scope != null) { foreach (GenericTypeVar var in g.scope) if (boundName.Equals(var.Name)) { g.ConstraintGenericTypeVar = var; break; } } } // case 3: constraint is parameterized -- the most complicated case CheckBoundParameterizedTypeImpl(g, bound); }
/// <sumary> /// Creates a GenericTypeVar object as in a type reference (usage), from a java reflection Type /// object. /// <sumary> public static GenericTypeVar GetGenericTypeVarRef(Type type, List<GenericTypeVar> scope) { GenericTypeVar g = new GenericTypeVar(); g.scope = scope; // case 1: arg is a concrete class if (!type.IsGenericParameter && !type.GetTypeInfo().IsGenericType) { g.classDescriptor = ClassDescriptor.GetClassDescriptor(type); return g; } else if (type.IsGenericParameter)// case 2: arg is another generic type var { String argName = type.Name; if (argName != null && scope != null) { foreach (GenericTypeVar var in scope) if (argName.Equals(var.Name)) { g.name = var.Name; g.referredGenericTypeVar = var; break; } } } // case 3: arg is parameterized CheckTypeParameterizedTypeImpl(g, type); g.scope = null; return g; }
/// <summary> /// Creates a GenericTypeVar object as the definition of a new generic type var, from a java /// reflection TypeVariable object. /// /// <param name='typeVariable'></param> /// <param name='scope'>the scope of current generic type vars; used to resolve generic type var names.</param> /// </summary> public static GenericTypeVar GetGenericTypeVarDef(Type typeVariable, List<GenericTypeVar> scope) { GenericTypeVar g = new GenericTypeVar(); g.scope = scope; g.name = typeVariable.Name; // resolve constraints ResolveGenericTypeVarDefinitionConstraints(g, typeVariable.GetTypeInfo().GetGenericParameterConstraints()); g.scope = null; return g; }