public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node) { // If node is a reserved method call, skip rewriting it. if (ReservedMethods.Any(reservedMethod => node.ToString().Contains(reservedMethod))) { return(node); } // First pass attempt to resolve the node before traversing it deeper AssociativeNode newIdentifierListNode = null; if (IsMatchingResolvedName(node, out newIdentifierListNode)) { return(newIdentifierListNode); } var rightNode = node.RightNode; var leftNode = node.LeftNode; rightNode = rightNode.Accept(this); leftNode = leftNode.Accept(this); node = new IdentifierListNode { LeftNode = leftNode, RightNode = rightNode, Optr = Operator.dot }; return(RewriteIdentifierListNode(node)); }
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); }
/// <summary> /// Retrieves the string format of the identifier list from left to right, leaving out any symbols after the last identifier. /// Given: A.B() /// Return: "A.B" /// Given: A.B.C()[0] /// Return: "A.B.C" /// Given: A.B().C /// Return: "A.B" /// Given: A.B[0].C /// Return: "A.B[0].C" /// </summary> /// <param name="identList"></param> /// <returns></returns> public static string GetIdentifierStringUntilFirstParenthesis(IdentifierListNode identList) { Validity.Assert(null != identList); string identListString = identList.ToString(); int removeIndex = identListString.IndexOf('('); if (removeIndex > 0) { identListString = identListString.Remove(removeIndex); } return(identListString); }
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())); }