void ParseInterface(Definition.InterfaceDef def) { foreach (var prop in def.Properties) { var semanticModel = compilation.GetSemanticModel(prop.Internal.SyntaxTree); if (prop.Getter != null && prop.Getter.Internal.Body != null) { prop.Getter.Body = ParseStatement(prop.Getter.Internal.Body, semanticModel); } if (prop.Setter != null) { prop.Setter.Body = ParseStatement(prop.Setter.Internal.Body, semanticModel); } } foreach (var method in def.Methods) { var semanticModel = compilation.GetSemanticModel(method.Internal.SyntaxTree); if (method.Internal.Body == null) { continue; } var statement = ParseStatement(method.Internal.Body, semanticModel) as BlockStatement; method.Body = statement.Statements.ToList(); } }
private void OutputInterface(Definition.InterfaceDef def) { Func <string> generics = () => { if (def.TypeParameters.Count == 0) { return(string.Empty); } Func <Definition.TypeParameterDef, string> generic = (t) => { if (t.BaseTypeConstraints.Count > 0) { return(t.Name + " extends " + string.Join(" & ", t.BaseTypeConstraints.Select(_ => GetTypeSpecifier(_)))); } else { return(t.Name); } }; return("<" + string.Join(",", def.TypeParameters.Select(_ => generic(_))) + ">"); }; List <Definition.TypeSpecifier> bases = new List <Definition.TypeSpecifier>(); List <Definition.TypeSpecifier> interfaces = new List <Definition.TypeSpecifier>(); foreach (var b in def.BaseTypes) { var simple = b as Definition.SimpleType; var gene = b as Definition.GenericType; if (simple != null) { if (simple.TypeKind == Definition.SimpleTypeKind.Interface || simple.TypeKind == Definition.SimpleTypeKind.Other) { interfaces.Add(b); } else { bases.Add(b); } } else if (gene != null) { if (gene.OuterType.TypeKind == Definition.SimpleTypeKind.Interface || gene.OuterType.TypeKind == Definition.SimpleTypeKind.Other) { interfaces.Add(b); } else { bases.Add(b); } } } Func <string> extends = () => { if (bases.Count == 0) { return(string.Empty); } return(" extends " + string.Join(",", GetTypeSpecifier(bases[0]))); }; // 表記変化注意 Func <string> implements = () => { if (interfaces.Count == 0) { return(string.Empty); } return(" extends " + string.Join(",", interfaces.Select(_ => GetTypeSpecifier(_)))); }; Summary(def.Summary); WriteLine( "{0} interface {1}{2} {3} {4}", GetAccessLevel(def.AccessLevel), def.Name, generics(), extends(), implements()); WriteLine("{{"); IndentDepth++; if (def.Fields != null) { foreach (var f in def.Fields) { OutputFieldInInterface(f); } } foreach (var p in def.Properties) { OutputPropertyInInterface(p); } foreach (var m in def.Methods) { OutputMethodInInterface(m); } IndentDepth--; WriteLine("}}"); }