protected override void Run(IDeclaration declaration, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) { var declaredElement = declaration.DeclaredElement; var attributesSet = declaredElement as IAttributesSet; var hasOveriddenImplicitNullability = false; if (attributesSet != null) { Assertion.Assert(declaredElement != null, "declaredElement != null"); var attributeInstances = attributesSet.GetAttributeInstances(inherit: false); switch (declaration) { case IParameterDeclaration parameterDeclaration: var parameter = parameterDeclaration.DeclaredElement.NotNull(); CheckForNotNullOnImplicitCanBeNull(consumer, parameter, attributeInstances, declaration); CheckForParameterSuperMemberConflicts(consumer, parameter, attributeInstances, declaration); break; case IMethodDeclaration methodDeclaration: var method = methodDeclaration.DeclaredElement.NotNull(); CheckForNotNullOnImplicitCanBeNull(consumer, method, attributeInstances, methodDeclaration.NameIdentifier); CheckForMethodSuperMemberConflicts(consumer, method, attributeInstances, methodDeclaration.NameIdentifier); break; case IOperatorDeclaration operatorDeclaration: var operatorKeyword = operatorDeclaration.OperatorKeyword; CheckForNotNullOnImplicitCanBeNull(consumer, declaredElement, attributeInstances, operatorKeyword); break; case IDelegateDeclaration delegateDeclaration: var delegateName = delegateDeclaration.NameIdentifier; CheckForNotNullOnImplicitCanBeNull(consumer, declaredElement, attributeInstances, delegateName); break; case IFieldDeclaration fieldDeclaration: var fieldName = fieldDeclaration.NameIdentifier; CheckForNotNullOnImplicitCanBeNull(consumer, declaredElement, attributeInstances, fieldName); break; case IPropertyDeclaration propertyDeclaration: var property = propertyDeclaration.DeclaredElement.NotNull(); var propertyName = propertyDeclaration.NameIdentifier; CheckForNotNullOnImplicitCanBeNull(consumer, declaredElement, attributeInstances, propertyName); CheckForPropertySuperMemberConflicts(consumer, property, attributeInstances, propertyName); break; case IIndexerDeclaration indexerDeclaration: var indexerProperty = indexerDeclaration.DeclaredElement.NotNull(); var indexerThisKeyword = indexerDeclaration.ThisKeyword; CheckForNotNullOnImplicitCanBeNull(consumer, declaredElement, attributeInstances, indexerThisKeyword); CheckForPropertySuperMemberConflicts(consumer, indexerProperty, attributeInstances, indexerThisKeyword); break; } hasOveriddenImplicitNullability |= _annotationAttributesChecker.ContainsAnyExplicitNullabilityAttributes(attributeInstances) && _implicitNullabilityProvider.AnalyzeDeclaredElement(declaredElement) != null; hasOveriddenImplicitNullability |= _annotationAttributesChecker.ContainsAnyExplicitItemNullabilityAttributes(attributeInstances) && _implicitNullabilityProvider.AnalyzeDeclaredElementContainerElement(declaredElement) != null; } DelegateToIncorrectNullableAttributeUsageAnalyzer(declaration, data, consumer, hasOveriddenImplicitNullability); }
public CodeAnnotationNullableValue?GetContainerElementNullableAttribute([CanBeNull] IDeclaredElement element) { return(_implicitNullabilityProvider.AnalyzeDeclaredElementContainerElement(element)); }