/// <summary> /// 完善类名 /// </summary> /// <param name="tree"></param> /// <param name="prefab"></param> /// <param name="rule"></param> /// <returns></returns> private static TypeDeclaration CompleteClass(ICSharpCode.NRefactory.CSharp.SyntaxTree tree, string className, GenCodeRule rule) { TypeDeclaration classNode = null; if (tree.Descendants.OfType <TypeDeclaration>().Where(x => x.Name == className).Count() == 0) { classNode = new TypeDeclaration(); classNode.Name = className; classNode.Modifiers |= Modifiers.Public; var comment = new Comment("<summary>", CommentType.Documentation); tree.AddChild(comment, Roles.Comment); comment = new Comment("[代码说明信息]", CommentType.Documentation); tree.AddChild(comment, Roles.Comment); comment = new Comment("<summary>", CommentType.Documentation); tree.AddChild(comment, Roles.Comment); tree.AddChild(classNode, Roles.TypeMemberRole); } classNode = tree.Descendants.OfType <TypeDeclaration>().Where(x => x.Name == className).First(); var baseType = GenCodeUtil.supportBaseTypes[rule.baseTypeIndex]; var basePanels = LoadAllBasePanels(); var bs = classNode.BaseTypes.Where(x => Array.Find(basePanels, y => y.Contains(x.ToString())) != null).FirstOrDefault(); if (bs != null) { classNode.BaseTypes.Remove(bs); } classNode.BaseTypes.Add(new SimpleType(baseType)); return(classNode); }
public ToolTipData(ICSharpCode.NRefactory.CSharp.SyntaxTree unit, ICSharpCode.NRefactory.Semantics.ResolveResult result, ICSharpCode.NRefactory.CSharp.AstNode node, CSharpAstResolver file) { this.Unit = unit; this.Result = result; this.Node = node; this.Resolver = file; }
/// <summary> /// Formats the file /// </summary> static string FormatFile(ICSharpCode.NRefactory.CSharp.SyntaxTree file) { var formatting = FormattingOptionsFactory.CreateMono(); formatting.AutoPropertyFormatting = PropertyFormatting.ForceOneLine; formatting.SimplePropertyFormatting = PropertyFormatting.ForceOneLine; var formatter = new CSharpFormatter(formatting) { FormattingMode = FormattingMode.Intrusive }; return(formatter.Format(file.ToString())); }
/// <summary> /// 完善命名空间 /// </summary> /// <param name="tree"></param> /// <param name="rule"></param> private static void CompleteNameSpace(ICSharpCode.NRefactory.CSharp.SyntaxTree tree, GenCodeRule rule) { string[] usingDeclarations = { "BridgeUI", "UnityEngine", "UnityEngine.UI", "System.Collections", "System.Collections.Generic", }; foreach (var item in usingDeclarations) { if (tree.Descendants.OfType <UsingDeclaration>().Where(x => x.Namespace == item).Count() == 0) { tree.AddChild <AstNode>(new UsingDeclaration(item), Roles.Root); } } }
private AstNode GetClassNode() { CompilerSettings setting = new CompilerSettings(); CSharpParser cpaser = new CSharpParser(setting); ICSharpCode.NRefactory.CSharp.SyntaxTree tree = cpaser.Parse(classStr); if (tree.Errors != null && tree.Errors.Count > 0) { foreach (var erro in tree.Errors) { Debug.LogError(erro.Message); Debug.LogError(erro.Region); } return(null); } else { AstNode classNode = tree.Children.First(); return(classNode); } }
public UICoder(string className) { this.className = className; firstCreate = true; tree = new ICSharpCode.NRefactory.CSharp.SyntaxTree(); }
public override void VisitSyntaxTree(ICSharpCode.NRefactory.CSharp.SyntaxTree syntaxTree) { base.VisitSyntaxTree(syntaxTree); }
void IAstVisitor.VisitSyntaxTree(SyntaxTree unit) { Visit(EnterSyntaxTree, LeaveSyntaxTree, unit); }
/// <summary> /// Formats the syntax tree and saves it /// </summary> public static void FormatAndSave(this ICSharpCode.NRefactory.CSharp.SyntaxTree file, string fileName) { var result = FormatFile(file); SaveFile(fileName, result); }