public override void VisitConstantDeclaration(IConstantDeclaration decl, SST context) { if (decl.DeclaredElement != null) { var name = decl.DeclaredElement.GetName <IFieldName>(); context.Fields.Add(new FieldDeclaration { Name = name }); } }
/// <summary> /// Replace empty strings with string dot empty. /// </summary> /// <param name="node"> /// The node to process. /// </param> public static void ReplaceEmptyStringsWithStringDotEmpty(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType().IsStringLiteral) { IAttribute attribute = tokenNode.GetContainingNode <IAttribute>(true); ISwitchLabelStatement switchLabelStatement = tokenNode.GetContainingNode <ISwitchLabelStatement>(true); IConstantDeclaration constantDeclaration = tokenNode.GetContainingNode <IConstantDeclaration>(true); IRegularParameterDeclaration parameterDeclaration = tokenNode.GetContainingNode <IRegularParameterDeclaration>(true); // Not for attributes, switch labels, constant declarations, or parameter declarations if (attribute == null && switchLabelStatement == null && constantDeclaration == null && parameterDeclaration == null) { string text = currentNode.GetText(); if (text == "\"\"" || text == "@\"\"") { const string NewText = "string.Empty"; ITokenNode newLiteral = (ITokenNode) CSharpTokenType.STRING_LITERAL_REGULAR.Create(new JetBrains.Text.StringBuffer(NewText), new TreeOffset(0), new TreeOffset(NewText.Length)); using (WriteLockCookie.Create(true)) { LowLevelModificationUtil.ReplaceChildRange(currentNode, currentNode, new ITreeNode[] { newLiteral }); } } } } } if (currentNode.FirstChild != null) { ReadabilityRules.ReplaceEmptyStringsWithStringDotEmpty(currentNode.FirstChild); } } }
public ConstantDeclarationCompiler(IConstantDeclaration constantDeclaration, AbstractILCompilerParams @params) : base(@params) { myConstantDeclaration = constantDeclaration; }