Esempio n. 1
0
        /// <summary>
        /// Inspects the input identifier list to match all class names with the class used in it
        /// </summary>
        /// <param name="classTable"></param>
        /// <param name="identifierList">single identifier or identifier list</param>
        /// <returns>list of fully resolved class names</returns>
        public static string[] GetResolvedClassName(ClassTable classTable, AssociativeNode identifierList)
        {
            var identListNode  = identifierList as IdentifierListNode;
            var identifierNode = identifierList as IdentifierNode;

            Validity.Assert(identListNode != null || identifierNode != null);

            string partialName = identListNode != null?
                                 GetIdentifierStringUntilFirstParenthesis(identListNode) : identifierList.Name;

            string[] classNames = classTable.GetAllMatchingClasses(partialName);

            // Failed to find the first time
            // Attempt to remove identifiers in the identifierlist until we find a class or not
            while (0 == classNames.Length)
            {
                // Move to the left node
                AssociativeNode leftNode = identListNode != null ? identListNode.LeftNode : identifierNode;
                if (leftNode is IdentifierListNode)
                {
                    identListNode = leftNode as IdentifierListNode;
                    classNames    = classTable.GetAllMatchingClasses(GetIdentifierStringUntilFirstParenthesis(identListNode));
                }
                if (leftNode is IdentifierNode)
                {
                    classNames = classTable.GetAllMatchingClasses(leftNode.Name);
                    break;
                }
                else
                {
                    break;
                }
            }
            return(classNames);
        }
Esempio n. 2
0
        private bool TryShortenClassName(IdentifierListNode node, out AssociativeNode shortNameNode)
        {
            shortNameNode = null;

            string qualifiedName = CoreUtils.GetIdentifierExceptMethodName(node);

            // if it is a global method with no class
            if (string.IsNullOrEmpty(qualifiedName))
            {
                return(false);
            }

            // Make sure qualifiedName is not a property
            var matchingClasses = classTable.GetAllMatchingClasses(qualifiedName);

            if (matchingClasses.Length == 0)
            {
                return(false);
            }

            string className = qualifiedName.Split('.').Last();

            var symbol = new ProtoCore.Namespace.Symbol(qualifiedName);

            if (!symbol.Matches(node.ToString()))
            {
                return(false);
            }

            shortNameNode = CreateNodeFromShortName(className, qualifiedName);
            return(shortNameNode != null);
        }