public override bool OnCompletionInsert(ScintillaNet.ScintillaControl sci, int position, string text, char trigger) { if (text == "Vector") { string insert = null; string line = sci.GetLine(sci.LineFromPosition(position)); Match m = Regex.Match(line, @"\svar\s+(?<varname>.+)\s*:\s*Vector\.<(?<indextype>.+)(?=(>\s*=))"); if (m.Success) { insert = String.Format(".<{0}>", m.Groups["indextype"].Value); } else { m = Regex.Match(line, @"\s*=\s*new"); if (m.Success) { ASResult result = ASComplete.GetExpressionType(sci, sci.PositionFromLine(sci.LineFromPosition(position)) + m.Index); if (result != null && !result.IsNull() && result.Member != null && result.Member.Type != null) { m = Regex.Match(result.Member.Type, @"(?<=<).+(?=>)"); if (m.Success) { insert = String.Format(".<{0}>", m.Value); } } } if (insert == null) { if (trigger == '.' || trigger == '(') { return(true); } insert = ".<>"; sci.InsertText(position + text.Length, insert); sci.CurrentPos = position + text.Length + 2; sci.SetSel(sci.CurrentPos, sci.CurrentPos); ASComplete.HandleAllClassesCompletion(sci, "", false, true); return(true); } } if (insert == null) { return(false); } if (trigger == '.') { sci.InsertText(position + text.Length, insert.Substring(1)); sci.CurrentPos = position + text.Length; } else { sci.InsertText(position + text.Length, insert); sci.CurrentPos = position + text.Length + insert.Length; } sci.SetSel(sci.CurrentPos, sci.CurrentPos); return(true); } return(false); }
void ProcessMouseMove(Point point) { int position = sci.PositionFromPointClose(point.X, point.Y); if (position < 0) { SetCurrentWord(null); } else if (ASContext.Context.IsFileValid) { Word word = new Word { StartPos = sci.WordStartPosition(position, true), EndPos = sci.WordEndPosition(position, true) }; ASResult expr = ASComplete.GetExpressionType(sci, word.EndPos); if (expr.IsNull()) { string overrideKey = ASContext.Context.Features.overrideKey; if (expr.Context == null || !expr.Context.BeforeBody || string.IsNullOrEmpty(overrideKey) || sci.GetWordFromPosition(position) != overrideKey) { word = null; } } SetCurrentWord(word); } }
private void OnMouseHover(ScintillaNet.ScintillaControl sci, int position) { if (!ASContext.Context.IsFileValid) { return; } lastHoverPosition = position; // get word at mouse position int style = sci.BaseStyleAt(position); if (!ASComplete.IsTextStyle(style)) { return; } position = sci.WordEndPosition(position, true); ASResult result = ASComplete.GetExpressionType(sci, position); // set tooltip if (!result.IsNull()) { string text = ASComplete.GetToolTipText(result); if (text == null) { return; } // show tooltip UITools.Tip.ShowAtMouseLocation(text); } }
private void ProcessMouseMove(Point point) { int position = sciControl.PositionFromPointClose(point.X, point.Y); if (position < 0) { SetCurrentWord(null); return; } if (ASContext.Context.IsFileValid) { Word word = new Word(); word.StartPos = sciControl.WordStartPosition(position, true); word.EndPos = sciControl.WordEndPosition(position, true); ASResult result = ASComplete.GetExpressionType(sciControl, word.EndPos); if (!result.IsNull()) { SetCurrentWord(word); } else { SetCurrentWord(null); } } }
private void OnMouseHover(ScintillaNet.ScintillaControl sci, int position) { if (ASContext.Locked || !ASContext.Context.IsFileValid()) { return; } // get word at mouse position int style = sci.BaseStyleAt(position); DebugConsole.Trace("Style=" + style); if (!ASComplete.IsTextStyle(style)) { return; } position = sci.WordEndPosition(position, true); ASResult result = ASComplete.GetExpressionType(sci, position); // set tooltip if (!result.IsNull()) { string text = ASComplete.GetToolTipText(result); DebugConsole.Trace("SHOW " + text); if (text == null) { return; } // show tooltip InfoTip.ShowAtMouseLocation(text); } }
/// <summary> /// Gets the result for menu updating from current position. /// </summary> private ASResult GetResultFromCurrentPosition() { ITabbedDocument document = PluginBase.MainForm.CurrentDocument; if (document == null || document.SciControl == null || !ASContext.Context.IsFileValid) { return(null); } Int32 position = document.SciControl.WordEndPosition(document.SciControl.CurrentPos, true); ASResult result = ASComplete.GetExpressionType(document.SciControl, position); return(result == null && result.IsNull() ? null : result); }
public override void ResolveTopLevelElement(string token, ASResult result) { if (topLevel != null && topLevel.Members.Count > 0) { // current class ClassModel inClass = ASContext.Context.CurrentClass; if (token == "this") { result.Member = topLevel.Members.Search("this", 0, 0); if (inClass.IsVoid()) { inClass = ASContext.Context.ResolveType(result.Member.Type, null); } result.Type = inClass; result.InFile = ASContext.Context.CurrentModel; return; } else if (token == "super") { if (inClass.IsVoid()) { MemberModel thisMember = topLevel.Members.Search("this", 0, 0); inClass = ASContext.Context.ResolveType(thisMember.Type, null); } inClass.ResolveExtends(); ClassModel extends = inClass.Extends; if (!extends.IsVoid()) { result.Member = topLevel.Members.Search("super", 0, 0); result.Type = extends; result.InFile = extends.InFile; return; } } else if (token == "global") { return; } // other top-level elements ASComplete.FindMember(token, topLevel, result, 0, 0); if (!result.IsNull()) { return; } } }
private void OnMouseHover(ScintillaControl sci, int position) { if (!ASContext.Context.IsFileValid) { return; } lastHoverPosition = position; // get word at mouse position int style = sci.BaseStyleAt(position); if (!ASComplete.IsTextStyle(style)) { return; } position = sci.WordEndPosition(position, true); ASResult result = ASComplete.GetExpressionType(sci, position); // set tooltip if (!result.IsNull()) { if (Control.ModifierKeys == Keys.Control) { var code = ASComplete.GetCodeTipCode(result); if (code == null) { return; } UITools.CodeTip.Show(sci, position - result.Path.Length, code); } else { string text = ASComplete.GetToolTipText(result); if (text == null) { return; } // show tooltip UITools.Tip.ShowAtMouseLocation(text); } } }
/// <summary> /// Checks if a given search match actually points to the given target source /// </summary> /// <returns>True if the SearchMatch does point to the target source.</returns> public static ASResult DeclarationLookupResult(ScintillaControl Sci, int position) { if (!ASContext.Context.IsFileValid || (Sci == null)) { return(null); } // get type at cursor position ASResult result = ASComplete.GetExpressionType(Sci, position); if (result.IsPackage) { return(result); } // open source and show declaration if (!result.IsNull()) { if (result.Member != null && (result.Member.Flags & FlagType.AutomaticVar) > 0) { return(null); } FileModel model = result.InFile ?? ((result.Member != null && result.Member.InFile != null) ? result.Member.InFile : null) ?? ((result.Type != null) ? result.Type.InFile : null); if (model == null || model.FileName == "") { return(null); } ClassModel inClass = result.InClass ?? result.Type; // for Back command int lookupLine = Sci.CurrentLine; int lookupCol = Sci.CurrentPos - Sci.PositionFromLine(lookupLine); ASContext.Panel.SetLastLookupPosition(ASContext.Context.CurrentFile, lookupLine, lookupCol); // open the file if (model != ASContext.Context.CurrentModel) { if (model.FileName.Length > 0 && File.Exists(model.FileName)) { ASContext.MainForm.OpenEditableDocument(model.FileName, false); } else { ASComplete.OpenVirtualFile(model); result.InFile = ASContext.Context.CurrentModel; if (result.InFile == null) { return(null); } if (inClass != null) { inClass = result.InFile.GetClassByName(inClass.Name); if (result.Member != null) { result.Member = inClass.Members.Search(result.Member.Name, 0, 0); } } else if (result.Member != null) { result.Member = result.InFile.Members.Search(result.Member.Name, 0, 0); } } } if ((inClass == null || inClass.IsVoid()) && result.Member == null) { return(null); } Sci = ASContext.CurSciControl; if (Sci == null) { return(null); } int line = 0; string name = null; bool isClass = false; // member if (result.Member != null && result.Member.LineFrom > 0) { line = result.Member.LineFrom; name = result.Member.Name; } // class declaration else if (inClass.LineFrom > 0) { line = inClass.LineFrom; name = inClass.Name; isClass = true; // constructor foreach (MemberModel member in inClass.Members) { if ((member.Flags & FlagType.Constructor) > 0) { line = member.LineFrom; name = member.Name; isClass = false; break; } } } if (line > 0) // select { if (isClass) { ASComplete.LocateMember("(class|interface)", name, line); } else { ASComplete.LocateMember("(function|var|const|get|set|property|[,(])", name, line); } } return(result); } return(null); }
/// <summary> /// Updates the state of the menu items /// </summary> private void UpdateMenuItems() { try { ResolvedContext resolved = ASComplete.CurrentResolvedContext; Boolean isValid = this.GetLanguageIsValid() && resolved != null && resolved.Position >= 0; this.refactorMainMenu.DelegateMenuItem.Enabled = false; this.refactorContextMenu.DelegateMenuItem.Enabled = false; ASResult result = isValid ? resolved.Result : null; if (result != null && !result.IsNull()) { Boolean isVoid = result.Type.IsVoid(); Boolean isClass = !isVoid && result.IsStatic && result.Member == null; Boolean isVariable = !isVoid && !isClass && RefactoringHelper.CheckFlag(result.Member.Flags, FlagType.Variable); Boolean isConstructor = !isVoid && !isClass && RefactoringHelper.CheckFlag(result.Member.Flags, FlagType.Constructor); this.refactorContextMenu.RenameMenuItem.Enabled = !(isClass || isConstructor || isVoid); this.refactorMainMenu.RenameMenuItem.Enabled = !(isClass || isConstructor || isVoid); this.editorReferencesItem.Enabled = this.viewReferencesItem.Enabled = true; if (result.Member != null && result.Type != null && result.InClass != null && result.InFile != null) { FlagType flags = result.Member.Flags; if ((flags & FlagType.Variable) > 0 && (flags & FlagType.LocalVar) == 0 && (flags & FlagType.ParameterVar) == 0) { this.refactorContextMenu.DelegateMenuItem.Enabled = true; this.refactorMainMenu.DelegateMenuItem.Enabled = true; } } } else { this.refactorMainMenu.RenameMenuItem.Enabled = false; this.refactorContextMenu.RenameMenuItem.Enabled = false; this.editorReferencesItem.Enabled = false; this.viewReferencesItem.Enabled = false; } IASContext context = ASContext.Context; if (context != null && context.CurrentModel != null) { Boolean truncate = (this.GetLanguageIsValid() && context.CurrentModel.Imports.Count > 0); Boolean organize = (this.GetLanguageIsValid() && context.CurrentModel.Imports.Count > 1); this.refactorContextMenu.OrganizeMenuItem.Enabled = organize; this.refactorContextMenu.TruncateMenuItem.Enabled = truncate && !this.LanguageIsHaxe(); this.refactorMainMenu.OrganizeMenuItem.Enabled = organize; this.refactorMainMenu.TruncateMenuItem.Enabled = truncate && !this.LanguageIsHaxe(); } this.surroundContextMenu.Enabled = false; this.refactorMainMenu.SurroundMenu.Enabled = false; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = false; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = false; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = false; this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = false; ITabbedDocument document = PluginBase.MainForm.CurrentDocument; if (document != null && document.IsEditable && this.GetLanguageIsValid() && document.SciControl.SelTextSize > 1) { Int32 selEnd = document.SciControl.SelectionEnd; Int32 selStart = document.SciControl.SelectionStart; if (!document.SciControl.PositionIsOnComment(selEnd) || !document.SciControl.PositionIsOnComment(selStart)) { this.surroundContextMenu.Enabled = true; this.refactorMainMenu.SurroundMenu.Enabled = true; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = true; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = true; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = true; this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = true; } } this.refactorContextMenu.CodeGeneratorMenuItem.Enabled = isValid; this.refactorMainMenu.CodeGeneratorMenuItem.Enabled = isValid; } catch {} }
private static void GenerateImplementation(ClassModel iType, ClassModel inClass, ScintillaControl sci, bool detached) { List<string> typesUsed = new List<string>(); StringBuilder sb = new StringBuilder(); string header = TemplateUtils.ReplaceTemplateVariable(TemplateUtils.GetTemplate("ImplementHeader"), "Class", iType.Type); header = TemplateUtils.ReplaceTemplateVariable(header, "BlankLine", detached ? BlankLine : null); sb.Append(header); sb.Append(NewLine); bool entry = true; ASResult result = new ASResult(); IASContext context = ASContext.Context; ContextFeatures features = context.Features; bool canGenerate = false; bool isHaxe = IsHaxe; FlagType flags = (FlagType.Function | FlagType.Getter | FlagType.Setter); if (isHaxe) flags |= FlagType.Variable; iType.ResolveExtends(); // resolve inheritance chain while (!iType.IsVoid() && iType.QualifiedName != "Object") { foreach (MemberModel method in iType.Members) { if ((method.Flags & flags) == 0 || method.Name == iType.Name) continue; // check if method exists ASComplete.FindMember(method.Name, inClass, result, method.Flags, 0); if (!result.IsNull()) continue; string decl; if ((method.Flags & FlagType.Getter) > 0) { if (isHaxe) { decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Property")); string templateName = null; string metadata = null; if (method.Parameters[0].Name == "get") { if (method.Parameters[1].Name == "set") { templateName = "GetterSetter"; metadata = "@:isVar"; } else templateName = "Getter"; } else if (method.Parameters[1].Name == "set") { templateName = "Setter"; } decl = TemplateUtils.ReplaceTemplateVariable(decl, "MetaData", metadata); if (templateName != null) { var accessor = NewLine + TemplateUtils.ToDeclarationString(method, TemplateUtils.GetTemplate(templateName)); accessor = TemplateUtils.ReplaceTemplateVariable(accessor, "Modifiers", null); accessor = TemplateUtils.ReplaceTemplateVariable(accessor, "Member", method.Name); decl += accessor; } } else decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Getter")); } else if ((method.Flags & FlagType.Setter) > 0) decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Setter")); else if ((method.Flags & FlagType.Function) > 0) decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Function")); else decl = NewLine + TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Variable")); decl = TemplateUtils.ReplaceTemplateVariable(decl, "Member", "_" + method.Name); decl = TemplateUtils.ReplaceTemplateVariable(decl, "Void", features.voidKey); decl = TemplateUtils.ReplaceTemplateVariable(decl, "Body", null); decl = TemplateUtils.ReplaceTemplateVariable(decl, "BlankLine", NewLine); if (!entry) { decl = TemplateUtils.ReplaceTemplateVariable(decl, "EntryPoint", null); } decl += NewLine; entry = false; sb.Append(decl); canGenerate = true; AddTypeOnce(typesUsed, GetQualifiedType(method.Type, iType)); if (method.Parameters != null && method.Parameters.Count > 0) foreach (MemberModel param in method.Parameters) AddTypeOnce(typesUsed, GetQualifiedType(param.Type, iType)); } // interface inheritance iType = iType.Extends; } if (!canGenerate) return; sci.BeginUndoAction(); try { int position = sci.CurrentPos; if (ASContext.Context.Settings.GenerateImports && typesUsed.Count > 0) { int offset = AddImportsByName(typesUsed, sci.LineFromPosition(position)); position += offset; sci.SetSel(position, position); } InsertCode(position, sb.ToString(), sci); } finally { sci.EndUndoAction(); } }
private static void GenerateImplementation(ClassModel aType, int position) { List<string> typesUsed = new List<string>(); StringBuilder sb = new StringBuilder(String.Format(GetTemplate("ImplementHeader"), aType.Type)); string entry = "$(EntryPoint)"; ASResult result = new ASResult(); IASContext context = ASContext.Context; ClassModel cClass = context.CurrentClass; ContextFeatures features = context.Features; bool canGenerate = false; string template = GetTemplate("ImplementPart"); aType.ResolveExtends(); // resolve inheritance chain while (!aType.IsVoid() && aType.QualifiedName != "Object") { foreach (MemberModel method in aType.Members) { if ((method.Flags & (FlagType.Function | FlagType.Getter | FlagType.Setter)) == 0 || method.Name == aType.Name) continue; // check if method exists ASComplete.FindMember(method.Name, cClass, result, method.Flags, 0); if (!result.IsNull()) continue; string decl = String.Format(template, GetDeclaration(method), entry); entry = ""; sb.Append(decl); canGenerate = true; addTypeOnce(typesUsed, getQualifiedType(method.Type, aType)); if (method.Parameters != null && method.Parameters.Count > 0) foreach (MemberModel param in method.Parameters) addTypeOnce(typesUsed, getQualifiedType(param.Type, aType)); } // interface inheritance aType = aType.Extends; } if (!canGenerate) return; ScintillaNet.ScintillaControl Sci = ASContext.CurSciControl; Sci.BeginUndoAction(); try { position = Sci.CurrentPos; if (ASContext.Context.Settings.GenerateImports && typesUsed.Count > 0) { int offset = AddImportsByName(typesUsed, Sci.LineFromPosition(position)); position += offset; Sci.SetSel(position, position); } InsertCode(position, sb.ToString()); } finally { Sci.EndUndoAction(); } }
private void UpdateMenuItems(ResolvedContext resolved) { try { var document = PluginBase.MainForm.CurrentDocument; var curFileName = document != null ? document.FileName : string.Empty; this.refactorMainMenu.DelegateMenuItem.Enabled = false; this.refactorContextMenu.DelegateMenuItem.Enabled = false; bool langIsValid = RefactoringHelper.GetLanguageIsValid(); bool isValid = langIsValid && resolved != null && resolved.Position >= 0; ASResult result = isValid ? resolved.Result : null; if (result != null && !result.IsNull()) { var validator = CommandFactoryProvider.GetFactory(result)?.GetValidator(typeof(Rename)) ?? CommandFactoryProvider.DefaultFactory.GetValidator(typeof(Rename)); var isRenameable = validator(result); this.refactorContextMenu.RenameMenuItem.Enabled = isRenameable; this.refactorMainMenu.RenameMenuItem.Enabled = isRenameable; var enabled = !result.IsPackage && (File.Exists(curFileName) || curFileName.Contains("[model]")); this.editorReferencesItem.Enabled = enabled; this.viewReferencesItem.Enabled = enabled; if (result.InFile != null && result.InClass != null && (result.InClass.Flags & FlagType.Interface) == 0 && result.Member != null && result.Type != null) { FlagType flags = result.Member.Flags; if ((flags & FlagType.Variable) > 0 && (flags & FlagType.LocalVar) == 0 && (flags & FlagType.ParameterVar) == 0) { this.refactorContextMenu.DelegateMenuItem.Enabled = true; this.refactorMainMenu.DelegateMenuItem.Enabled = true; } } } else { this.refactorMainMenu.RenameMenuItem.Enabled = false; this.refactorContextMenu.RenameMenuItem.Enabled = false; this.editorReferencesItem.Enabled = false; this.viewReferencesItem.Enabled = false; } IASContext context = ASContext.Context; if (context != null && context.CurrentModel != null) { bool enabled = langIsValid && context.CurrentModel.Imports.Count > 0; this.refactorContextMenu.OrganizeMenuItem.Enabled = enabled; this.refactorContextMenu.TruncateMenuItem.Enabled = enabled; this.refactorMainMenu.OrganizeMenuItem.Enabled = enabled; this.refactorMainMenu.TruncateMenuItem.Enabled = enabled; } refactorMainMenu.MoveMenuItem.Enabled = false; refactorContextMenu.MoveMenuItem.Enabled = false; this.surroundContextMenu.Enabled = false; this.refactorMainMenu.SurroundMenu.Enabled = false; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = false; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = false; this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = false; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = false; if (document != null && document.IsEditable && langIsValid) { bool isValidFile = IsValidFile(curFileName); refactorMainMenu.MoveMenuItem.Enabled = isValidFile; refactorContextMenu.MoveMenuItem.Enabled = isValidFile; var sci = document.SciControl; if (sci.SelTextSize > 0) { if (!sci.PositionIsOnComment(sci.SelectionStart) || !sci.PositionIsOnComment(sci.SelectionEnd)) { this.surroundContextMenu.Enabled = true; this.refactorMainMenu.SurroundMenu.Enabled = true; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = true; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = true; } if (context != null) { var declAtSelStart = context.GetDeclarationAtLine(sci.LineFromPosition(sci.SelectionStart)); var declAtSelEnd = context.GetDeclarationAtLine(sci.LineFromPosition(sci.SelectionEnd)); if (declAtSelStart != null && declAtSelStart.Member != null && (declAtSelStart.Member.Flags & FlagType.Function) > 0 && declAtSelEnd != null && declAtSelStart.Member.Equals(declAtSelEnd.Member)) { this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = true; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = true; } } } } this.refactorMainMenu.CodeGeneratorMenuItem.Enabled = isValid; this.refactorContextMenu.CodeGeneratorMenuItem.Enabled = isValid; } catch { } }
/// <summary> /// Updates the state of the menu items /// </summary> private void UpdateMenuItems() { try { this.refactorMainMenu.DelegateMenuItem.Enabled = false; this.refactorContextMenu.DelegateMenuItem.Enabled = false; bool langIsValid = RefactoringHelper.GetLanguageIsValid(); ResolvedContext resolved = ASComplete.CurrentResolvedContext; bool isValid = langIsValid && resolved != null && resolved.Position >= 0; ASResult result = isValid ? resolved.Result : null; if (result != null && !result.IsNull()) { bool isRenameable = (result.Member != null && RefactoringHelper.ModelFileExists(result.Member.InFile) && !RefactoringHelper.IsUnderSDKPath(result.Member.InFile)) || (result.Type != null && RefactoringHelper.ModelFileExists(result.Type.InFile) && !RefactoringHelper.IsUnderSDKPath(result.Type.InFile)) || (RefactoringHelper.ModelFileExists(result.InFile) && !RefactoringHelper.IsUnderSDKPath(result.InFile)) || result.IsPackage; this.refactorContextMenu.RenameMenuItem.Enabled = isRenameable; this.refactorMainMenu.RenameMenuItem.Enabled = isRenameable; bool isNotPackage = !result.IsPackage; this.editorReferencesItem.Enabled = isNotPackage; this.viewReferencesItem.Enabled = isNotPackage; if (result.Member != null && result.Type != null && result.InClass != null && result.InFile != null) { FlagType flags = result.Member.Flags; if ((flags & FlagType.Variable) > 0 && (flags & FlagType.LocalVar) == 0 && (flags & FlagType.ParameterVar) == 0) { this.refactorContextMenu.DelegateMenuItem.Enabled = true; this.refactorMainMenu.DelegateMenuItem.Enabled = true; } } } else { this.refactorMainMenu.RenameMenuItem.Enabled = false; this.refactorContextMenu.RenameMenuItem.Enabled = false; this.editorReferencesItem.Enabled = false; this.viewReferencesItem.Enabled = false; } IASContext context = ASContext.Context; if (context != null && context.CurrentModel != null) { bool truncate = langIsValid && context.CurrentModel.Imports.Count > 0; bool organize = (langIsValid && context.CurrentModel.Imports.Count > 1); this.refactorContextMenu.OrganizeMenuItem.Enabled = organize; this.refactorContextMenu.TruncateMenuItem.Enabled = truncate; this.refactorMainMenu.OrganizeMenuItem.Enabled = organize; this.refactorMainMenu.TruncateMenuItem.Enabled = truncate; } this.surroundContextMenu.Enabled = false; this.refactorMainMenu.SurroundMenu.Enabled = false; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = false; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = false; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = false; this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = false; ITabbedDocument document = PluginBase.MainForm.CurrentDocument; if (document != null && document.IsEditable && langIsValid && document.SciControl.SelTextSize > 1) { Int32 selEnd = document.SciControl.SelectionEnd; Int32 selStart = document.SciControl.SelectionStart; if (!document.SciControl.PositionIsOnComment(selEnd) || !document.SciControl.PositionIsOnComment(selStart)) { this.surroundContextMenu.Enabled = true; this.refactorMainMenu.SurroundMenu.Enabled = true; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = true; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = true; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = true; this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = true; } } this.refactorContextMenu.CodeGeneratorMenuItem.Enabled = isValid; this.refactorMainMenu.CodeGeneratorMenuItem.Enabled = isValid; } catch {} }
private static void GenerateImplementation(ClassModel aType, int position) { List<string> typesUsed = new List<string>(); StringBuilder sb = new StringBuilder(TemplateUtils.ReplaceTemplateVariable(TemplateUtils.GetTemplate("ImplementHeader"), "Class", aType.Type)); sb.Append(NewLine); bool entry = true; ASResult result = new ASResult(); IASContext context = ASContext.Context; ClassModel cClass = context.CurrentClass; ContextFeatures features = context.Features; bool canGenerate = false; aType.ResolveExtends(); // resolve inheritance chain while (!aType.IsVoid() && aType.QualifiedName != "Object") { foreach (MemberModel method in aType.Members) { if ((method.Flags & (FlagType.Function | FlagType.Getter | FlagType.Setter)) == 0 || method.Name == aType.Name) continue; // check if method exists ASComplete.FindMember(method.Name, cClass, result, method.Flags, 0); if (!result.IsNull()) continue; string decl = entry ? NewLine : ""; if ((method.Flags & FlagType.Getter) > 0) decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Getter")); else if ((method.Flags & FlagType.Setter) > 0) decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Setter")); else decl = TemplateUtils.ToDeclarationWithModifiersString(method, TemplateUtils.GetTemplate("Function")); decl = TemplateUtils.ReplaceTemplateVariable(decl, "Member", "_" + method.Name); decl = TemplateUtils.ReplaceTemplateVariable(decl, "Void", features.voidKey); decl = TemplateUtils.ReplaceTemplateVariable(decl, "Body", null); decl = TemplateUtils.ReplaceTemplateVariable(decl, "BlankLine", NewLine); if (!entry) { decl = TemplateUtils.ReplaceTemplateVariable(decl, "EntryPoint", null); } decl += NewLine; entry = false; sb.Append(decl); canGenerate = true; addTypeOnce(typesUsed, getQualifiedType(method.Type, aType)); if (method.Parameters != null && method.Parameters.Count > 0) foreach (MemberModel param in method.Parameters) addTypeOnce(typesUsed, getQualifiedType(param.Type, aType)); } // interface inheritance aType = aType.Extends; } if (!canGenerate) return; ScintillaNet.ScintillaControl Sci = ASContext.CurSciControl; Sci.BeginUndoAction(); try { position = Sci.CurrentPos; if (ASContext.Context.Settings.GenerateImports && typesUsed.Count > 0) { int offset = AddImportsByName(typesUsed, Sci.LineFromPosition(position)); position += offset; Sci.SetSel(position, position); } InsertCode(position, sb.ToString()); } finally { Sci.EndUndoAction(); } }
/// <summary> /// Top-level elements lookup /// </summary> /// <param name="token">Element to search</param> /// <param name="result">Response structure</param> public override void ResolveTopLevelElement(string token, ASResult result) { if (topLevel != null && topLevel.Members.Count > 0) { // current class ClassModel inClass = ASContext.Context.CurrentClass; if (token == "this") { result.Member = topLevel.Members.Search("this", 0, 0); if (inClass.IsVoid()) inClass = ASContext.Context.ResolveType(result.Member.Type, null); result.Type = inClass; result.InFile = ASContext.Context.CurrentModel; return; } else if (token == "super") { if (inClass.IsVoid()) { MemberModel thisMember = topLevel.Members.Search("this", 0, 0); inClass = ASContext.Context.ResolveType(thisMember.Type, null); } inClass.ResolveExtends(); ClassModel extends = inClass.Extends; if (!extends.IsVoid()) { result.Member = topLevel.Members.Search("super", 0, 0); result.Type = extends; result.InFile = extends.InFile; return; } } // other top-level elements ASComplete.FindMember(token, topLevel, result, 0, 0); if (!result.IsNull()) return; // special _levelN if (hasLevels && token.StartsWith("_") && re_level.IsMatch(token)) { result.Member = new MemberModel(); result.Member.Name = token; result.Member.Flags = FlagType.Variable; result.Member.Type = "MovieClip"; result.Type = ResolveType("MovieClip", null); result.InFile = topLevel; } } }
private static void ShowGetSetList(FoundDeclaration found) { string name = GetPropertyNameFor(found.member); ASResult result = new ASResult(); ClassModel curClass = ASContext.Context.CurrentClass; ASComplete.FindMember(name, curClass, result, FlagType.Getter, 0); bool hasGetter = !result.IsNull(); ASComplete.FindMember(name, curClass, result, FlagType.Setter, 0); bool hasSetter = !result.IsNull(); if (hasGetter && hasSetter) return; List<ICompletionListItem> known = new List<ICompletionListItem>(); if (!hasGetter && !hasSetter) { string label = TextHelper.GetString("ASCompletion.Label.GenerateGetSet"); known.Add(new GeneratorItem(label, GeneratorJobType.GetterSetter, found.member, found.inClass)); } if (!hasGetter) { string label = TextHelper.GetString("ASCompletion.Label.GenerateGet"); known.Add(new GeneratorItem(label, GeneratorJobType.Getter, found.member, found.inClass)); } if (!hasSetter) { string label = TextHelper.GetString("ASCompletion.Label.GenerateSet"); known.Add(new GeneratorItem(label, GeneratorJobType.Setter, found.member, found.inClass)); } CompletionList.Show(known, false); }
static void ShowSetterList(FoundDeclaration found, ICollection<ICompletionListItem> options) { var name = GetPropertyNameFor(found.member); var result = new ASResult(); ASComplete.FindMember(name, ASContext.Context.CurrentClass, result, FlagType.Setter, 0); if (!result.IsNull()) return; var label = TextHelper.GetString("ASCompletion.Label.GenerateSet"); options.Add(new GeneratorItem(label, GeneratorJobType.Setter, found.member, found.inClass)); }