public string ToPythonString(bool ignoreAlias = false)
        {
            if (!ignoreAlias && Alias != null)
            {
                return(Alias);
            }

            if (IsNamedTypeParameter)
            {
                return($"{Namespace}_{Name}".Replace('.', '_'));
            }

            var str = "";

            if (Namespace != null)
            {
                str += $"{Namespace}.";
            }

            str += Name;

            if (TypeParameters.Count == 0)
            {
                return(str);
            }

            str += "[";

            // Callable requires Callable[[ParameterType1, ParameterType2, ...], ReturnType]
            if (Namespace == "typing" && Name == "Callable")
            {
                if (IsAction)
                {
                    str += "[";
                    str += string.Join(", ", TypeParameters.Select(type => type.ToPythonString()));
                    str += "], None";
                }
                else
                {
                    str += "[";
                    str += string.Join(
                        ", ",
                        TypeParameters.SkipLast(1).Select(type => type.ToPythonString()));
                    str += "], ";
                    str += TypeParameters.Last().ToPythonString();
                }
            }
            else
            {
                str += string.Join(", ", TypeParameters.Select(type => type.ToPythonString()));
            }

            str += "]";

            return(str);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override string ToDebugString()
        {
            string typeParameters = TypeParameters.Count > 0
                ? "<" + string.Join(", ", TypeParameters.Select(tp => tp.ToDebugString())) + ">"
                : string.Empty;

            string parameters = string.Join(", ", Parameters.Select(p => p.ToDebugString()));

            return(I($"{typeParameters}({parameters}) => {ReturnType.ToDebugString()}"));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public override string ToDebugString()
        {
            string typeParameters = TypeParameters.Count > 0
                ? "<" + string.Join(", ", TypeParameters.Select(tp => tp.ToDebugString())) + ">"
                : string.Empty;

            string parameters = I($"({string.Join(", ", Parameters.Select(p => p.ToDebugString()))})");

            string returnType = ReturnType != null ? ": " + ReturnType.ToDebugString() : string.Empty;

            return(typeParameters + parameters + returnType);
        }
Esempio n. 4
0
        public override IEnumerable <INotation> GetMembers()
        {
            yield return(CustomAttributes.InsertBlank().Combine());

            yield return(Accessibility.ToDisplayString().ToNotation());

            if (IsAsync)
            {
                yield return(ConstNotations.Blank);

                yield return(ConstNotations.Async);
            }
            if (IsOverride)
            {
                yield return(ConstNotations.Blank);

                yield return(ConstNotations.Override);
            }
            yield return(ConstNotations.Blank);

            yield return(ReturnType.ToNotation());

            yield return(ConstNotations.Blank);

            yield return(Name.ToNotation());

            if (TypeParameters.Count > 0)
            {
                yield return(ConstNotations.OpenAngleBracket);

                yield return(TypeParameters.Select(i => i.ToOnlyTypeDefinitionNotation()).InsertComma().Combine());

                yield return(ConstNotations.CloseAngleBracket);
            }
            yield return(ConstNotations.OpenParen);

            yield return(Parameters.InsertComma().Combine());

            yield return(ConstNotations.CloseParen);

            yield return(TypeParameters.Select(i => i.ToConstantNotation(IsOverride)).InsertBlank().Combine());

            yield return(ConstNotations.OpenBrace);

            yield return(Body.Combine());

            yield return(ConstNotations.CloseBrace);
        }
Esempio n. 5
0
        /// <inheritdoc />
        public override string ToDebugString()
        {
            var decorators = ToDebugString(Decorators);

            string typeParameters = TypeParameters.Count > 0
                ? "<" + string.Join(", ", TypeParameters.Select(p => p.ToString())) + ">"
                : string.Empty;
            string extendedTypes = ExtendedTypes.Count > 0
                ? " extends " + string.Join(", ", ExtendedTypes.Select(t => t.ToString()))
                : string.Empty;

            return(decorators + GetModifierString() + "interface " + ToDebugString(Name)
                   + typeParameters
                   + extendedTypes
                   + Body);
        }
        public StructDefinitionSyntax(ISyntaxNode parent, JurParser.StructDeclarationContext context) : base(parent, context)
        {
            Name           = context.ID(0).GetText();
            IsNominal      = context.NOMINAL() != null;
            TypeParameters = context.ID().Skip(1).Select(x => new TypeParameterSyntax(this, x.GetText(), Line, this)).ToImmutableArray();
            InlinedTypes   = ToTypes(context.inlinedType().Select(x => x.type()).ToArray());
            Fields         = ToFields(context.uninitializedVarDeclaration());

            FullName = IsGeneric
                           ? Name + "<" + string.Join(",", TypeParameters.Select(x => x.Name)) + ">"
                           : Name;

            ImmediateChildren = ImmutableArray.Create <ITreeNode>()
                                .AddRange(InlinedTypes)
                                .AddRange(Fields);
        }
Esempio n. 7
0
        /// <summary>
        /// The declartion part of the method, e.g. 'private int MyMethod(in MyType type, out ThatType that)'
        /// </summary>
        public string GetDeclarationString()
        {
            return(_declarationCache ??= BuildString());

            string BuildString()
            {
                var str = new StringBuilder();

                str.Append(Accessibility.ToCodeString()); // private
                str.Append(' ');
                str.Append(ReturnType);                   // int
                str.Append(' ');
                if (!IsConstructor)
                {
                    str.Append(MethodName); // MyMethod
                }
                if (TypeParameters.Count > 0)
                {
                    str.Append('<');
                    str.Append(string.Join(",", TypeParameters.Select(x => x.GenericName)));
                    str.Append('>');
                }
                str.Append("(");
                str.Append(string.Join(", ", Arguments.Select(x => x.ToParamString())));
                str.Append(")");
                if (TypeParameters.All(x => !x.HasConstrain))
                {
                    return(str.ToString());
                }
                foreach (var generic in TypeParameters)
                {
                    if (!generic.HasConstrain)
                    {
                        continue;
                    }
                    str.Append("where");
                    str.Append(' ');
                    str.Append(generic.GenericName);
                    str.Append(" : ");
                    str.Append(string.Join(",", GetGenericsArgs(generic)));
                    str.Append(' ');
                }
                return(str.ToString());
            }
Esempio n. 8
0
 public ClassInfo ReplaceTypeParameterNames(Func <string, string> replacer)
 => new ClassInfo(Name, TypeParameters.Select(t => replacer(t)), Flags);
Esempio n. 9
0
 public override string ToString()
 {
     if (SpecialName == GenericWildcard.SpecialName && WildcardConstraints != null)
     {
         return(SpecialName + WildcardBoundsType + string.Join(" & ", WildcardConstraints));
     }
     else if (SpecialName != null)
     {
         return(SpecialName + ArrayPart);
     }
     else if (ReferencedTypeParameter != null)
     {
         return(ReferencedTypeParameter.ToString() + ArrayPart);
     }
     else
     {
         return(string.Format("{0}{1}{2}{3}{4}",
                              ReferencedType?.Parent?.Name,
                              string.IsNullOrEmpty(ReferencedType?.Parent?.Name) ? string.Empty : ".",
                              ReferencedType?.Name,
                              TypeParameters == null ? null : '<' + string.Join(", ", TypeParameters.Select(_ => _.ToString())) + '>',
                              ArrayPart));
     }
 }
Esempio n. 10
0
 public string AsString() =>
 string.Join(".", Namespaces.Concat(Enumerable.Repeat(Identifier, 1))) +
 (TypeParameters.IsNullOrEmpty() ? string.Empty :
  "<" + string.Join(", ", TypeParameters.Select(t => t.AsString())) + ">") +
 (IsArray ? "[]" : string.Empty);
Esempio n. 11
0
 public override string ToString()
 {
     return((IsExtension ? "!" : "") + Name + (TypeParameters.Count() > 0 ? "<" + string.Join(",", TypeParameters.Select(t => t.ToString())) + ">" : ""));
 }
 public override string ToString()
 {
     if (SpecialName != null)
     {
         return(SpecialName);
     }
     else if (ReferencedTypeParameter != null)
     {
         return(ReferencedTypeParameter.Name);
     }
     else
     {
         return(string.Format("{0}{1}{2}{3}{4}",
                              ReferencedType.Parent.Name,
                              string.IsNullOrEmpty(ReferencedType.Parent.Name) ? string.Empty : ".",
                              ReferencedType.Name,
                              TypeParameters == null ? null : '<' + string.Join(", ", TypeParameters.Select(_ => _.ToString())) + '>',
                              ArrayPart));
     }
 }
Esempio n. 13
0
 public NameInfo ReplaceTypeParameterNames(Func <string, string> replacer)
 => new NameInfo(Classes.Select(c => c.ReplaceTypeParameterNames(replacer)),
                 Name,
                 TypeParameters.Select(t => replacer(t)),
                 Parameters.Select(p => p.ReplaceTypeParameterNames(replacer)),
                 Flags);
Esempio n. 14
0
        //The ID of a generic method uses postfix ``n, n is the count of in method parameters, for example, System.Tuple.Create``1(``0)
        public override void Build(ECMAStore store)
        {
            if (DocId != null && DocId.Contains('|'))
            {
                var parts = DocId.Split(':');
                if (parts?.Length == 2)
                {
                    Id = parts[1];
                    if (Id.StartsWith(Parent.Uid))
                    {
                        Id = Id.Substring(Parent.Uid.Length, Id.Length - Parent.Uid.Length).TrimStart('.');
                        return;
                    }
                }
            }
            Id = Name.Replace('.', '#');
            if (TypeParameters?.Count > 0)
            {
                Id = Id.Substring(0, Id.LastIndexOf('<')) + "``" + TypeParameters.Count;
            }
            //handle eii prefix
            Id = Id.Replace('<', '{').Replace('>', '}');
            Id = Id.Replace(',', '@');
            if (Parameters?.Count > 0)
            {
                //Type conversion operator can be considered a special operator whose name is the UID of the target type,
                //with one parameter of the source type.
                //For example, an operator that converts from string to int should be Explicit(System.String to System.Int32).
                if (Name == "op_Explicit" || Name == "op_Implicit")
                {
                    var typeParamsOnType   = Parent.TypeParameters?.Select(tp => tp.Name).ToList();
                    var typeParamsOnMember = TypeParameters?.Select(tp => tp.Name).ToList();

                    var rtype = ReturnValueType.VersionedTypes.First().Value;

                    Id += string.Format("({0})~{1}",
                                        Parameters.First().Type.ToSpecId(typeParamsOnType, typeParamsOnMember),
                                        rtype.ToSpecId(typeParamsOnType, typeParamsOnMember));
                }
                //spec is wrong, no need to treat indexer specially, so comment this part out
                //else if (MemberType == MemberType.Property && Signatures.ContainsKey("C#") && Signatures["C#"].Contains("["))
                //{
                //    Id += string.Format("[{0}]", string.Join(",", GetParameterUids(store)));
                //}
                else
                {
                    Id += string.Format("({0})", string.Join(",", GetParameterUids(store)));
                }
            }

            //special handling for compatibility in UWP legacy MD content
            if (store.UWPMode && DocId != null)
            {
                var pos1 = Id.IndexOf('(');
                var pos2 = DocId.IndexOf('(');
                if (pos1 > 0 && pos2 > 0)
                {
                    Id = Id.Substring(0, pos1) + DocId.Substring(pos2);
                }
            }
        }