private bool CanBeConvertToStringEmpty(IStringLiteral literal) { IFieldDeclaration field = literal.Enclosing <IFieldDeclaration>(); if (field.Exists && field.Modifiers.Modifiers.IsConst()) { return(false); } IVariableDeclaration variable = literal.Enclosing <IVariableDeclaration>(); if (variable.Exists && variable.IsConst) { return(false); } IAttribute attributes = literal.Enclosing <IAttribute>(); if (attributes.Exists) { return(false); } return(true); }
private void ReplaceWithStringEmpty(IStringLiteral literal) { IMemberAccess isEmpty = literal.Language.MemberAccess(literal.Language.TypeName(literal.Type), literal.Language.None <IExpression>(), literal.Language.Identifier("Empty")); literal.ReplaceWith(isEmpty); }
private void ReplaceWithStringEmpty(IStringLiteral literal) { IMemberAccess isEmpty = literal.Language.MemberAccess(literal.Language.TypeName(literal.Type), literal.Language.None<IExpression>(), literal.Language.Identifier("Empty")); literal.ReplaceWith(isEmpty); }
private static int FitsOnOneLine(IStringLiteral expression, int remainingSpace) { if (expression.LiteralKind != LiteralExpressionKind.None) { remainingSpace -= 2; } return(remainingSpace - expression.Text.Length); }
private bool CanBeConvertToStringEmpty(IStringLiteral literal) { IFieldDeclaration field = literal.Enclosing<IFieldDeclaration>(); if (field.Exists && field.Modifiers.Modifiers.IsConst()) { return false; } IVariableDeclaration variable = literal.Enclosing<IVariableDeclaration>(); if (variable.Exists && variable.IsConst) { return false; } IAttribute attributes = literal.Enclosing<IAttribute>(); if (attributes.Exists) { return false; } return true; }
private IStringLiteral EatStringLiteral(IStringLiteral stringLiteral) { switch (tokens[0].type) { case Global.DataType.ENDSTATEMENT: return stringLiteral; case Global.DataType.STRING: stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, tokens[0].value)); CutData(1); return EatStringLiteral(stringLiteral); case Global.DataType.STRINGINTERPOLATION: CutData(1); stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, EatExpression())); return EatStringLiteral(stringLiteral); case Global.DataType.STRINGINTERPOLATIONEND: CutData(1); return stringLiteral; case Global.DataType.ESCAPEDCHARACTER: switch (tokens[0].value) { case "\\0": stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, Global.EscapedCharacter.Null)); break; case "\\\\": stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, Global.EscapedCharacter.Backslash)); break; case "\\t": stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, Global.EscapedCharacter.HorizontalTab)); break; case "\\n": stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, Global.EscapedCharacter.LineFeed)); break; case "\\r": stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, Global.EscapedCharacter.CarriageReturn)); break; case "\\\"": stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, Global.EscapedCharacter.DoubleQuote)); break; case "\\'": stringLiteral.Elements.Add(new StringElement(stringLiteral.Context, Global.EscapedCharacter.SingleQuote)); break; default: Swift.error(new InternalError("Trying to parse the unrecognized character " + tokens[0].value)); break; } CutData(1); return EatStringLiteral(stringLiteral); } Swift.error(new InternalError("Trying to parse a string literal containing illegal tokens")); return null; }