예제 #1
0
        public void LookupResolvedName_ForGlobalClass_RewriteAst()
        {
            const string code   = @"import (""FFITarget.dll"");";
            var          mirror = thisTest.RunScriptSource(code);

            var testCore = thisTest.GetTestCore();
            var astNodes = CoreUtils.BuildASTList(testCore, "a = GlobalClass.GlobalClass(a);");

            var elementResolver = new ElementResolver();

            var newNodes = ElementRewriter.RewriteElementNames(testCore.ClassTable, elementResolver, astNodes).ToList();

            Assert.AreEqual("a = GlobalClass.GlobalClass(a);\n", newNodes[0].ToString());

            astNodes = CoreUtils.BuildASTList(testCore, "a : GlobalClass;");

            newNodes = ElementRewriter.RewriteElementNames(testCore.ClassTable, elementResolver, astNodes).ToList();

            Assert.AreEqual("a : GlobalClass", newNodes[0].ToString());

            // Add verification for contents of element resolver resolution map
            Assert.AreEqual(1, elementResolver.ResolutionMap.Count);

            var assembly     = elementResolver.LookupAssemblyName("GlobalClass");
            var resolvedName = elementResolver.LookupResolvedName("GlobalClass");

            Assert.AreEqual("FFITarget.dll", assembly);
            Assert.AreEqual("GlobalClass", resolvedName);
        }
예제 #2
0
        /// <summary>
        /// Determines if the completion string is a valid type and
        /// enumerates the list of completion members on the type
        /// </summary>
        /// <param name="code"> code typed in the code block </param>
        /// <param name="stringToComplete"> Class name or declared variable </param>
        /// <param name="resolver"></param>
        /// <returns> list of method and property members of the type </returns>
        internal IEnumerable <CompletionData> GetCompletionsOnType(string code, string stringToComplete, ElementResolver resolver = null)
        {
            IEnumerable <StaticMirror> members = null;

            if (resolver != null)
            {
                stringToComplete = resolver.LookupResolvedName(stringToComplete) ?? stringToComplete;
            }

            // Determine if the string to be completed is a class
            var type = GetClassType(stringToComplete);

            if (type != null)
            {
                members = type.GetMembers();
            }
            // If not of class type
            else
            {
                // Check if the string to be completed is a declared variable
                string typeName = CodeCompletionParser.GetVariableType(code, stringToComplete);
                if (typeName != null)
                {
                    type = GetClassType(typeName);
                }

                if (type != null)
                {
                    members = type.GetInstanceMembers();
                }
            }

            return(members.Select(x => CompletionData.ConvertMirrorToCompletionData(x)));
        }
예제 #3
0
        public void LookupResolvedName_FromCompiler_RewriteAst()
        {
            string code   = @"import (""FFITarget.dll"");";
            var    mirror = thisTest.RunScriptSource(code);

            var testCore = thisTest.GetTestCore();
            var astNodes = CoreUtils.BuildASTList(testCore, "d = ElementResolverTarget.ElementResolverTarget();");
            var astNode  = astNodes[0];

            var elementResolver = new ElementResolver();

            var elementRewriter = new ElementRewriter(testCore.ClassTable);

            elementRewriter.LookupResolvedNameAndRewriteAst(elementResolver, ref astNode);

            Assert.AreEqual("d = FFITarget.ElementResolverTarget.ElementResolverTarget();\n", astNode.ToString());

            // Add verification for contents of element resolver resolution map
            Assert.AreEqual(1, elementResolver.ResolutionMap.Count);

            var assembly     = elementResolver.LookupAssemblyName("ElementResolverTarget");
            var resolvedName = elementResolver.LookupResolvedName("ElementResolverTarget");

            Assert.AreEqual("FFITarget.dll", assembly);
            Assert.AreEqual("FFITarget.ElementResolverTarget", resolvedName);
        }
예제 #4
0
        /// <summary>
        /// Returns the list of function signatures of all overloads of a given method
        /// </summary>
        /// <param name="code"> code being typed in code block </param>
        /// <param name="functionName"> given method name for which signature is queried </param>
        /// <param name="functionPrefix"> class name in case of constructor or static method, OR
        /// declared instance variable on which method is invoked </param>
        /// <param name="resolver"></param>
        /// <returns> list of method overload signatures </returns>
        internal IEnumerable <CompletionData> GetFunctionSignatures(string code, string functionName, string functionPrefix,
                                                                    ElementResolver resolver = null)
        {
            IEnumerable <MethodMirror> candidates = null;

            // if function is global, search for function in Built-ins
            if (string.IsNullOrEmpty(functionPrefix))
            {
                return(StaticMirror.GetOverloadsOnBuiltIns(core, functionName).
                       Select(x =>
                {
                    return new CompletionData(x.MethodName, CompletionData.CompletionType.Method)
                    {
                        Stub = x.ToString()
                    };
                }));
            }

            // Determine if the function prefix is a class name
            if (resolver != null)
            {
                functionPrefix = resolver.LookupResolvedName(functionPrefix) ?? functionPrefix;
            }

            var type = GetClassType(functionPrefix);

            if (type != null)
            {
                candidates = type.GetOverloadsOnType(functionName);
            }
            // If not of class type
            else
            {
                // Check if the function prefix is a typed identifier
                string typeName = CodeCompletionParser.GetVariableType(code, functionPrefix);
                if (typeName != null)
                {
                    type = GetClassType(typeName);
                }

                if (type != null)
                {
                    candidates = type.GetOverloadsOnInstance(functionName);
                }
            }
            return(candidates.Select(x => CompletionData.ConvertMirrorToCompletionData(x)));
        }
예제 #5
0
        public void LookupResolvedName_ForNestedNamespacesExpressionFromCompiler_RewriteAst()
        {
            const string code   = @"import (""FFITarget.dll"");";
            var          mirror = thisTest.RunScriptSource(code);

            var    testCore  = thisTest.GetTestCore();
            string class1    = "NestedResolverTarget";
            string class2    = "ElementResolverTarget";
            string fullName1 = "FFITarget.NameSpaceA.NameSpaceB.NameSpaceC.NestedResolverTarget";
            string fullName2 = "FFITarget.ElementResolverTarget";
            var    astNodes  = CoreUtils.BuildASTList(testCore, string.Format("d = {0}.Property.Method({1}.Create().Property.Method({0}.Property.Property));", class1, class2));

            var elementResolver = new ElementResolver();

            var newNodes = ElementRewriter.RewriteElementNames(testCore.ClassTable, elementResolver, astNodes);

            Assert.AreEqual(
                string.Format("d = {0}.Property.Method({1}.Create().Property.Method({0}.Property.Property));\n", fullName1, fullName2),
                newNodes.ElementAt(0).ToString());

            // Add verification for contents of element resolver resolution map
            var assembly     = elementResolver.LookupAssemblyName(class2);
            var resolvedName = elementResolver.LookupResolvedName(class2);

            Assert.AreEqual("FFITarget.dll", assembly);
            Assert.AreEqual(fullName2, resolvedName);

            ///////////////////////////////////////////////
            astNodes = CoreUtils.BuildASTList(testCore, string.Format("d = {0}.Property.Method({1}.Create().Property.Method({0}.Property.Property));", fullName1, fullName2));

            elementResolver = new ElementResolver();

            newNodes = ElementRewriter.RewriteElementNames(testCore.ClassTable, elementResolver, astNodes);

            Assert.AreEqual(
                string.Format("d = {0}.Property.Method({1}.Create().Property.Method({0}.Property.Property));\n", fullName1, fullName2),
                newNodes.ElementAt(0).ToString());

            // Add verification for contents of element resolver resolution map
            assembly     = elementResolver.LookupAssemblyName(fullName2);
            resolvedName = elementResolver.LookupResolvedName(fullName2);

            Assert.AreEqual("FFITarget.dll", assembly);
            Assert.AreEqual(fullName2, resolvedName);
        }
예제 #6
0
        public void LookupResolvedName_ForTypedIdentifierFromCompiler_RewriteAst()
        {
            const string code   = @"import (""FFITarget.dll"");";
            var          mirror = thisTest.RunScriptSource(code);

            var testCore = thisTest.GetTestCore();
            var astNodes = CoreUtils.BuildASTList(testCore, "d : ElementResolverTarget;");

            var elementResolver = new ElementResolver();

            var newNodes = ElementRewriter.RewriteElementNames(testCore.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("d : FFITarget.ElementResolverTarget", newNodes.ElementAt(0).ToString());

            // Add verification for contents of element resolver resolution map
            var assembly     = elementResolver.LookupAssemblyName("ElementResolverTarget");
            var resolvedName = elementResolver.LookupResolvedName("ElementResolverTarget");

            Assert.AreEqual("FFITarget.dll", assembly);
            Assert.AreEqual("FFITarget.ElementResolverTarget", resolvedName);
        }
예제 #7
0
        private void VerifyResult(string fullName, string partialName, string functionOrProperty, bool isProperty = false)
        {
            var testCore = thisTest.GetTestCore();

            var astNodes = CoreUtils.BuildASTList(testCore, string.Format("d = {0}.{1};", partialName, functionOrProperty));

            var elementResolver = new ElementResolver();

            var newNodes = ElementRewriter.RewriteElementNames(testCore.ClassTable, elementResolver, astNodes);

            Assert.AreEqual(string.Format("d = {0}.{1};\n", fullName, functionOrProperty), newNodes.ElementAt(0).ToString());

            if (!isProperty)
            {
                // Add verification for contents of element resolver resolution map
                var assembly     = elementResolver.LookupAssemblyName(partialName);
                var resolvedName = elementResolver.LookupResolvedName(partialName);

                Assert.AreEqual("FFITarget.dll", assembly);
                Assert.AreEqual(fullName, resolvedName);
            }
        }
예제 #8
0
        public void LookupResolvedName_ForNestedExpressionFromCompiler_RewriteAst()
        {
            const string code   = @"import (""FFITarget.dll"");";
            var          mirror = thisTest.RunScriptSource(code);

            var testCore = thisTest.GetTestCore();
            var astNodes = CoreUtils.BuildASTList(testCore, "d = ElementResolverTarget.Create().Property.Method(ElementResolverTarget.Create().Property);");

            var elementResolver = new ElementResolver();

            var newNodes = ElementRewriter.RewriteElementNames(testCore.ClassTable, elementResolver, astNodes);

            Assert.AreEqual("d = FFITarget.ElementResolverTarget.Create().Property.Method(FFITarget.ElementResolverTarget.Create().Property);\n", newNodes.ElementAt(0).ToString());

            // Add verification for contents of element resolver resolution map
            Assert.AreEqual(1, elementResolver.ResolutionMap.Count);

            var assembly     = elementResolver.LookupAssemblyName("ElementResolverTarget");
            var resolvedName = elementResolver.LookupResolvedName("ElementResolverTarget");

            Assert.AreEqual("FFITarget.dll", assembly);
            Assert.AreEqual("FFITarget.ElementResolverTarget", resolvedName);
        }