public PathBuilder(ICypherFluentQuery query, IPathExtent path, string pathVariable, AnnotationsContext context) : this(query, context) { Path = path; PathVariable = pathVariable; }
private static void AnalyzeConflictingImmutabilityOnTypeParameters( SyntaxNodeAnalysisContext ctx, AnnotationsContext annotationsContext ) { // Get the symbol for the parameter if (ctx.SemanticModel.GetDeclaredSymbol(ctx.Node) is not ITypeParameterSymbol symbol) { return; } // Check if the parameter has both the [Immutable] and the [OnlyIf] attributes if (!annotationsContext.Objects.Immutable.IsDefined(symbol) || !annotationsContext.Objects.OnlyIf.IsDefined(symbol) ) { return; } // Create the diagnostic on the parameter (excluding the attribute) var diagnostic = Diagnostic.Create( Diagnostics.ConflictingImmutability, symbol.DeclaringSyntaxReferences[0].GetSyntax().GetLastToken().GetLocation(), "Immutable", "ConditionallyImmutable.OnlyIf", symbol.Kind.ToString().ToLower()); ctx.ReportDiagnostic(diagnostic); }
private static void AnalyzeConditionalImmutabilityOnMethodDeclarations( SyntaxNodeAnalysisContext ctx, AnnotationsContext annotationsContext ) { // Get the symbol for the method if (ctx.SemanticModel.GetDeclaredSymbol(ctx.Node) is not IMethodSymbol symbol) { return; } foreach (var parameter in symbol.TypeParameters) { // Check if the parameter has the [OnlyIf] attribute if (!annotationsContext.Objects.OnlyIf.IsDefined(parameter)) { continue; } // Create the diagnostic on the parameter (including the attribute) var diagnostic = Diagnostic.Create( Diagnostics.UnexpectedConditionalImmutability, parameter.DeclaringSyntaxReferences[0].GetSyntax().GetLocation()); ctx.ReportDiagnostic(diagnostic); } }
public PathBuilder(ICypherFluentQuery query, Expression <Func <IPathBuilder, IPathExtent> > expression, AnnotationsContext context = null) : this(query, context) { Path = expression?.Compile().Invoke(this); PathVariable = expression?.Parameters[0].Name; }
private static void AnalyzeConflictingImmutabilityOnMember( SyntaxNodeAnalysisContext ctx, AnnotationsContext annotationsContext ) { // Ensure syntax is expected and get the symbol if (ctx.Node is not TypeDeclarationSyntax syntax) { return; } var symbol = ctx.SemanticModel.GetDeclaredSymbol(syntax); // Get information about immutability bool hasImmutable = annotationsContext.Objects.Immutable.IsDefined(symbol); bool hasConditionallyImmutable = annotationsContext.Objects.ConditionallyImmutable.IsDefined(symbol); bool hasImmutableBase = annotationsContext.Objects.ImmutableBaseClass.IsDefined(symbol); // Check if there are conflicting immutability attributes if (hasImmutable && hasConditionallyImmutable) { // [Immutable] and [ConditionallyImmutable] both exist, // so create a diagnostic var diagnostic = Diagnostic.Create( Diagnostics.ConflictingImmutability, syntax.Identifier.GetLocation(), "Immutable", "ConditionallyImmutable", syntax.Keyword); ctx.ReportDiagnostic(diagnostic); } if (hasImmutable && hasImmutableBase) { // [Immutable] and [ImmutableBaseClassAttribute] both exist, // so create a diagnostic var diagnostic = Diagnostic.Create( Diagnostics.ConflictingImmutability, syntax.Identifier.GetLocation(), "Immutable", "ImmutableBaseClassAttribute", syntax.Keyword); ctx.ReportDiagnostic(diagnostic); } if (hasConditionallyImmutable && hasImmutableBase) { // [ConditionallyImmutable] and [ImmutableBaseClassAttribute] both exist, // so create a diagnostic var diagnostic = Diagnostic.Create( Diagnostics.ConflictingImmutability, syntax.Identifier.GetLocation(), "ConditionallyImmutable", "ImmutableBaseClassAttribute", syntax.Keyword); ctx.ReportDiagnostic(diagnostic); } }
public ImmutableAttributeConsistencyChecker( Compilation compilation, DiagnosticSink diagnosticSink, ImmutabilityContext context, AnnotationsContext annotationsContext ) { m_compilation = compilation; m_diagnosticSink = diagnosticSink; m_context = context; m_annotationsContext = annotationsContext; }
private ImmutabilityContext( AnnotationsContext annotationsContext, ImmutableDictionary <INamedTypeSymbol, ImmutableTypeInfo> extraImmutableTypes, ImmutableHashSet <IMethodSymbol> knownImmutableReturns, ImmutableHashSet <ITypeParameterSymbol> conditionalTypeParamemters ) { m_annotationsContext = annotationsContext; m_extraImmutableTypes = extraImmutableTypes; m_knownImmutableReturns = knownImmutableReturns; m_conditionalTypeParameters = conditionalTypeParamemters; }
private static void AnalyzeTypeArguments( SyntaxNodeAnalysisContext ctx, AnnotationsContext annotationsContext, ImmutabilityContext immutabilityContext, SimpleNameSyntax syntax ) { if (syntax.IsFromDocComment()) { // ignore things in doccomments such as crefs return; } SymbolInfo info = ctx.SemanticModel.GetSymbolInfo(syntax, ctx.CancellationToken); // Ignore anything that cannot have type arguments/parameters if (!GetTypeParamsAndArgs(info.Symbol, out var typeParameters, out var typeArguments)) { return; } int i = 0; var paramArgPairs = typeParameters.Zip(typeArguments, (p, a) => (p, a, i++)); foreach (var(parameter, argument, position) in paramArgPairs) { // TODO: this should eventually use information from ImmutableTypeInfo // however the current information about immutable type parameters // includes [Immutable] filling for what will instead be the upcoming // [OnlyIf] (e.g. it would be broken for IEnumerable<>) if (!annotationsContext.Objects.Immutable.IsDefined(parameter)) { continue; } if (!immutabilityContext.IsImmutable( new ImmutabilityQuery( ImmutableTypeKind.Total, argument ), // If the syntax is a GenericName (has explicit type arguments) then the error should be on the argument // Otherwise, it should be on the identifier itself getLocation: () => syntax is GenericNameSyntax genericSyntax ? genericSyntax.TypeArgumentList.Arguments[position].GetLocation() : syntax.Identifier.GetLocation(), out Diagnostic diagnostic )) { // TODO: not necessarily a good diagnostic for this use-case ctx.ReportDiagnostic(diagnostic); } } }
public ImmutableDefinitionChecker( Compilation compilation, DiagnosticSink diagnosticSink, ImmutabilityContext context, AnnotationsContext annotationsContext ) { m_compilation = compilation; m_diagnosticSink = diagnosticSink; m_context = context; m_annotationsContext = annotationsContext; }
private static void AnalyzeTypeDeclaration( SymbolAnalysisContext ctx, AnnotationsContext annotationsContext, ImmutabilityContext immutabilityContext, INamedTypeSymbol typeSymbol ) { if (typeSymbol.IsImplicitlyDeclared) { return; } ImmutableAttributeConsistencyChecker consistencyChecker = new ImmutableAttributeConsistencyChecker( compilation: ctx.Compilation, diagnosticSink: ctx.ReportDiagnostic, context: immutabilityContext, annotationsContext: annotationsContext ); consistencyChecker.CheckTypeDeclaration(typeSymbol); if (typeSymbol.TypeKind == TypeKind.Interface) { return; } if (!annotationsContext.Objects.Immutable.IsDefined(typeSymbol) && !annotationsContext.Objects.ConditionallyImmutable.IsDefined(typeSymbol) && !annotationsContext.Objects.ImmutableBaseClass.IsDefined(typeSymbol) ) { return; } if (annotationsContext.Objects.ConditionallyImmutable.IsDefined(typeSymbol)) { immutabilityContext = immutabilityContext.WithConditionalTypeParametersAsImmutable(typeSymbol); } ImmutableDefinitionChecker checker = new ImmutableDefinitionChecker( compilation: ctx.Compilation, diagnosticSink: ctx.ReportDiagnostic, context: immutabilityContext, annotationsContext: annotationsContext ); checker.CheckDeclaration(typeSymbol); }
public static ImmutableTypeInfo Create( AnnotationsContext annotationsContext, ImmutableTypeKind kind, INamedTypeSymbol type ) { ImmutableArray <bool> immutableTypeParameters = type .TypeParameters .Select(p => annotationsContext.Objects.OnlyIf.IsDefined(p)) .ToImmutableArray(); return(new ImmutableTypeInfo( kind: kind, type: type, conditionalTypeParameters: immutableTypeParameters )); }
public AccountController( AnnotationsContext context, //we can get the context this way if needed (although, we do not need it in this controller) UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, SignInManager <ApplicationUser> signInManager, IEmailSender emailSender, ISmsSender smsSender, ILoggerFactory loggerFactory) { _context = context; _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _emailSender = emailSender; _smsSender = smsSender; _logger = loggerFactory.CreateLogger <AccountController>(); }
public static AnnotationsBuilder AddNeo4jAnnotations <TContext>(this IServiceCollection services) where TContext : AnnotationsContext { try { services.AddSingleton <EntityService, EntityService>(provider => { return(AnnotationsContext.CreateNewEntityService()); }); } catch { } services.AddScoped <AnnotationsContext, TContext>(); return(new AnnotationsBuilder(typeof(TContext), services)); }
private void RegisterAnalysis(CompilationStartAnalysisContext context) { DependencyRegistry dependencyRegistry; if (!DependencyRegistry.TryCreateRegistry(context.Compilation, out dependencyRegistry)) { return; } if (!AnnotationsContext.TryCreate(context.Compilation, out AnnotationsContext annotationsContext)) { return; } var immutabilityCtx = ImmutabilityContext.Create(context.Compilation, annotationsContext); context.RegisterSyntaxNodeAction( ctx => AnalyzeInvocation(ctx, immutabilityCtx, dependencyRegistry), SyntaxKind.InvocationExpression ); }
private static void AnalyzeMember( SymbolAnalysisContext ctx, AnnotationsContext annotationsContext, ImmutabilityContext immutabilityContext ) { // We only care about checking static fields/properties. These // are global variables, so we always want them to be immutable. // The fields/properties of [Immutable] types get handled via // AnalyzeTypeDeclaration. if (!ctx.Symbol.IsStatic) { return; } // Ignore const things, which include enum names. if (ctx.Symbol is IFieldSymbol f && f.IsConst) { return; } // We would like this check to run for generated code too, but // there are two problems: // (1) the easy one: we generate some static variables that are // safe in practice but don't analyze well. // (2) the hard one: resx code-gen generates some stuff that's // safe in practice but doesn't analyze well. if (ctx.Symbol.IsFromGeneratedCode()) { return; } var checker = new ImmutableDefinitionChecker( compilation: ctx.Compilation, diagnosticSink: ctx.ReportDiagnostic, context: immutabilityContext, annotationsContext: annotationsContext ); checker.CheckMember(ctx.Symbol); }
private static void AnalyzeMethodDeclarationConsistency( SymbolAnalysisContext ctx, AnnotationsContext annotationsContext, ImmutabilityContext immutabilityContext, IMethodSymbol methodSymbol ) { // Static methods can't implement interface methods if (methodSymbol.IsStatic) { return; } ImmutableAttributeConsistencyChecker consistencyChecker = new ImmutableAttributeConsistencyChecker( compilation: ctx.Compilation, diagnosticSink: ctx.ReportDiagnostic, context: immutabilityContext, annotationsContext: annotationsContext ); consistencyChecker.CheckMethodDeclaration(methodSymbol); }
public static void CompilationStart( CompilationStartAnalysisContext context ) { if (!AnnotationsContext.TryCreate(context.Compilation, out AnnotationsContext annotationsContext)) { return; } ImmutabilityContext immutabilityContext = ImmutabilityContext.Create(context.Compilation, annotationsContext); context.RegisterSymbolAction( ctx => AnalyzeTypeDeclaration( ctx, annotationsContext, immutabilityContext, (INamedTypeSymbol)ctx.Symbol ), SymbolKind.NamedType ); context.RegisterSymbolAction( ctx => AnalyzeMethodDeclarationConsistency( ctx, annotationsContext, immutabilityContext, (IMethodSymbol)ctx.Symbol ), SymbolKind.Method ); context.RegisterSymbolAction( ctx => AnalyzeMember(ctx, annotationsContext, immutabilityContext), SymbolKind.Field, SymbolKind.Property ); context.RegisterSyntaxNodeAction( ctx => AnalyzeTypeArguments( ctx, annotationsContext, immutabilityContext, (SimpleNameSyntax)ctx.Node ), SyntaxKind.IdentifierName, SyntaxKind.GenericName ); context.RegisterSyntaxNodeAction( ctx => AnalyzeConditionalImmutabilityOnMethodDeclarations( ctx, annotationsContext ), SyntaxKind.MethodDeclaration, SyntaxKind.LocalFunctionStatement ); context.RegisterSyntaxNodeAction( ctx => AnalyzeConflictingImmutabilityOnTypeParameters( ctx, annotationsContext ), SyntaxKind.TypeParameter ); context.RegisterSyntaxNodeAction( ctx => AnalyzeConflictingImmutabilityOnMember( ctx, annotationsContext ), SyntaxKind.ClassDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.StructDeclaration ); }
public Store(AnnotationsContext context) { AnnotationsContext = context ?? throw new ArgumentNullException(nameof(context)); EntityTypes.AddAll(context.EntityService); }
public PathBuilder(ICypherFluentQuery query, AnnotationsContext context = null) : base(query, context) { }
protected Repository(AnnotationsContext context) { Db = context; DbSet = Db.Set <TEntity>(); }
/// <summary> /// Initializes a new instance of the <see cref="UserStore{TUser}" /> class using an already initialized Neo4j /// GrpahClient. /// </summary> public UserStore(AnnotationsContext context) : base(context) { context.EntityService.AddEntityType(typeof(TUser)); }
/// <summary> /// Initializes a new instance of the <see cref="RoleStore{TRole}" /> class /// </summary> /// <param name="database">The database.</param> public RoleStore(AnnotationsContext context) : base(context) { context.EntityService.AddEntityType(typeof(TRole)); }
public QueryWriterWrapper(QueryWriter queryWriter, AnnotationsContext annotationsContext) { QueryWriter = queryWriter ?? throw new ArgumentNullException(nameof(queryWriter)); AnnotationsContext = annotationsContext ?? throw new ArgumentNullException(nameof(annotationsContext)); IsBoltClient = annotationsContext.IsBoltClient; }
public UnitOfWork(AnnotationsContext context) { _context = context; }
public static bool CheckAudited( AnnotationsContext annotationsContext, ISymbol symbol, DiagnosticSink diagnosticSink, out Location location) { // Collect audit information var hasStaticAudited = annotationsContext.Statics.Audited.IsDefined(symbol); var hasStaticUnaudited = annotationsContext.Statics.Unaudited.IsDefined(symbol); var hasMutabilityAudited = annotationsContext.Mutability.Audited.IsDefined(symbol); var hasMutabilityUnaudited = annotationsContext.Mutability.Unaudited.IsDefined(symbol); var hasBothStaticsAttributes = hasStaticAudited && hasStaticUnaudited; var hasBothMutabilityAttributes = hasMutabilityAudited && hasMutabilityUnaudited; var hasEitherStaticsAttributes = hasStaticAudited || hasStaticUnaudited; var hasEitherMutabilityAttributes = hasMutabilityAudited || hasMutabilityUnaudited; // If there are no audits, don't do anything if (!hasEitherStaticsAttributes && !hasEitherMutabilityAttributes) { location = null; return(false); } var syntaxLocation = symbol .DeclaringSyntaxReferences[0] .GetSyntax() .GetLastToken() .GetLocation(); // Check if both static audits are applied if (hasBothStaticsAttributes) { var diagnostic = Diagnostic.Create( Diagnostics.ConflictingImmutability, syntaxLocation, "Statics.Audited", "Statics.Unaudited", symbol.Kind.ToString().ToLower()); diagnosticSink(diagnostic); } // Check if both mutability audits are applied if (hasBothMutabilityAttributes) { var diagnostic = Diagnostic.Create( Diagnostics.ConflictingImmutability, syntaxLocation, "Mutability.Audited", "Mutability.Unaudited", symbol.Kind.ToString().ToLower()); diagnosticSink(diagnostic); } AttributeData attr = null; if (symbol.IsStatic) { // Check if a static member is using mutability audits if (hasEitherMutabilityAttributes) { var diagnostic = Diagnostic.Create( Diagnostics.InvalidAuditType, syntaxLocation, "static", symbol.Kind.ToString().ToLower(), "Statics.*"); diagnosticSink(diagnostic); } attr = annotationsContext.Statics.Audited.GetAll(symbol).FirstOrDefault() ?? annotationsContext.Statics.Unaudited.GetAll(symbol).FirstOrDefault(); } else { // Check if a non-static member is using static audits if (hasEitherStaticsAttributes) { var diagnostic = Diagnostic.Create( Diagnostics.InvalidAuditType, syntaxLocation, "non-static", symbol.Kind.ToString().ToLower(), "Mutability.*"); diagnosticSink(diagnostic); } attr = annotationsContext.Mutability.Audited.GetAll(symbol).FirstOrDefault() ?? annotationsContext.Mutability.Unaudited.GetAll(symbol).FirstOrDefault(); } if (attr != null) { location = GetLocation(attr); return(true); } location = null; return(false); }
public Annotated(ICypherFluentQuery query, AnnotationsContext context = null) : this(query) { AnnotationsContext = context; }
public AnnotationRespository(AnnotationsContext context) : base(context) { }
public Path(IPathBuilder builder, AnnotationsContext context) : base(builder.CypherQuery, context) { Builder = builder; //PatternBuildStrategy = builder.PatternBuildStrategy; }
internal static void EnsureRightJObject(AnnotationsContext context, ref JObject valueJObject, out JObject valueMetadataJObject) { //the neo4jclient guys really messed things up here //so use heuristics to determine if we are passing the right data or not, and then get the right data //this is for deserialization only //example json received /* * { * "extensions": {}, * "metadata": { * "id": 176, * "labels": [ * "IdentityUser" * ], * "type": "INTEREST" //only for relationships * }, * "paged_traverse": "http://localhost:7474/db/data/node/176/paged/traverse/{returnType}{?pageSize,leaseTime}", * "outgoing_relationships": "http://localhost:7474/db/data/node/176/relationships/out", * "outgoing_typed_relationships": "http://localhost:7474/db/data/node/176/relationships/out/{-list|&|types}", * "labels": "http://localhost:7474/db/data/node/176/labels", * "create_relationship": "http://localhost:7474/db/data/node/176/relationships", * "traverse": "http://localhost:7474/db/data/node/176/traverse/{returnType}", * "all_relationships": "http://localhost:7474/db/data/node/176/relationships/all", * "all_typed_relationships": "http://localhost:7474/db/data/node/176/relationships/all/{-list|&|types}", * "property": "http://localhost:7474/db/data/node/176/properties/{key}", * "self": "http://localhost:7474/db/data/node/176", * "incoming_relationships": "http://localhost:7474/db/data/node/176/relationships/in", * "properties": "http://localhost:7474/db/data/node/176/properties", * "incoming_typed_relationships": "http://localhost:7474/db/data/node/176/relationships/in/{-list|&|types}", * "data": { * actual data ... * } * } */ valueMetadataJObject = null; var expectedProps = new Dictionary <string, JTokenType> { //{ "data", JTokenType.Object }, { "metadata", JTokenType.Object }, { "self", JTokenType.String } }; var _valueJObject = valueJObject; var hasDataJToken = _valueJObject.TryGetValue("data", out var dataJToken); var dataJObject = dataJToken as JObject; if (expectedProps.All(prop => _valueJObject[prop.Key]?.Type == prop.Value)) { //hopefully we are right //replace the jObject with "data" valueJObject = dataJObject; valueMetadataJObject = _valueJObject["metadata"] as JObject; } else if (hasDataJToken || context.IsBoltClient) { //most likely using bolt client if (hasDataJToken && _valueJObject.Count == 1) { //for bolt clients, the data property has to be the only child valueJObject = dataJObject; } if (dataJObject != null && dataJObject.TryGetValue(Defaults.BoltMetadataPropertyName, out var boltMetadata) && boltMetadata is JObject boltMetadataJObject) { //extract the metadata dataJObject.Remove(Defaults.BoltMetadataPropertyName); valueMetadataJObject = boltMetadataJObject; } } }