internal void AddReserved(ISymbol blame, AttributeData attrib) { Reservation reservation; if (attrib.TryGetInt32ByName(nameof(ProtoReservedAttribute.From), out var from) && attrib.TryGetInt32ByName(nameof(ProtoReservedAttribute.To), out var to)) { reservation = new Reservation(attrib.GetLocation(blame), from, to); } else if (attrib.TryGetInt32ByName("field", out from)) { reservation = new Reservation(attrib.GetLocation(blame), from, from); } else if (attrib.TryGetStringByName("field", out string name)) { reservation = new Reservation(attrib.GetLocation(blame), name); } else { return; } (_reservations ??= new List <Reservation>()).Add(reservation); }
private static void AnalyzeImplementation(SymbolAnalysisContext context, INamedTypeSymbol modelType, ISymbol symbol, AttributeData attribute, Compilation compilation) { var name = symbol.Name; var modelAttributeType = attribute.GetCrossReferenceAttributeType(compilation); if (modelAttributeType == null) { return; } var spec = modelAttributeType.GetModelDeclarationSpec(compilation); if (!spec.HasValue) { return; } var specValue = spec.Value; var isProperty = specValue.IsProperty; var returnType = specValue.ReturnType; var parameterTypes = specValue.ParameterTypes; if (!IsImplementation(symbol, isProperty, specValue.ReturnType, specValue.ParameterTypes)) { context.ReportDiagnostic(Diagnostic.Create(Rules.InvalidImplementationAttribute, attribute.GetLocation(), attribute.AttributeClass, isProperty ? Resources.StringFormatArg_Property : Resources.StringFormatArg_Method, returnType, parameterTypes.FormatString())); return; } var modelAttribute = modelType.GetAttributes().Where(x => x.AttributeClass.Equals(modelAttributeType) && x.GetStringArgument() == name).FirstOrDefault(); if (modelAttribute == null) { context.ReportDiagnostic(Diagnostic.Create(Rules.MissingDeclarationAttribute, attribute.GetLocation(), modelAttributeType, name)); } }
private static void AnalyzeModelDeclarationAttribute(SymbolAnalysisContext context, INamedTypeSymbol modelType, AttributeData attribute) { var compilation = context.Compilation; var spec = attribute.AttributeClass.GetModelDeclarationSpec(compilation); if (!spec.HasValue) { return; } var specValue = spec.Value; var name = attribute.GetStringArgument(); if (name == null) { return; } var implementation = GetImplementation(modelType, name, specValue); if (implementation == null) { var isProperty = specValue.IsProperty; var parameterTypes = specValue.ParameterTypes; var returnType = specValue.ReturnType; context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementation, attribute.GetLocation(), (isProperty ? Resources.StringFormatArg_Property : Resources.StringFormatArg_Method), name, returnType, parameterTypes.FormatString())); return; } var crossRefAttributeType = attribute.GetCrossReferenceAttributeType(compilation); if (crossRefAttributeType == null) { return; } if (!implementation.HasAttribute(crossRefAttributeType)) { context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementationAttribute, implementation.Locations[0], crossRefAttributeType)); } }
private static void AnalyzeModelDesignerSpec(SymbolAnalysisContext context, ISymbol symbol, ITypeSymbol type, AttributeData attribute) { var spec = attribute.GetModelDesignerSpec(context.Compilation); if (!spec.HasValue) { return; } var validOnTypes = spec.Value.ValidOnTypes; if (validOnTypes == null) { return; } validOnTypes = validOnTypes.Where(x => x != null).ToArray(); if (!IsValid(type, validOnTypes)) { context.ReportDiagnostic(Diagnostic.Create(Rules.ModelDesignerSpecInvalidType, attribute.GetLocation(), attribute.AttributeClass, FormatString(validOnTypes), type)); return; } if (ArgumentMissing(attribute, spec.Value.RequiresArgument)) { context.ReportDiagnostic(Diagnostic.Create(Rules.ModelDesignerSpecRequiresArgument, attribute.GetLocation(), attribute.AttributeClass)); return; } }
private static void AnalyzeImplementation(SymbolAnalysisContext context, INamedTypeSymbol dbType, IMethodSymbol implementation, AttributeData attribute) { var name = implementation.Name; var compilation = context.Compilation; var declarationModelTypes = GetDeclarationModelTypes(dbType, name, compilation); if (declarationModelTypes.IsDefaultOrEmpty) { context.ReportDiagnostic(Diagnostic.Create(Rules.MissingDeclarationAttribute, attribute.GetLocation(), compilation.GetKnownType(KnownTypes.RelationshipAttribute), name)); } else if (declarationModelTypes.Length == 1) { var modelType = declarationModelTypes[0]; if (!IsImplementation(implementation, modelType, compilation)) { context.ReportDiagnostic(Diagnostic.Create(Rules.InvalidImplementationAttribute, attribute.GetLocation(), attribute.AttributeClass, Resources.StringFormatArg_Method, compilation.GetKnownType(KnownTypes.KeyMapping), modelType)); } } }
private static void AnalyzeDeclaration(SymbolAnalysisContext context, INamedTypeSymbol dbType, IPropertySymbol dbTable, AttributeData attribute, HashSet <string> names) { var name = attribute.GetStringArgument(); if (name == null) { return; } if (names.Contains(name)) { context.ReportDiagnostic(Diagnostic.Create(Rules.DuplicateDeclarationAttribute, attribute.GetLocation(), attribute.AttributeClass, name)); return; } names.Add(name); var modelType = dbTable.GetModelType(); if (modelType == null) { return; } var compilation = context.Compilation; var implementation = GetImplementation(dbType, name, modelType, compilation); if (implementation == null) { var keyMappingType = compilation.GetKnownType(KnownTypes.KeyMapping); context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementation, attribute.GetLocation(), Resources.StringFormatArg_Method, name, keyMappingType, modelType)); return; } var implementationAttribute = compilation.GetKnownType(KnownTypes._RelationshipAttribute); if (!implementation.HasAttribute(implementationAttribute)) { context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementationAttribute, implementation.Locations[0], implementationAttribute)); } }