Exemple #1
0
        public override void VisitQueryBody(QueryBodySyntax node)
        {
            foreach (var clause in node.Clauses)
            {
                Visit(clause);
            }
            _proceed = false;

            if (node.Continuation == null)
            {
                Visit(node.SelectOrGroup);
                _proceed = true;
                return;
            }

            Visit(node.SelectOrGroup);
            _properties.Last = _properties.Last;
            foreach (string variable in _fromVariables.Where(v => v.Value == _linqIndex).Select(v => v.Key).ToList())
            {
                AddProperties(GetProperties(_variables[variable]));
                _fromVariables.Remove(variable);
                _variables.Remove(variable);
            }
            var variableDependences = new PropertyDependence();

            AddProperties(_properties.Last, variableDependences);
            _variables.Add(node.Continuation.Identifier.ValueText, variableDependences);
            _fromVariables.Add(node.Continuation.Identifier.ValueText, _linqIndex);
            Visit(node.Continuation);
            _proceed = true;
        }
Exemple #2
0
        public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
        {
            PropertyDependence initializerProperties;

            if (node.Initializer == null)
            {
                initializerProperties = new PropertyDependence();
            }
            else
            {
                var parameter = _semanticModel.GetSymbolInfo(node.Initializer).Symbol as ParameterSymbol;
                if (parameter == null)
                {
                    var getInitializerMembersVisitor = new GetMembersVisitor(this);
                    getInitializerMembersVisitor.Visit(node.Initializer);
                    initializerProperties = getInitializerMembersVisitor._properties;
                    AddProperties(getInitializerMembersVisitor._properties);
                }
                else
                {
                    initializerProperties = new PropertyDependence {
                        ParameterSymbol = parameter
                    }
                };
            }
            _variables.Add(node.Identifier.ValueText, initializerProperties);
            _proceed = true;
        }
Exemple #3
0
        public override void VisitConditionalExpression(ConditionalExpressionSyntax node)
        {
            var getConditionMembers = new GetMembersVisitor(this);

            getConditionMembers.Visit(node.Condition);
            AddProperties(getConditionMembers._properties);

            var getWhenTrueMembers = new GetMembersVisitor(this);

            getWhenTrueMembers.Visit(node.WhenTrue);
            AddProperties(getWhenTrueMembers._properties);

            var getWhenFalseMembers = new GetMembersVisitor(this);

            getWhenFalseMembers.Visit(node.WhenFalse);
            AddProperties(getWhenFalseMembers._properties);

            var last = new PropertyDependence();

            AddProperties(getWhenFalseMembers._properties.Last, last);
            AddProperties(getWhenTrueMembers._properties.Last, last);
            _properties.Last = last;

            _proceed = true;
        }
Exemple #4
0
        private List <List <PropertySymbolInfo> > GetProperties(PropertyDependence properties)
        {
            var value = new List <List <PropertySymbolInfo> >();

            GetPropertiesRecursive(properties, value);
            return(value);
        }
Exemple #5
0
 private void AddProperties(PropertyDependence addedProperties, PropertyDependence properties = null)
 {
     if (properties == null)
     {
         properties = _properties;
     }
     if (addedProperties.Error || properties.Error)
     {
         properties.Error = true;
         return;
     }
     AddProperties(addedProperties.Dependences, properties.Dependences);
     foreach (var addedPropertyDependences in addedProperties.PropertiesDependences)
     {
         PropertyDependence propertyDependences, last = null;
         if (!properties.PropertiesDependences.TryGetValue(addedPropertyDependences.Key, out propertyDependences))
         {
             properties.PropertiesDependences.Add(addedPropertyDependences.Key, propertyDependences = new PropertyDependence());
         }
         else
         {
             last = propertyDependences.Last;
             propertyDependences.ResetLast();
         }
         AddProperties(addedPropertyDependences.Value, propertyDependences);
         if (last != null)
         {
             AddProperties(propertyDependences.Last, last);
             propertyDependences.Last = last;
         }
     }
 }
Exemple #6
0
 private void GetPropertiesRecursive(PropertyDependence dependences, List <List <PropertySymbolInfo> > value)
 {
     AddProperties(dependences.Dependences, value);
     foreach (var propertyDependences in dependences.PropertiesDependences)
     {
         GetPropertiesRecursive(propertyDependences.Value, value);
     }
 }
Exemple #7
0
 private GetMembersVisitor(GetMembersVisitor @base,
                           Dictionary <string, PropertyDependence> variables = null)
     : this(
         @base._semanticModel, @base._specificationsElements, @base._serverFxDALInterfacesNamespace,
         @base._semanticModelPerMethods, @base._methodPerMethodSymbols, @base._getMethods,
         @base._extensionMethods, variables ?? @base._variables, @base._fromVariables, @base._linqIndex,
         @base._alreadyCalledMethods, @base._definePropertyDependences, @base._failed)
 {
     _fromOriginalMethod = false;
     _returnProperties   = @base._returnProperties;
 }
Exemple #8
0
 private void AddReturnProperties(PropertyDependence addedProperties)
 {
     if (addedProperties == null)
     {
         return;
     }
     if (_returnProperties == null)
     {
         _returnProperties = new PropertyDependence();
     }
     AddProperties(addedProperties.Last, _returnProperties);
 }
Exemple #9
0
 private GetMembersVisitor(ISemanticModel semanticModel, SpecificationsElements specificationsElements,
                           string serverFxDALInterfacesNamespace,
                           ConcurrentDictionary <MethodDeclarationSyntax, ISemanticModel> semanticModelPerMethods,
                           ConcurrentDictionary <string, MethodDeclarationSyntax> methodPerMethodSymbols,
                           Dictionary <string, List <MethodDeclarationSyntax> > getMethods, List <MethodDeclarationSyntax> extensionMethods,
                           Dictionary <string, PropertyDependence> variables, Dictionary <string, int> fromVariables,
                           int linqIndex, List <MethodSymbol> alreadyCalledMethods, bool definePropertyDependences, int failed = 0)
 {
     _semanticModel                  = semanticModel;
     _specificationsElements         = specificationsElements;
     _serverFxDALInterfacesNamespace = serverFxDALInterfacesNamespace;
     _semanticModelPerMethods        = semanticModelPerMethods;
     _methodPerMethodSymbols         = methodPerMethodSymbols;
     _getMethods                = getMethods;
     _extensionMethods          = extensionMethods;
     _variables                 = variables;
     _fromVariables             = fromVariables;
     _linqIndex                 = linqIndex;
     _alreadyCalledMethods      = alreadyCalledMethods;
     _properties                = new PropertyDependence();
     _definePropertyDependences = definePropertyDependences;
     _failed = failed;
 }
Exemple #10
0
        public override void VisitConditionalExpression(ConditionalExpressionSyntax node)
        {
            var getConditionMembers = new GetMembersVisitor(this);
            getConditionMembers.Visit(node.Condition);
            AddProperties(getConditionMembers._properties);

            var getWhenTrueMembers = new GetMembersVisitor(this);
            getWhenTrueMembers.Visit(node.WhenTrue);
            AddProperties(getWhenTrueMembers._properties);

            var getWhenFalseMembers = new GetMembersVisitor(this);
            getWhenFalseMembers.Visit(node.WhenFalse);
            AddProperties(getWhenFalseMembers._properties);

            var last = new PropertyDependence();
            AddProperties(getWhenFalseMembers._properties.Last, last);
            AddProperties(getWhenTrueMembers._properties.Last, last);
            _properties.Last = last;

            _proceed = true;
        }
Exemple #11
0
        public override void VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            var expressionSymbol = _semanticModel.GetSymbolInfo(node.Expression).Symbol;
            if (expressionSymbol is ITypeSymbol)
                return;
            var parameterSymbol = expressionSymbol as IParameterSymbol;
            PropertyDependence variableProperties;
            var propertySymbol = _semanticModel.GetSymbolInfo(node).Symbol as PropertySymbol;
            if (propertySymbol == null)
                return;
            bool systemProperty = propertySymbol.ContainingType.ContainingNamespace != null && propertySymbol.ContainingType.ContainingNamespace.ToString().StartsWith("System");
            if (systemProperty)
            {
                switch (propertySymbol.ContainingType.ConstructedFrom.ToString())
                {
                    case "System.Collections.Generic.KeyValuePair<TKey, TValue>":
                        _properties.Error = true;
                        _properties.Last.Error = true;
                        _proceed = true;
                        return;
                }
            }

            Action applyOnParameter = () =>
            {
                bool knownVariable = _variables.TryGetValue(parameterSymbol.Name, out variableProperties);
                if (knownVariable && variableProperties != null)
                {
                    PropertyDependence newLast;
                    if (variableProperties.PropertiesDependences.TryGetValue(propertySymbol.Name, out newLast))
                    {
                        _properties.Last = newLast.Last;
                        _properties = newLast;
                        _proceed = true;
                        return;
                    }
                }
                if (systemProperty)
                {
                    _proceed = true;
                    return;
                }
                if (knownVariable)
                {
                    if (variableProperties == null || variableProperties.Last.Dependences.Count == 0)
                        AddProperty(new List<PropertySymbolInfo>() { PropertySymbolInfo.Get(propertySymbol) });
                    else
                        foreach (var dp in variableProperties.Last.Dependences)
                            AddProperty(new List<PropertySymbolInfo>(dp) { PropertySymbolInfo.Get(propertySymbol) });
                    _proceed = true;
                }
            };
            if (parameterSymbol != null)
            {
                applyOnParameter();
                if (_proceed)
                    return;
            }

            {
                var membersVisitor = new GetMembersVisitor(this);
                membersVisitor.Visit(node.Expression);
                if ((parameterSymbol = membersVisitor._properties.ParameterSymbol) != null)
                {
                    applyOnParameter();
                    if (_proceed)
                        return;
                }
                AddProperties(membersVisitor._properties, _properties);
                PropertyDependence newLast;
                if (membersVisitor._properties.Last.PropertiesDependences.TryGetValue(propertySymbol.Name, out newLast))
                {
                    AddProperties(newLast);
                    _properties.Last = newLast.Last;
                    _proceed = true;
                    return;
                }
                if (systemProperty)
                {
                    _proceed = true;
                    return;
                }
                if (membersVisitor._properties.Dependences.Count != 0 || membersVisitor._properties.PropertiesDependences.Count != 0)
                {
                    var dependencesList = new List<List<PropertySymbolInfo>>();
                    foreach (var pd in membersVisitor._properties.Last.Dependences)
                    {
                        var dependences = new List<PropertySymbolInfo>(pd);
                        dependences.Add(PropertySymbolInfo.Get(propertySymbol));
                        AddProperty(dependences);
                        dependencesList.Add(dependences);
                    }
                    _properties.Last = new PropertyDependence { Dependences = dependencesList };
                    _proceed = true;
                }
            }
        }
Exemple #12
0
        public override void VisitQueryBody(QueryBodySyntax node)
        {
            foreach (var clause in node.Clauses)
                Visit(clause);
            _proceed = false;

            if (node.Continuation == null)
            {
                Visit(node.SelectOrGroup);
                _proceed = true;
                return;
            }

            Visit(node.SelectOrGroup);
            _properties.Last = _properties.Last;
            foreach (string variable in _fromVariables.Where(v => v.Value == _linqIndex).Select(v => v.Key).ToList())
            {
                AddProperties(GetProperties(_variables[variable]));
                _fromVariables.Remove(variable);
                _variables.Remove(variable);
            }
            var variableDependences = new PropertyDependence();
            AddProperties(_properties.Last, variableDependences);
            _variables.Add(node.Continuation.Identifier.ValueText, variableDependences);
            _fromVariables.Add(node.Continuation.Identifier.ValueText, _linqIndex);
            Visit(node.Continuation);
            _proceed = true;
        }
Exemple #13
0
 public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
 {
     PropertyDependence initializerProperties;
     if (node.Initializer == null)
         initializerProperties = new PropertyDependence();
     else
     {
         var parameter = _semanticModel.GetSymbolInfo(node.Initializer).Symbol as ParameterSymbol;
         if (parameter == null)
         {
             var getInitializerMembersVisitor = new GetMembersVisitor(this);
             getInitializerMembersVisitor.Visit(node.Initializer);
             initializerProperties = getInitializerMembersVisitor._properties;
             AddProperties(getInitializerMembersVisitor._properties);
         }
         else
             initializerProperties = new PropertyDependence { ParameterSymbol = parameter };
     }
     _variables.Add(node.Identifier.ValueText, initializerProperties);
     _proceed = true;
 }
Exemple #14
0
        public override void VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            var expressionSymbol = _semanticModel.GetSymbolInfo(node.Expression).Symbol;

            if (expressionSymbol is ITypeSymbol)
            {
                return;
            }
            var parameterSymbol = expressionSymbol as IParameterSymbol;
            PropertyDependence variableProperties;
            var propertySymbol = _semanticModel.GetSymbolInfo(node).Symbol as PropertySymbol;

            if (propertySymbol == null)
            {
                return;
            }
            bool systemProperty = propertySymbol.ContainingType.ContainingNamespace != null && propertySymbol.ContainingType.ContainingNamespace.ToString().StartsWith("System");

            if (systemProperty)
            {
                switch (propertySymbol.ContainingType.ConstructedFrom.ToString())
                {
                case "System.Collections.Generic.KeyValuePair<TKey, TValue>":
                    _properties.Error      = true;
                    _properties.Last.Error = true;
                    _proceed = true;
                    return;
                }
            }

            Action applyOnParameter = () =>
            {
                bool knownVariable = _variables.TryGetValue(parameterSymbol.Name, out variableProperties);
                if (knownVariable && variableProperties != null)
                {
                    PropertyDependence newLast;
                    if (variableProperties.PropertiesDependences.TryGetValue(propertySymbol.Name, out newLast))
                    {
                        _properties.Last = newLast.Last;
                        _properties      = newLast;
                        _proceed         = true;
                        return;
                    }
                }
                if (systemProperty)
                {
                    _proceed = true;
                    return;
                }
                if (knownVariable)
                {
                    if (variableProperties == null || variableProperties.Last.Dependences.Count == 0)
                    {
                        AddProperty(new List <PropertySymbolInfo>()
                        {
                            PropertySymbolInfo.Get(propertySymbol)
                        });
                    }
                    else
                    {
                        foreach (var dp in variableProperties.Last.Dependences)
                        {
                            AddProperty(new List <PropertySymbolInfo>(dp)
                            {
                                PropertySymbolInfo.Get(propertySymbol)
                            });
                        }
                    }
                    _proceed = true;
                }
            };

            if (parameterSymbol != null)
            {
                applyOnParameter();
                if (_proceed)
                {
                    return;
                }
            }

            {
                var membersVisitor = new GetMembersVisitor(this);
                membersVisitor.Visit(node.Expression);
                if ((parameterSymbol = membersVisitor._properties.ParameterSymbol) != null)
                {
                    applyOnParameter();
                    if (_proceed)
                    {
                        return;
                    }
                }
                AddProperties(membersVisitor._properties, _properties);
                PropertyDependence newLast;
                if (membersVisitor._properties.Last.PropertiesDependences.TryGetValue(propertySymbol.Name, out newLast))
                {
                    AddProperties(newLast);
                    _properties.Last = newLast.Last;
                    _proceed         = true;
                    return;
                }
                if (systemProperty)
                {
                    _proceed = true;
                    return;
                }
                if (membersVisitor._properties.Dependences.Count != 0 || membersVisitor._properties.PropertiesDependences.Count != 0)
                {
                    var dependencesList = new List <List <PropertySymbolInfo> >();
                    foreach (var pd in membersVisitor._properties.Last.Dependences)
                    {
                        var dependences = new List <PropertySymbolInfo>(pd);
                        dependences.Add(PropertySymbolInfo.Get(propertySymbol));
                        AddProperty(dependences);
                        dependencesList.Add(dependences);
                    }
                    _properties.Last = new PropertyDependence {
                        Dependences = dependencesList
                    };
                    _proceed = true;
                }
            }
        }
Exemple #15
0
        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var methodSymbol = (MethodSymbol)_semanticModel.GetSymbolInfo(node).Symbol;

            if (methodSymbol == null || !(methodSymbol.IsStatic || _specificationsElements.GetSpecificationEquivalentMethod(ref methodSymbol) || methodSymbol.ContainingNamespace.ToString() == "System.Linq"))
            {
                return;
            }
            var argumentExpressions    = node.ArgumentList.Arguments.Select(a => a.Expression).ToList();
            var memberAccessExpression = node.Expression as MemberAccessExpressionSyntax;

            if (memberAccessExpression != null && (_semanticModel.GetSymbolInfo(memberAccessExpression.Expression).Symbol as ITypeSymbol) == null)
            {
                argumentExpressions.Insert(0, memberAccessExpression.Expression);
            }
            string methodSymbolString = methodSymbol.ToString();
            MethodDeclarationSyntax method;

            if (_methodPerMethodSymbols.TryGetValue(methodSymbolString, out method))
            {
                if (_alreadyCalledMethods.Contains(methodSymbol))
                {
                    if (++_failed > MaxFailed)
                    {
                        return;
                    }
                }
                else
                {
                    _alreadyCalledMethods.Add(methodSymbol);
                }
                if (_getMethods.Values.SelectMany(m => m).Contains(method))
                {
                    var membersVisitor = new GetMembersVisitor(this);
                    membersVisitor.Visit(argumentExpressions[0]);
                    AddProperties(membersVisitor._properties);
                    AddProperty(new List <PropertySymbolInfo>(LastOrDefault(membersVisitor._properties.Dependences))
                    {
                        new PropertySymbolInfo(TypeSymbolInfo.Get(methodSymbol.ReturnType),
                                               SpecificationMethods.GetPropertyNameFromMethod(method), TypeSymbolInfo.Get(methodSymbol.Parameters[0].Type),
                                               method)
                    });
                }
                else
                {
                    var variables = new Dictionary <string, PropertyDependence>();
                    int index     = 0;
                    foreach (var argumentExpression in argumentExpressions)
                    {
                        var membersVisitor = new GetMembersVisitor(this);
                        membersVisitor.Visit(argumentExpression);
                        AddProperties(membersVisitor._properties);
                        if (membersVisitor._properties.Dependences.GroupBy(p => p.Count).All(g => g.Count() == 1))
                        {
                            variables.Add(methodSymbol.Parameters[index].Name, membersVisitor._properties);
                        }
                        index++;
                    }
                    {
                        var semanticModel  = _semanticModelPerMethods[method];
                        var membersVisitor = new GetMembersVisitor(semanticModel, _specificationsElements,
                                                                   _serverFxDALInterfacesNamespace, _semanticModelPerMethods, _methodPerMethodSymbols,
                                                                   _getMethods, _extensionMethods, variables, _fromVariables, _linqIndex, _alreadyCalledMethods,
                                                                   _definePropertyDependences, _failed);
                        membersVisitor._returnProperties = new PropertyDependence();
                        membersVisitor.Visit(method.Body);
                        AddProperties(membersVisitor._properties);
                        if (!(membersVisitor._returnProperties.Dependences.Count == 0 && membersVisitor._returnProperties.PropertiesDependences.Count == 0))
                        {
                            _properties.Last = membersVisitor._returnProperties;
                        }
                        _proceed = true;
                    }
                }
            }
            else
            {
                if (methodSymbol.ContainingNamespace.ToString() == "System.Linq")
                {
                    var membersVisitor = new GetMembersVisitor(this);
                    membersVisitor.Visit(argumentExpressions[0]);
                    if (membersVisitor._properties.Last != null)
                    {
                        _properties.Last = membersVisitor._properties.Last;
                    }
                    AddProperties(membersVisitor._properties);
                    Action <int, Action <PropertyDependence> > visitLambda = (argumentIndex, addProperties) =>
                    {
                        var lambdaExpression = argumentExpressions[argumentIndex] as SimpleLambdaExpressionSyntax;
                        if (lambdaExpression != null)
                        {
                            var variables = new Dictionary <string, PropertyDependence>(_variables);
                            if (!variables.ContainsKey(lambdaExpression.Parameter.Identifier.ValueText))
                            {
                                variables.Add(lambdaExpression.Parameter.Identifier.ValueText, _properties);
                            }
                            else
                            {
                                variables[lambdaExpression.Parameter.Identifier.ValueText] = _properties;
                            }
                            membersVisitor = new GetMembersVisitor(this, variables);
                            membersVisitor._returnProperties = null;
                            membersVisitor.Visit(lambdaExpression.Body);
                            addProperties(membersVisitor._properties);
                            _proceed = true;
                        }
                    };
                    switch (argumentExpressions.Count)
                    {
                    case 1:
                        _properties.Last = membersVisitor._properties.Last;
                        _proceed         = true;
                        break;

                    case 2:
                        bool applyLast = false;
                        switch (methodSymbol.Name)
                        {
                        case "Where":
                        case "OrderBy":
                        case "OrderByDescending":
                        case "ThenBy":
                        case "ThenByDescending":
                        case "Take":
                        case "Skip":
                        case "First":
                        case "FirstOrDefault":
                        case "Last":
                        case "LastOrDefault":
                        case "Single":
                        case "SingleOrDefault":
                            _properties.Last = membersVisitor._properties.Last;
                            break;

                        case "GroupBy":
                            _properties.Last = membersVisitor._properties.Last;
                            visitLambda(1, pd =>
                            {
                                if (_properties.PropertiesDependences.ContainsKey("Key"))
                                {
                                    _properties.PropertiesDependences["Key"] = pd;
                                }
                                else
                                {
                                    _properties.PropertiesDependences.Add("Key", pd);
                                }
                            });
                            _properties.ResetLast();
                            return;

                        case "Union":
                        case "Intersect":
                            membersVisitor = new GetMembersVisitor(this);
                            membersVisitor.Visit(argumentExpressions[1]);
                            AddProperties(membersVisitor._properties);
                            AddProperties(membersVisitor._properties.Last, _properties.Last);
                            _proceed = true;
                            return;

                        default:
                            applyLast = true;
                            break;
                        }
                        visitLambda(1, pd =>
                        {
                            AddProperties(pd);
                            if (applyLast)
                            {
                                _properties.Last = pd.Last;
                            }
                        });
                        break;

                    case 3:
                        switch (methodSymbol.Name)
                        {
                        case "SelectMany":
                            var last = membersVisitor._properties.Last;
                            _properties.Last = last;
                            var collectionDependence = new PropertyDependence();
                            visitLambda(1, pd =>
                            {
                                AddProperties(pd);
                                AddProperties(pd, collectionDependence);
                            });
                            _properties.ResetLast();
                            var lambdaExpression = (ParenthesizedLambdaExpressionSyntax)argumentExpressions[2];
                            var variables        = new Dictionary <string, PropertyDependence>(_variables);
                            var parameter        = lambdaExpression.ParameterList.Parameters[0];
                            if (!variables.ContainsKey(parameter.Identifier.ValueText))
                            {
                                variables.Add(parameter.Identifier.ValueText, last);
                            }
                            else
                            {
                                variables[parameter.Identifier.ValueText] = last;
                            }
                            parameter = lambdaExpression.ParameterList.Parameters[1];
                            if (!variables.ContainsKey(parameter.Identifier.ValueText))
                            {
                                variables.Add(parameter.Identifier.ValueText, collectionDependence.Last);
                            }
                            else
                            {
                                variables[parameter.Identifier.ValueText] = collectionDependence.Last;
                            }
                            membersVisitor = new GetMembersVisitor(this, variables);
                            membersVisitor.Visit(lambdaExpression.Body);
                            AddProperties(membersVisitor._properties);
                            _properties.Last = membersVisitor._properties;
                            _proceed         = true;
                            return;
                        }
                        break;

                    case 5:
                        switch (methodSymbol.Name)
                        {
                        case "Join":
                        case "GroupJoin":
                            var last = membersVisitor._properties.Last;
                            membersVisitor = new GetMembersVisitor(this);
                            membersVisitor.Visit(argumentExpressions[1]);
                            AddProperties(membersVisitor._properties);
                            var joinLast = membersVisitor._properties.Last;
                            _properties.Last = last;
                            visitLambda(2, pd => AddProperties(pd));
                            _proceed         = false;
                            _properties.Last = joinLast;
                            visitLambda(3, pd => AddProperties(pd));
                            _proceed = false;
                            _properties.ResetLast();
                            var lambdaExpression = (ParenthesizedLambdaExpressionSyntax)argumentExpressions[4];
                            var variables        = new Dictionary <string, PropertyDependence>(_variables);
                            var parameter        = lambdaExpression.ParameterList.Parameters[0];
                            if (!variables.ContainsKey(parameter.Identifier.ValueText))
                            {
                                variables.Add(parameter.Identifier.ValueText, last);
                            }
                            else
                            {
                                variables[parameter.Identifier.ValueText] = last;
                            }
                            parameter = lambdaExpression.ParameterList.Parameters[1];
                            if (!variables.ContainsKey(parameter.Identifier.ValueText))
                            {
                                variables.Add(parameter.Identifier.ValueText, joinLast);
                            }
                            else
                            {
                                variables[parameter.Identifier.ValueText] = joinLast;
                            }
                            membersVisitor = new GetMembersVisitor(this, variables);
                            membersVisitor.Visit(lambdaExpression.Body);
                            AddProperties(membersVisitor._properties);
                            _properties.Last = membersVisitor._properties;
                            _proceed         = true;
                            return;
                        }
                        break;
                    }
                }
            }
        }
Exemple #16
0
 private void AddProperties(PropertyDependence addedProperties, PropertyDependence properties = null)
 {
     if (properties == null)
         properties = _properties;
     if (addedProperties.Error || properties.Error)
     {
         properties.Error = true;
         return;
     }
     AddProperties(addedProperties.Dependences, properties.Dependences);
     foreach (var addedPropertyDependences in addedProperties.PropertiesDependences)
     {
         PropertyDependence propertyDependences, last = null;
         if (!properties.PropertiesDependences.TryGetValue(addedPropertyDependences.Key, out propertyDependences))
             properties.PropertiesDependences.Add(addedPropertyDependences.Key, propertyDependences = new PropertyDependence());
         else
         {
             last = propertyDependences.Last;
             propertyDependences.ResetLast();
         }
         AddProperties(addedPropertyDependences.Value, propertyDependences);
         if (last != null)
         {
             AddProperties(propertyDependences.Last, last);
             propertyDependences.Last = last;
         }
     }
 }
Exemple #17
0
 private GetMembersVisitor(GetMembersVisitor @base,
     Dictionary<string, PropertyDependence> variables = null)
     : this(@base._semanticModel, @base._specificationsElements, @base._serverFxDALInterfacesNamespace,
         @base._semanticModelPerMethods, @base._methodPerMethodSymbols, @base._getMethods,
         @base._extensionMethods, variables ?? @base._variables, @base._fromVariables, @base._linqIndex,
         @base._alreadyCalledMethods, @base._definePropertyDependences, @base._failed)
 {
     _fromOriginalMethod = false;
     _returnProperties = @base._returnProperties;
 }
Exemple #18
0
 public void ResetLast()
 {
     _last = null;
 }
Exemple #19
0
 private void AddReturnProperties(PropertyDependence addedProperties)
 {
     if (addedProperties == null)
         return;
     if (_returnProperties == null)
         _returnProperties = new PropertyDependence();
     AddProperties(addedProperties.Last, _returnProperties);
 }
Exemple #20
0
 public override void VisitInvocationExpression(InvocationExpressionSyntax node)
 {
     var methodSymbol = (MethodSymbol)_semanticModel.GetSymbolInfo(node).Symbol;
     if (methodSymbol == null || !(methodSymbol.IsStatic || _specificationsElements.GetSpecificationEquivalentMethod(ref methodSymbol) || methodSymbol.ContainingNamespace.ToString() == "System.Linq"))
         return;
     var argumentExpressions = node.ArgumentList.Arguments.Select(a => a.Expression).ToList();
     var memberAccessExpression = node.Expression as MemberAccessExpressionSyntax;
     if (memberAccessExpression != null && (_semanticModel.GetSymbolInfo(memberAccessExpression.Expression).Symbol as ITypeSymbol) == null)
         argumentExpressions.Insert(0, memberAccessExpression.Expression);
     string methodSymbolString = methodSymbol.ToString();
     MethodDeclarationSyntax method;
     if (_methodPerMethodSymbols.TryGetValue(methodSymbolString, out method))
     {
         if (_alreadyCalledMethods.Contains(methodSymbol))
         {
             if (++_failed > MaxFailed)
                 return;
         }
         else
             _alreadyCalledMethods.Add(methodSymbol);
         if (_getMethods.Values.SelectMany(m => m).Contains(method))
         {
             var membersVisitor = new GetMembersVisitor(this);
             membersVisitor.Visit(argumentExpressions[0]);
             AddProperties(membersVisitor._properties);
             AddProperty(new List<PropertySymbolInfo>(LastOrDefault(membersVisitor._properties.Dependences))
             {
                 new PropertySymbolInfo(TypeSymbolInfo.Get(methodSymbol.ReturnType),
                     SpecificationMethods.GetPropertyNameFromMethod(method), TypeSymbolInfo.Get(methodSymbol.Parameters[0].Type),
                     method)
             });
         }
         else
         {
             var variables = new Dictionary<string, PropertyDependence>();
             int index = 0;
             foreach (var argumentExpression in argumentExpressions)
             {
                 var membersVisitor = new GetMembersVisitor(this);
                 membersVisitor.Visit(argumentExpression);
                 AddProperties(membersVisitor._properties);
                 if (membersVisitor._properties.Dependences.GroupBy(p => p.Count).All(g => g.Count() == 1))
                     variables.Add(methodSymbol.Parameters[index].Name, membersVisitor._properties);
                 index++;
             }
             {
                 var semanticModel = _semanticModelPerMethods[method];
                 var membersVisitor = new GetMembersVisitor(semanticModel, _specificationsElements,
                     _serverFxDALInterfacesNamespace, _semanticModelPerMethods, _methodPerMethodSymbols,
                     _getMethods, _extensionMethods, variables, _fromVariables, _linqIndex, _alreadyCalledMethods,
                     _definePropertyDependences, _failed);
                 membersVisitor._returnProperties = new PropertyDependence();
                 membersVisitor.Visit(method.Body);
                 AddProperties(membersVisitor._properties);
                 if (!(membersVisitor._returnProperties.Dependences.Count == 0 && membersVisitor._returnProperties.PropertiesDependences.Count == 0))
                     _properties.Last = membersVisitor._returnProperties;
                 _proceed = true;
             }
         }
     }
     else
     {
         if (methodSymbol.ContainingNamespace.ToString() == "System.Linq")
         {
             var membersVisitor = new GetMembersVisitor(this);
             membersVisitor.Visit(argumentExpressions[0]);
             if (membersVisitor._properties.Last != null)
                 _properties.Last = membersVisitor._properties.Last;
             AddProperties(membersVisitor._properties);
             Action<int, Action<PropertyDependence>> visitLambda = (argumentIndex, addProperties) =>
             {
                 var lambdaExpression = argumentExpressions[argumentIndex] as SimpleLambdaExpressionSyntax;
                 if (lambdaExpression != null)
                 {
                     var variables = new Dictionary<string, PropertyDependence>(_variables);
                     if (!variables.ContainsKey(lambdaExpression.Parameter.Identifier.ValueText))
                         variables.Add(lambdaExpression.Parameter.Identifier.ValueText, _properties);
                     else
                         variables[lambdaExpression.Parameter.Identifier.ValueText] = _properties;
                     membersVisitor = new GetMembersVisitor(this, variables);
                     membersVisitor._returnProperties = null;
                     membersVisitor.Visit(lambdaExpression.Body);
                     addProperties(membersVisitor._properties);
                     _proceed = true;
                 }
             };
             switch (argumentExpressions.Count)
             {
                 case 1:
                     _properties.Last = membersVisitor._properties.Last;
                     _proceed = true;
                     break;
                 case 2:
                     bool applyLast = false;
                     switch (methodSymbol.Name)
                     {
                         case "Where":
                         case "OrderBy":
                         case "OrderByDescending":
                         case "ThenBy":
                         case "ThenByDescending":
                         case "Take":
                         case "Skip":
                         case "First":
                         case "FirstOrDefault":
                         case "Last":
                         case "LastOrDefault":
                         case "Single":
                         case "SingleOrDefault":
                             _properties.Last = membersVisitor._properties.Last;
                             break;
                         case "GroupBy":
                             _properties.Last = membersVisitor._properties.Last;
                             visitLambda(1, pd =>
                             {
                                 if (_properties.PropertiesDependences.ContainsKey("Key"))
                                     _properties.PropertiesDependences["Key"] = pd;
                                 else
                                     _properties.PropertiesDependences.Add("Key", pd);
                             });
                             _properties.ResetLast();
                             return;
                         case "Union":
                         case "Intersect":
                             membersVisitor = new GetMembersVisitor(this);
                             membersVisitor.Visit(argumentExpressions[1]);
                             AddProperties(membersVisitor._properties);
                             AddProperties(membersVisitor._properties.Last, _properties.Last);
                             _proceed = true;
                             return;
                         default:
                             applyLast = true;
                             break;
                     }
                     visitLambda(1, pd =>
                     {
                         AddProperties(pd);
                         if (applyLast)
                             _properties.Last = pd.Last;
                     });
                     break;
                 case 3:
                     switch (methodSymbol.Name)
                     {
                         case "SelectMany":
                             var last = membersVisitor._properties.Last;
                             _properties.Last = last;
                             var collectionDependence = new PropertyDependence();
                             visitLambda(1, pd =>
                             {
                                 AddProperties(pd);
                                 AddProperties(pd, collectionDependence);
                             });
                             _properties.ResetLast();
                             var lambdaExpression = (ParenthesizedLambdaExpressionSyntax)argumentExpressions[2];
                             var variables = new Dictionary<string, PropertyDependence>(_variables);
                             var parameter = lambdaExpression.ParameterList.Parameters[0];
                             if (!variables.ContainsKey(parameter.Identifier.ValueText))
                                 variables.Add(parameter.Identifier.ValueText, last);
                             else
                                 variables[parameter.Identifier.ValueText] = last;
                             parameter = lambdaExpression.ParameterList.Parameters[1];
                             if (!variables.ContainsKey(parameter.Identifier.ValueText))
                                 variables.Add(parameter.Identifier.ValueText, collectionDependence.Last);
                             else
                                 variables[parameter.Identifier.ValueText] = collectionDependence.Last;
                             membersVisitor = new GetMembersVisitor(this, variables);
                             membersVisitor.Visit(lambdaExpression.Body);
                             AddProperties(membersVisitor._properties);
                             _properties.Last = membersVisitor._properties;
                             _proceed = true;
                             return;
                     }
                     break;
                 case 5:
                     switch (methodSymbol.Name)
                     {
                         case "Join":
                         case "GroupJoin":
                             var last = membersVisitor._properties.Last;
                             membersVisitor = new GetMembersVisitor(this);
                             membersVisitor.Visit(argumentExpressions[1]);
                             AddProperties(membersVisitor._properties);
                             var joinLast = membersVisitor._properties.Last;
                             _properties.Last = last;
                             visitLambda(2, pd => AddProperties(pd));
                             _proceed = false;
                             _properties.Last = joinLast;
                             visitLambda(3, pd => AddProperties(pd));
                             _proceed = false;
                             _properties.ResetLast();
                             var lambdaExpression = (ParenthesizedLambdaExpressionSyntax)argumentExpressions[4];
                             var variables = new Dictionary<string, PropertyDependence>(_variables);
                             var parameter = lambdaExpression.ParameterList.Parameters[0];
                             if (!variables.ContainsKey(parameter.Identifier.ValueText))
                                 variables.Add(parameter.Identifier.ValueText, last);
                             else
                                 variables[parameter.Identifier.ValueText] = last;
                             parameter = lambdaExpression.ParameterList.Parameters[1];
                             if (!variables.ContainsKey(parameter.Identifier.ValueText))
                                 variables.Add(parameter.Identifier.ValueText, joinLast);
                             else
                                 variables[parameter.Identifier.ValueText] = joinLast;
                             membersVisitor = new GetMembersVisitor(this, variables);
                             membersVisitor.Visit(lambdaExpression.Body);
                             AddProperties(membersVisitor._properties);
                             _properties.Last = membersVisitor._properties;
                             _proceed = true;
                             return;
                     }
                     break;
             }
         }
     }
 }
Exemple #21
0
 public void ResetLast()
 {
     _last = null;
 }
Exemple #22
0
 private GetMembersVisitor(ISemanticModel semanticModel, SpecificationsElements specificationsElements,
     string serverFxDALInterfacesNamespace,
     ConcurrentDictionary<MethodDeclarationSyntax, ISemanticModel> semanticModelPerMethods,
     ConcurrentDictionary<string, MethodDeclarationSyntax> methodPerMethodSymbols,
     Dictionary<string, List<MethodDeclarationSyntax>> getMethods, List<MethodDeclarationSyntax> extensionMethods,
     Dictionary<string, PropertyDependence> variables, Dictionary<string, int> fromVariables,
     int linqIndex, List<MethodSymbol> alreadyCalledMethods, bool definePropertyDependences, int failed = 0)
 {
     _semanticModel = semanticModel;
     _specificationsElements = specificationsElements;
     _serverFxDALInterfacesNamespace = serverFxDALInterfacesNamespace;
     _semanticModelPerMethods = semanticModelPerMethods;
     _methodPerMethodSymbols = methodPerMethodSymbols;
     _getMethods = getMethods;
     _extensionMethods = extensionMethods;
     _variables = variables;
     _fromVariables = fromVariables;
     _linqIndex = linqIndex;
     _alreadyCalledMethods = alreadyCalledMethods;
     _properties = new PropertyDependence();
     _definePropertyDependences = definePropertyDependences;
     _failed = failed;
 }
Exemple #23
0
 private void GetPropertiesRecursive(PropertyDependence dependences, List<List<PropertySymbolInfo>> value)
 {
     AddProperties(dependences.Dependences, value);
     foreach (var propertyDependences in dependences.PropertiesDependences)
         GetPropertiesRecursive(propertyDependences.Value, value);
 }
Exemple #24
0
 private List<List<PropertySymbolInfo>> GetProperties(PropertyDependence properties)
 {
     var value = new List<List<PropertySymbolInfo>>();
     GetPropertiesRecursive(properties, value);
     return value;
 }