Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private void AddTypesToCompletionData(string stringToComplete, List <CompletionData> completions, ElementResolver resolver)
        {
            var partialName = stringToComplete.ToLower();
            // Add matching Classes
            var classMirrorGroups = StaticMirror.GetAllTypes(core).
                                    Where(x => !x.IsHiddenInLibrary && x.Alias.ToLower().Contains(partialName)).
                                    GroupBy(x => x.Alias);

            foreach (var classMirrorGroup in classMirrorGroups)
            {
                // For those class names that have collisions, use shorter names
                bool useShorterName = classMirrorGroup.Count() > 1;
                if (useShorterName)
                {
                    // For colliding namespaces, compute shortest unique names for each
                    var namespaces = classMirrorGroup.Select(x => new Symbol(x.ClassName)).ToList();
                    var shortNames = Symbol.GetShortestUniqueNames(namespaces);
                    Debug.Assert(shortNames.Count() == classMirrorGroup.Count());

                    // Update class mirror (group) Alias with short name computed above
                    for (int i = 0; i < classMirrorGroup.Count(); i++)
                    {
                        var cm = classMirrorGroup.ElementAt(i);
                        cm.Alias = shortNames.ElementAt(i).Value;
                    }
                }
                completions.AddRange(classMirrorGroup.
                                     Where(x => !x.IsEmpty).
                                     Select(x =>
                                            CompletionData.ConvertMirrorToCompletionData(x, useShorterName,
                                                                                         resolver: resolver)));
            }
        }
Ejemplo n.º 3
0
 public void NameMatching()
 {
     Symbol symbol = new Symbol("Com.Autodesk.Designscript.ProtoGeometry.Point");
     Assert.IsTrue(symbol.Matches("Com.Autodesk.Designscript.ProtoGeometry.Point"));
     Assert.IsTrue(symbol.Matches("ProtoGeometry.Point"));
     Assert.IsTrue(symbol.Matches("Designscript.Point"));
     Assert.IsTrue(symbol.Matches("Autodesk.Point"));
     Assert.IsTrue(symbol.Matches("Com.Point"));
     Assert.IsTrue(symbol.Matches("Com.Autodesk.Point"));
     Assert.IsTrue(symbol.Matches("Com.Designscript.Point"));
     Assert.IsTrue(symbol.Matches("Com.ProtoGeometry.Point"));
     Assert.IsTrue(symbol.Matches("Autodesk.ProtoGeometry.Point"));
     Assert.IsTrue(symbol.Matches("Autodesk.Designscript.Point"));
     Assert.IsTrue(symbol.Matches("Designscript.ProtoGeometry.Point"));
     Assert.IsTrue(symbol.Matches("Point"));
     Assert.IsFalse(symbol.Matches("Autodesk.Com.Designscript.Point"));
     Assert.IsFalse(symbol.Matches("Com.ProtoGeometry.Autodesk.Point"));
     Assert.IsFalse(symbol.Matches("Com.Designscript.Autodesk.Point"));
     Assert.IsFalse(symbol.Matches("Autodesk"));
 }
Ejemplo n.º 4
0
        private AssociativeNode RewriteIdentifierListNode(AssociativeNode identifierList)
        {
            var resolvedName = ResolveClassName(identifierList);

            if (string.IsNullOrEmpty(resolvedName))
                return identifierList;

            var identListNode = identifierList as IdentifierListNode;

            var newIdentList = CoreUtils.CreateNodeFromString(resolvedName);

            // If the original input node matches with the resolved name, simply return 
            // the identifier list constructed from the resolved name
            var symbol = new Symbol(resolvedName);
            if (symbol.Matches(identifierList.ToString()))
                return newIdentList;

            // Remove partialName from identListNode and replace with newIdentList
            AssociativeNode leftNode = identListNode != null ? identListNode.LeftNode : identifierList;
            AssociativeNode rightNode = identListNode != null ? identListNode.RightNode : identifierList;

            var intermediateNodes = new List<AssociativeNode>();
            while (leftNode is IdentifierListNode && !symbol.Matches(leftNode.ToString()))
            {
                intermediateNodes.Insert(0, ((IdentifierListNode)leftNode).RightNode);
                leftNode = ((IdentifierListNode)leftNode).LeftNode;
            }
            intermediateNodes.Insert(0, newIdentList);

            var lNode = CoreUtils.CreateNodeByCombiningIdentifiers(intermediateNodes);

            // The last ident list for the functioncall or identifier rhs
            var lastIdentList = new IdentifierListNode
            {
                LeftNode = lNode,
                RightNode = rightNode,
                Optr = Operator.dot
            };

            return lastIdentList;
        }
Ejemplo n.º 5
0
 public void SymbolName()
 {
     Symbol symbol = new Symbol("Com.Autodesk.Designscript.ProtoGeometry.Point");
     Assert.AreEqual("Point", symbol.Name);
     Assert.AreEqual("Com.Autodesk.Designscript.ProtoGeometry.Point", symbol.FullName);
 }
Ejemplo n.º 6
0
        private bool IsMatchingResolvedName(IdentifierListNode identifierList, out AssociativeNode newIdentList)
        {
            newIdentList = null;
            var resolvedName = ResolveClassName(identifierList);
            if (string.IsNullOrEmpty(resolvedName))
                return false;

            newIdentList = CoreUtils.CreateNodeFromString(resolvedName);
            
            var symbol = new Symbol(resolvedName);
            return symbol.Matches(identifierList.ToString());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Finds a unique matching symbol for the given partial name.
        /// </summary>
        /// <param name="partialName">Partial symbol name for lookup</param>
        /// <param name="symbol">Matching symbol or null</param>
        /// <returns>True if only one unique symbol could be found with given
        /// partial name.</returns>
        public bool TryGetUniqueSymbol(string partialName, out Symbol symbol)
        {
            if (TryGetExactSymbol(partialName, out symbol))
            {
                return true;
            }

            Symbol[] symbols = TryGetSymbols(partialName, (Symbol s) => s.Matches(partialName));
            if (symbols.Length == 1)
                symbol = symbols[0];
            else
                symbol = null;

            return symbol != null;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Finds a symbol in this table which has exactly same name as given 
        /// fully qualified name.
        /// </summary>
        /// <param name="fullName">Fully qualified name for lookup</param>
        /// <param name="symbol">Matching symbol for given fullName.</param>
        /// <returns>True if exact matching symbol is found.</returns>
        public bool TryGetExactSymbol(string fullName, out Symbol symbol)
        {
            Symbol[] symbols = TryGetSymbols(fullName, (Symbol s) => s.FullName.Equals(fullName));
            if (symbols.Length == 1)
                symbol = symbols[0];
            else
                symbol = null;

            return symbol != null;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds the given symbol to this symbol table
        /// </summary>
        /// <param name="qualifiedSymbol">FullyQualifiedSymbolName</param>
        /// <returns>True if symbol is added successfully, false if the symbol was 
        /// already present in the table.</returns>
        public bool AddSymbol(Symbol qualifiedSymbol)
        {
            string symbolName = qualifiedSymbol.Name;

            HashSet<Symbol> container = null;
            if (!symbolTable.TryGetValue(symbolName, out container))
            {
                container = new HashSet<Symbol>();
                symbolTable.Add(symbolName, container);
            }
            return container.Add(qualifiedSymbol);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Adds the given symbol to this symbol table
 /// </summary>
 /// <param name="fullname">Fully qualified name for the symbol</param>
 /// <returns>The newly added symbol if added successfully, else null.</returns>
 public Symbol AddSymbol(string fullname)
 {
     Symbol symbol = new Symbol(fullname);
     if (AddSymbol(symbol))
         return symbol;
     return null;
 }