private ITypeElement GetRelatedTypeElementFromAttributeUsage(ICSharpLiteralExpression literalExpression) { var attribute = AttributeNavigator.GetByConstructorArgumentExpression(literalExpression); if (attribute == null) { return(null); } var argument = (ICSharpArgument)literalExpression.Parent.NotNull(); if (argument.MatchingParameter == null) { return(null); } var parameter = argument.MatchingParameter.Element; var constructor = attribute.ConstructorReference.GetResolved <IConstructor>().NotNull(); var literalArgumentIndex = constructor.Parameters.IndexOf(parameter); if (literalArgumentIndex == 0) { return(null); } var typeofExpression = attribute.Arguments[literalArgumentIndex - 1].Expression as ITypeofExpression; if (typeofExpression == null) { return(null); } return(((IDeclaredType)typeofExpression.ArgumentType).GetTypeElement()); }
public ReferenceCollection GetReferences(ITreeNode element, ReferenceCollection oldReferences) { // Protocol.TraceLogger.Log(LoggingLevel.INFO, $"GetReferences: {element.GetSourceFile()?.Name}: Node Type: {element.NodeType}"); if (element is ILiteralExpression literal && literal.ConstantValue.Value is string) { var argumentExpression = literal as ICSharpExpression; var attribute = AttributeNavigator.GetByConstructorArgumentExpression(argumentExpression); if (attribute?.Name.Reference.Resolve().DeclaredElement is IClass @class && Equals(@class.GetClrName(), GivenAttribute)) { // attribute.DumpObj(1); var stringRegexLiteral = attribute.ConstructorArgumentExpressions[0] as ILiteralExpression; var stringToken = stringRegexLiteral.Literal as CSharpGenericToken; var regexString = stringToken.GetText(); Protocol.TraceLogger.Log(LoggingLevel.INFO, $"Found GIVEN attribute with regex: {regexString}"); return(oldReferences); } } return(oldReferences); }
public IReference[] GetReferences(ITreeNode element, IReference[] oldReferences) { var literal = element as ILiteralExpression; if (literal != null && literal.ConstantValue.Value is string) { var attribute = AttributeNavigator.GetByConstructorArgumentExpression(literal as ICSharpExpression); if (attribute != null) { var @class = attribute.Name.Reference.Resolve().DeclaredElement as IClass; if (@class != null && Equals(@class.GetClrName(), XunitTestProvider.PropertyDataAttribute)) { var typeElement = (from a in attribute.PropertyAssignments where a.PropertyNameIdentifier.Name == "PropertyType" select GetTypeof(a.Source as ITypeofExpression)).FirstOrDefault(); var member = GetAppliedToMethodDeclaration(attribute); if (member != null && member.DeclaredElement != null && typeElement == null) { typeElement = member.DeclaredElement.GetContainingType(); } if (typeElement == null) { return(EmptyArray <IReference> .Instance); } var reference = new PropertyDataReference(typeElement, literal); return(oldReferences != null && oldReferences.Length == 1 && Equals(oldReferences[0], reference) ? oldReferences : new IReference[] { reference }); } } } return(EmptyArray <IReference> .Instance); }