public void ProcessBeforeInterior(ITreeNode element, FilteringHighlightingConsumer context) { if (!(element is IMethodDeclaration method)) { return; } var psiServices = method.GetPsiServices(); var invalidNames = new LocalList <string>(); foreach (var attribute in method.Attributes) { var stepKind = SpecflowAttributeHelper.GetAttributeStepKind(attribute.GetAttributeType().GetClrName()); if (stepKind == null) { continue; } var attributeInstance = attribute.GetAttributeInstance(); if (attributeInstance.PositionParameterCount < 1) { continue; } var constantValue = attributeInstance.PositionParameter(0).ConstantValue; if (!constantValue.IsValid()) { continue; } if (!(constantValue.Value is string stepText)) { continue; } var expectedMethodName = SpecflowStepHelper.GetMethodNameAndParameterFromStepPattern(stepKind.Value, stepText, psiServices, _daemonProcess.SourceFile, method.Params.ParameterDeclarations.Select(x => x.DeclaredName).ToList()); if (string.Equals(method.DeclaredName, expectedMethodName, StringComparison.InvariantCultureIgnoreCase)) { return; } if (method.DeclaredName.ToLowerInvariant().StartsWith(stepKind.ToString().ToLowerInvariant())) { invalidNames.Insert(0, expectedMethodName); } else { invalidNames.Add(expectedMethodName); } } if (invalidNames.Count > 0) { var expectedName = invalidNames.FirstOrDefault(); context.AddHighlighting(new MethodNameMismatchPatternInfo(method, expectedName)); } }
public void ProcessBeforeInterior(ITreeNode element, FilteringHighlightingConsumer context) { if (!(element is IMethodDeclaration method)) { return; } var psiServices = method.GetPsiServices(); var invalidNames = new LocalList <string>(); foreach (var attribute in method.Attributes) { var stepKind = SpecflowAttributeHelper.GetAttributeStepKind(attribute.GetAttributeType().GetClrName()); if (stepKind == null) { continue; } var attributeInstance = attribute.GetAttributeInstance(); if (attributeInstance.PositionParameterCount < 1) { continue; } var constantValue = attributeInstance.PositionParameter(0).ConstantValue; if (!constantValue.IsValid()) { continue; } if (!(constantValue.Value is string stepText)) { continue; } if (method.DeclaredElement == null) { continue; } var expectedMethodName = _stepDefinitionBuilder.GetStepDefinitionMethodNameFromPattern(stepKind.Value, stepText, method.DeclaredElement.Parameters.SelectNotNull(x => x.ShortName).ToArray()); expectedMethodName = psiServices.Naming.Suggestion.GetDerivedName(expectedMethodName, NamedElementKinds.Method, ScopeKind.Common, CSharpLanguage.Instance.NotNull(), new SuggestionOptions(), _daemonProcess.SourceFile); if (string.Equals(method.DeclaredName, expectedMethodName, StringComparison.InvariantCultureIgnoreCase)) { return; } if (method.DeclaredName.ToLowerInvariant().StartsWith(stepKind.ToString().ToLowerInvariant())) { invalidNames.Insert(0, expectedMethodName); } else { invalidNames.Add(expectedMethodName); } } if (invalidNames.Count > 0) { var expectedName = invalidNames.FirstOrDefault(); context.AddHighlighting(new MethodNameMismatchPatternInfo(method, expectedName)); } }