internal static TypeRef FromGenericQualifiedName(Span span, GenericQualifiedName qname) { var tref = new ClassTypeRef(span, qname.QualifiedName); if (qname.IsGeneric) { return(new GenericTypeRef(span, tref, qname.GenericParams.Select(p => FromObject(Span.Invalid, p)).ToList())); } else { return(tref); } }
internal PseudoClassConstUse(Text.Span span, GenericQualifiedName className, Text.Span classNamePosition, Types type, Text.Span namePosition) : this(span, ClassTypeRef.FromGenericQualifiedName(classNamePosition, className), type, namePosition) { }
public override void VisitClassTypeRef(ClassTypeRef x) { _results.Push(new GenericQualifiedName(x.ClassName)); }
/// <summary> /// Creates direct type reference from a string. /// </summary> /// <param name="span">Position of the name.</param> /// <param name="name">Input string, primitive type name or a class name.</param> /// <param name="naming">Optional the naming context. The name will be translated.</param> /// <returns>Type reference. Cannot be <c>null</c>.</returns> public static TypeRef FromString(Span span, string name, NamingContext naming = null) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException(nameof(name)); } // multiple types var sepindex = name.IndexOf(PHPDocBlock.TypeVarDescTag.TypeNamesSeparator); if (sepindex >= 0) { var names = name.Split(new char[] { PHPDocBlock.TypeVarDescTag.TypeNamesSeparator }); Debug.Assert(names.Length > 1); var trefs = new TypeRef[names.Length]; int offset = 0; for (int i = 0; i < names.Length; i++) { var str = names[i]; trefs[i] = FromString(new Span(span.Start + offset, str.Length), str, naming); offset += str.Length + 1; // + separator } return(new MultipleTypeRef(span, trefs)); } // nullable if (name[0] == '?') { return(new NullableTypeRef(span, FromString(new Span(span.Start + 1, span.Length - 1), name.Substring(1), naming))); } // var qname = Syntax.QualifiedName.Parse(name, false); // primitive types PrimitiveTypeRef.PrimitiveType primitive; if (qname.IsSimpleName && Enum.TryParse(qname.Name.Value, true, out primitive)) { return(new PrimitiveTypeRef(span, primitive)); } // reserved type names ReservedTypeRef.ReservedType rtype; if (qname.IsSimpleName && ReservedTypeRef.ReservedTypes.TryGetValue(qname.Name, out rtype)) { return(new ReservedTypeRef(span, rtype)); } // direct types TypeRef result = new ClassTypeRef(span, qname); // apply naming context QualifiedName translated; if (Syntax.QualifiedName.TryTranslateAlias(qname, naming, out translated)) { result = new TranslatedTypeRef(span, translated, result); } // return(result); }