Пример #1
0
        public static AbstractType[] ResolveType(IEditorData editor, ResolutionContext ctxt = null)
        {
            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor);
            }

            var o = GetScopedCodeObject(editor);

            var optionBackup = ctxt.CurrentContext.ContextDependentOptions;

            ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;

            AbstractType[] ret;

            if (o is IExpression)
            {
                ret = ExpressionTypeEvaluation.EvaluateTypes((IExpression)o, ctxt);
            }
            else if (o is ITypeDeclaration)
            {
                ret = TypeDeclarationResolver.Resolve((ITypeDeclaration)o, ctxt);
            }
            else if (o is INode)
            {
                ret = new[] { TypeDeclarationResolver.HandleNodeMatch(o as INode, ctxt) }
            }
            ;
            else
            {
                ret = null;
            }

            ctxt.CurrentContext.ContextDependentOptions = optionBackup;

            return(ret);
        }
Пример #2
0
        public static AbstractType[] ResolveTypeLoosely(IEditorData editor, out NodeResolutionAttempt resolutionAttempt, ResolutionContext ctxt = null)
        {
            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor);
            }

            var o = GetScopedCodeObject(editor);

            var optionBackup = ctxt.CurrentContext.ContextDependentOptions;

            ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;
            resolutionAttempt = NodeResolutionAttempt.Normal;

            AbstractType[] ret;

            if (o is IExpression)
            {
                ret = ExpressionTypeEvaluation.EvaluateTypes((IExpression)o, ctxt);
            }
            else if (o is ITypeDeclaration)
            {
                ret = TypeDeclarationResolver.Resolve((ITypeDeclaration)o, ctxt);
            }
            else if (o is INode)
            {
                ret = new[] { TypeDeclarationResolver.HandleNodeMatch(o as INode, ctxt, null, o) }
            }
            ;
            else
            {
                ret = null;
            }

            if (ret == null)
            {
                resolutionAttempt = NodeResolutionAttempt.NoParameterOrTemplateDeduction;

                if (o is PostfixExpression_MethodCall)
                {
                    o = (o as PostfixExpression_MethodCall).PostfixForeExpression;
                }

                ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.NoTemplateParameterDeduction;

                if (o is IdentifierExpression)
                {
                    ret = ExpressionTypeEvaluation.GetOverloads(o as IdentifierExpression, ctxt, deduceParameters: false);
                }
                else if (o is ITypeDeclaration)
                {
                    ret = TypeDeclarationResolver.Resolve(o as ITypeDeclaration, ctxt);
                }
                else if (o is IExpression)
                {
                    ret = ExpressionTypeEvaluation.EvaluateTypes(o as IExpression, ctxt);
                }
            }

            if (ret == null)
            {
                resolutionAttempt = NodeResolutionAttempt.RawSymbolLookup;
                ret = TypeDeclarationResolver.HandleNodeMatches(LookupIdRawly(editor, o as ISyntaxRegion), ctxt, null, o);
            }

            if (ret != null)
            {
                foreach (var r in ret)
                {
                    if (r != null)
                    {
                        r.DeclarationOrExpressionBase = o;
                    }
                }
            }

            ctxt.CurrentContext.ContextDependentOptions = optionBackup;
            return(ret);
        }