/// <nodoc /> public static int FitsOnOneLine(INodeArray <INode> nodes, int separatorSize, int remainingSpace) { if (nodes.IsNullOrEmpty()) { return(remainingSpace); } if (nodes.Count > 5) { // Always print more than 5 nodes on separate lines. return(-1); } int space = remainingSpace; foreach (var node in nodes.AsStructEnumerable()) { if (space != remainingSpace) { // Subtract space for separators on subsequent nodes space -= separatorSize; } space = FitsOnOneLine(node, space); if (space < 0) { // if it already doesn't fit, the rest won't fit either return(space); } } return(space); }
private List <Expression> EnumerateTaggedExpressionsForPathAtomInterpolation( ITemplateLiteralFragment headNode, INodeArray <ITemplateSpan> templateSpans, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId) { // Creating a list that will hold all potential expressions List <Expression> result = new List <Expression>((templateSpans.Length * 2) + 1); string head = headNode.Text; if (!string.IsNullOrEmpty(head)) { var convertedPathAtomLiteral = m_literalConverter.ConvertPathAtomLiteral(head, Location(headNode)); if (convertedPathAtomLiteral == null) { // Error has been reported. return(null); } result.Add(convertedPathAtomLiteral); } foreach (var span in templateSpans.AsStructEnumerable()) { if (span.Expression != null) { var convertedExpression = m_converter.ConvertExpression(span.Expression, escapes, currentQualifierSpaceId); if (convertedExpression != null) { result.Add(convertedExpression); } } var fragment = span.Literal.Text; if (!string.IsNullOrEmpty(fragment)) { var convertedPathAtomLiteral = m_literalConverter.ConvertPathAtomLiteral(fragment, Location(span.Literal)); if (convertedPathAtomLiteral == null) { // Error has been reported. return(null); } result.Add(convertedPathAtomLiteral); } } return(result); }
private static T VisitEachNode <T>(Func <NodeOrNodesOrNull, T> cbNode, INodeArray <INode> nodes) where T : class { if (nodes != null) { foreach (var node in nodes.AsStructEnumerable()) { var result = cbNode(new NodeOrNodesOrNull(node)); if (result != null) { return(result); } } } return(default(T)); }