public object Build(IPsiAssembly assembly) { SpecflowStepsDefinitionsCacheEntries stepDefinitions = null; _psiAssemblyFileLoader.GetOrLoadAssembly(assembly, true, (psiAssembly, assemblyFile, metadataAssembly) => { stepDefinitions = new SpecflowStepsDefinitionsCacheEntries(); foreach (var type in metadataAssembly.GetTypes()) { if (type.CustomAttributesTypeNames.All(a => a.FullName.GetText() != SpecflowAttributeHelper.BindingAttribute.FullName)) { continue; } var classCacheEntry = new SpecflowStepDefinitionCacheClassEntry(type.FullyQualifiedName, true); foreach (var method in type.GetMethods().Where(x => x.IsPublic)) { // FIXME: We should avoid adding method that are not step here (it's just using more memory) var methodCacheEntry = classCacheEntry.AddMethod(method.Name); for (var index = 0; index < method.CustomAttributes.Length; index++) { var attributeInstance = method.CustomAttributes[index]; if (attributeInstance.ConstructorArguments.Length == 0) { continue; } var regex = attributeInstance.ConstructorArguments[0].Value as string; if (regex == null) { continue; } var attributeTypeName = method.CustomAttributesTypeNames[index].FullName.ToString(); if (SpecflowAttributeHelper.IsAttributeForKind(GherkinStepKind.Given, attributeTypeName)) { methodCacheEntry.AddStep(GherkinStepKind.Given, regex); } if (SpecflowAttributeHelper.IsAttributeForKind(GherkinStepKind.When, attributeTypeName)) { methodCacheEntry.AddStep(GherkinStepKind.When, regex); } if (SpecflowAttributeHelper.IsAttributeForKind(GherkinStepKind.Then, attributeTypeName)) { methodCacheEntry.AddStep(GherkinStepKind.Then, regex); } } } stepDefinitions.Add(classCacheEntry); } }); return(stepDefinitions); }
private SpecflowStepDefinitionCacheClassEntry BuildBindingClassCacheEntry(IClassDeclaration classDeclaration, bool hasSpecflowBindingAttribute) { var classCacheEntry = new SpecflowStepDefinitionCacheClassEntry(classDeclaration.CLRName, hasSpecflowBindingAttribute); foreach (var member in classDeclaration.MemberDeclarations) { if (!(member is IMethodDeclaration methodDeclaration)) { continue; } var methodCacheEntry = classCacheEntry.AddMethod(methodDeclaration.DeclaredName); foreach (var attributeInstance in methodDeclaration.Attributes.Select(x => x.GetAttributeInstance())) { if (attributeInstance.PositionParameterCount == 0) { continue; } var parameter = attributeInstance.PositionParameter(0); var regex = parameter.ConstantValue.Value as string; if (regex == null) { continue; } if (SpecflowAttributeHelper.IsAttributeForKind(GherkinStepKind.Given, attributeInstance.GetAttributeType().GetClrName())) { methodCacheEntry.AddStep(GherkinStepKind.Given, regex); } if (SpecflowAttributeHelper.IsAttributeForKind(GherkinStepKind.When, attributeInstance.GetAttributeType().GetClrName())) { methodCacheEntry.AddStep(GherkinStepKind.When, regex); } if (SpecflowAttributeHelper.IsAttributeForKind(GherkinStepKind.Then, attributeInstance.GetAttributeType().GetClrName())) { methodCacheEntry.AddStep(GherkinStepKind.Then, regex); } } } return(classCacheEntry); }