public static async Task <PassiveDeclarationSyntax> FromParseAsync(ClassDeclarationSyntax declaration, Document document, CancellationToken ct) { var ns = declaration.Parent is NamespaceDeclarationSyntax nsds ? (nsds.Name is QualifiedNameSyntax qns ? qns.ToString() : throw new Exception()) : throw new Exception(); var symbol = await SymbolFinder.FindSourceDeclarationsAsync( document.Project, declaration.Identifier.ValueText, false, ct); var sourceType = symbol.OfType <INamedTypeSymbol>() .FirstOrDefault(x => x.GetFullNameSpace() == ns); var attr = sourceType.GetAttributes() .First(x => x.AttributeClass.Name == "PassiveDecorationAttribute"); if (!(attr.ConstructorArguments[0].Value is string domainName)) { throw new Exception(); } if (!(attr.ConstructorArguments[1].Value is string eventName)) { throw new Exception(); } return(new PassiveDeclarationSyntax( Regex.Replace(declaration.Identifier.ValueText, "Settings$", ""), await BattleEventSyntax.FromParseAsync(declaration, eventName, document, ct), await TokenAttributeSyntax.FromParseAsync(declaration, document, ct), TypeName.FromSymbol(sourceType), domainName, eventName)); }
public FactoryDefinition GetDefinition() { var genericHost = _syntax.InterfaceSymbol.HasAttribute(nameof(ConfigureGenericHostAttribute)); var resolvers = _syntax.Resolvers .Select(x => new ResolverAnalyzer(x).GetDefinition()) .ToArray(); var collectionResolvers = _syntax.CollectionResolvers .Select(x => new CollectionResolverAnalyzer(x).GetDefinition()) .ToArray(); var captures = _syntax.Captures .Select(x => new CaptureAnalyzer(x).GetDefinition()) .ToArray(); return(new FactoryDefinition( GetFactoryTypeName(), TypeName.FromSymbol(_syntax.InterfaceSymbol), GetDependencies(), resolvers, collectionResolvers, captures, genericHost)); }
public static async Task <PhaseGroupSyntax> FromDeclarationAsync(InterfaceDeclarationSyntax syntax, Document document, CancellationToken ct) { async Task <INamedTypeSymbol> GetSymbol() { var ns = syntax.Parent is NamespaceDeclarationSyntax nsds ? (nsds.Name is QualifiedNameSyntax qns ? qns.ToString() : throw new Exception()) : throw new Exception(); var symbols = await SymbolFinder.FindSourceDeclarationsAsync( document.Project, syntax.Identifier.ValueText, false, ct); var namedTypeSymbol = symbols.OfType <INamedTypeSymbol>() .First(x => x.GetFullNameSpace() == ns); return(namedTypeSymbol); } var symbol = await GetSymbol(); return(new PhaseGroupSyntax(TypeName.FromSymbol(symbol), PhaseMethodSyntax.FromPhaseGroupType(symbol).ToArray())); }
public IEnumerable <TypeName> GetCapableServiceTypes() { yield return(TypeName.FromSymbol(InterfaceSymbol)); foreach (var capture in Captures) { yield return(capture.TypeName); } }
public static IEnumerable <AdditionalParameterSyntax> FromMethod(IMethodSymbol method) { foreach (var parameter in method.Parameters) { var isContext = parameter.GetAttributes() .Any(x => x.AttributeClass.Name == "PhaseContextAttribute"); if (!isContext) { yield return(new AdditionalParameterSyntax(TypeName.FromSymbol(parameter.Type), parameter.Name)); } } }
public static ResolutionSyntax FromType(INamedTypeSymbol symbol) { var isDisposable = symbol.AllInterfaces .Any(x => x.Name == "IDisposable" && x.GetFullNameSpace() == "System"); if (symbol.Constructors.Length == 0) { return(new ResolutionSyntax(TypeName.FromSymbol(symbol), new TypeName[0], isDisposable)); } var dependencies = symbol.Constructors[0].Parameters .Select(x => TypeName.FromSymbol(x.Type)) .ToArray(); return(new ResolutionSyntax(TypeName.FromSymbol(symbol), dependencies, isDisposable)); }
public static ResultTypeSyntax FromMethod(IMethodSymbol method) { // 戻り値が Task<PhaseResult<T>> であるという前提 if (method.ReturnType is INamedTypeSymbol nts && nts.Name == "Task") { if (nts.TypeArguments.Length == 1 && nts.TypeArguments[0] is INamedTypeSymbol nts2 && nts2.Name == "PhaseResult") { if (nts2.TypeArguments.Length == 1 && nts2.TypeArguments[0] is INamedTypeSymbol nts3) { return(new ResultTypeSyntax(TypeName.FromSymbol(nts3))); } } } throw new Exception(); }
static ResolutionSyntax?GetResolutionAsElement(AttributeData resolutionAttr, TypeName type) { if (resolutionAttr.ConstructorArguments[0].Value is INamedTypeSymbol nts) { if (TypeName.FromSymbol(nts.BaseType) == type) { return(ResolutionSyntax.FromType(nts)); } foreach (var @interface in nts.AllInterfaces) { if (TypeName.FromSymbol(@interface) == type) { return(ResolutionSyntax.FromType(nts)); } } } return(null); }
public static CaptureSyntax[] FromFactory(INamedTypeSymbol factory) { IEnumerable <CaptureSyntax> GetCaptures() { var inInterfaces = factory.AllInterfaces .SelectMany(x => x.GetMembers()); var properties = factory.GetMembers() .Concat(inInterfaces) .OfType <IPropertySymbol>(); foreach (var property in properties) { if (!property.IsReadOnly) { continue; } if (!property.Type.HasAttribute(nameof(FactoryAttribute))) { continue; } if (property.Type is INamedTypeSymbol namedType) { var resolvers = ResolverSyntax.FromParent(namedType); yield return(new CaptureSyntax(property.Name, TypeName.FromSymbol(namedType), resolvers.Item1, resolvers.Item2)); } } } return(GetCaptures().ToArray()); }
public static ParameterSyntax[] FromResolver(IMethodSymbol symbol) { return(symbol.Parameters .Select(x => new ParameterSyntax(TypeName.FromSymbol(x.Type), x.Name)) .ToArray()); }