Exemplo n.º 1
0
        private static IEnumerable <IComponentRegistration> CreateRegistration(IInvocationExpression invocationExpression, IDeclaredType first, IDeclaredType last)
        {
            if (first == null || last == null)
            {
                yield break;
            }

            ITypeElement fromType = first.GetTypeElement();
            ITypeElement toType   = last.GetTypeElement();

            if (fromType != null && toType != null)
            {
                yield return(fromType.Equals(toType)
                                 ? new ComponentRegistration(invocationExpression, fromType)
                                 : new ComponentRegistration(invocationExpression, fromType, toType));
            }
        }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            // todo for now assume that interfaces are not supported
            if (typeElement is IInterface)
            {
                return(false);
            }

            if (Implementation != null)
            {
                if (Implementation.IsGenericInterface())
                {
                    return(typeElement.IsDescendantOf(Implementation));
                }

                return(Implementation.Equals(typeElement));
            }

            return(serviceType.Equals(typeElement));
        }
Exemplo n.º 3
0
        private static IList <ITypeMember> GetStaticColorProperties(ITypeElement unityColorType)
        {
            var colorProperties = new LocalList <ITypeMember>();

            foreach (var typeMember in unityColorType.GetMembers())
            {
                if (!typeMember.IsStatic)
                {
                    continue;
                }

                var typeOwner = typeMember as ITypeOwner;
                if (typeOwner is IProperty || typeOwner is IField)
                {
                    var declaredType = typeOwner.Type as IDeclaredType;
                    if (declaredType != null && unityColorType.Equals(declaredType.GetTypeElement()))
                    {
                        colorProperties.Add(typeMember);
                    }
                }
            }

            return(colorProperties.ResultingList());
        }
Exemplo n.º 4
0
 private static bool IsDeclaredBy(IMethod declaredElement, ITypeElement typeElem)
 {
     return(typeElem.Equals(declaredElement.GetContainingType()));
 }
Exemplo n.º 5
0
        private static IList<ITypeMember> GetStaticColorProperties(ITypeElement unityColorType)
        {
            var colorProperties = new LocalList<ITypeMember>();

            foreach (var typeMember in unityColorType.GetMembers())
            {
                if (!typeMember.IsStatic) continue;

                var typeOwner = typeMember as ITypeOwner;
                if (typeOwner is IProperty || typeOwner is IField)
                {
                    var declaredType = typeOwner.Type as IDeclaredType;
                    if (declaredType != null && unityColorType.Equals(declaredType.GetTypeElement()))
                    {
                        colorProperties.Add(typeMember);
                    }
                }
            }

            return colorProperties.ResultingList();
        }
Exemplo n.º 6
0
        private IEnumerable <IReferenceExpression> GetRelatedExpressionsInner([NotNull] ITreeNode scope, [CanBeNull] ITreeNode from = null)
        {
            var descendants = scope.ThisAndDescendants();

            while (descendants.MoveNext())
            {
                var current = descendants.Current;
                if (current == from)
                {
                    isFound = true;
                }

                switch (current)
                {
                case ICSharpClosure _:
                    descendants.SkipThisNode();
                    break;

                case IInvocationExpression invocationExpression:
                    descendants.SkipThisNode();
                    var argumentList = invocationExpression.ArgumentList;
                    if (argumentList != null)
                    {
                        foreach (var re in GetRelatedExpressionsInner(argumentList, from))
                        {
                            if (isFound)
                            {
                                yield return(re);
                            }
                        }
                    }

                    var invokedExpression = invocationExpression.InvokedExpression;
                    foreach (var re in GetRelatedExpressionsInner(invokedExpression, from))
                    {
                        if (isFound)
                        {
                            yield return(re);
                        }
                    }

                    continue;

                case IAssignmentExpression assignmentExpression:
                    descendants.SkipThisNode();
                    var source = assignmentExpression.Source;
                    if (source != null)
                    {
                        foreach (var re in GetRelatedExpressionsInner(source, from))
                        {
                            if (isFound)
                            {
                                yield return(re);
                            }
                        }
                    }

                    var dest = assignmentExpression.Dest;
                    if (dest != null)
                    {
                        foreach (var re in GetRelatedExpressionsInner(dest, from))
                        {
                            if (isFound)
                            {
                                yield return(re);
                            }
                        }
                    }

                    continue;

                case IReferenceExpression referenceExpression:
                    var currentNodeDeclaredElement = referenceExpression.Reference.Resolve().DeclaredElement as IClrDeclaredElement;
                    var currentNodeContainingType  = currentNodeDeclaredElement?.GetContainingType();
                    switch (currentNodeDeclaredElement)
                    {
                    case IField _:
                    case IProperty _:
                        var qualifier = referenceExpression.QualifierExpression as IReferenceExpression;
                        if (!ReComparer.Equals(ComponentReferenceExpression, qualifier))
                        {
                            continue;
                        }

                        if (currentNodeContainingType == null)
                        {
                            continue;
                        }

                        if (!ContainingType.Equals(currentNodeContainingType))
                        {
                            continue;
                        }

                        break;

                    case IMethod method:
                        if (currentNodeContainingType == null ||
                            !ContainingType.Equals(currentNodeContainingType))
                        {
                            if (!myIgnoreNotComponentInvocations && isFound)
                            {
                                yield return(referenceExpression);
                            }
                            continue;
                        }
                        break;

                    default:
                        continue;
                    }

                    if (isFound && !IsReferenceExpressionNotRelated(referenceExpression, currentNodeDeclaredElement, currentNodeContainingType))
                    {
                        yield return(referenceExpression);
                    }

                    break;
                }
            }
        }