private AssociativeNode CreateNodeFromShortName(string className, string qualifiedName) { // Get the list of conflicting namespaces that contain the same class name var matchingClasses = classTable.ClassNodes.Where( x => x.Name.Split('.').Last().Equals(className)).ToList(); if (matchingClasses.Count == 0) { return(null); } if (matchingClasses.Count == 1) { // If there is no class conflict simply use the class name as the shortest name. return(CoreUtils.CreateNodeFromString(className)); } var shortName = resolver?.LookupShortName(qualifiedName); if (!string.IsNullOrEmpty(shortName)) { return(CoreUtils.CreateNodeFromString(shortName)); } // Use the namespace list to derive the list of shortest unique names var symbolList = matchingClasses.Select(matchingClass => new Symbol(matchingClass.Name)); var shortNames = Symbol.GetShortestUniqueNames(symbolList); // remove hidden class if any from shortNames before proceeding var hiddenClassNodes = matchingClasses. Where(x => x.ClassAttributes?.HiddenInLibrary ?? false).ToList(); if (hiddenClassNodes.Any()) { foreach (var hiddenClassNode in hiddenClassNodes) { var keyToRemove = new Symbol(hiddenClassNode.Name); shortNames.Remove(keyToRemove); } } // Get the shortest name corresponding to the fully qualified name if (shortNames.TryGetValue(new Symbol(qualifiedName), out shortName)) { return(CoreUtils.CreateNodeFromString(shortName)); } // If shortName for fully qualified classname is not found, it could be a base class // present in class hierarchy of any of the other matchingClasses, in which case // set shortName to the one for the derived class. var qualifiedClassNode = matchingClasses.FirstOrDefault(x => x.Name == qualifiedName); var classHierarchies = matchingClasses.Where(x => x != qualifiedClassNode). Select(y => classTable.GetClassHierarchy(y)); foreach (var hierarchy in classHierarchies) { // If A derives from B, which derives from C, the hierarchy for A // is listed in that order: [A, B, C], so we start searching in reverse order. for (int i = hierarchy.Count - 1; i > 0; i--) { if (hierarchy[i] == qualifiedClassNode) { shortName = shortNames[new Symbol(hierarchy[0].Name)]; return(CoreUtils.CreateNodeFromString(shortName)); } } } return(null); }