public int Compare(ClassModel x, ClassModel y) => CaseSensitiveImportComparer.CompareImports(x.Name + "." + x.InFile.Package, y.Name + "." + y.InFile.Package);
/// <summary> /// Add an 'import' statement in the current file /// </summary> /// <param name="member">Generates 'import {member.Type};'</param> /// <param name="fixScrolling">Keep the editor view as if we didn't add any code in the file</param> /// <returns>Inserted characters count</returns> public static int InsertImport(MemberModel member, bool fixScrolling) { ScintillaControl sci = ASContext.CurSciControl; FileModel cFile = ASContext.Context.CurrentModel; int position = sci.CurrentPos; int curLine = sci.LineFromPosition(position); string fullPath = member.Type; if ((member.Flags & (FlagType.Class | FlagType.Enum | FlagType.TypeDef | FlagType.Struct)) > 0) { FileModel inFile = member.InFile; if (inFile != null && inFile.Module == member.Name && inFile.Package != "") fullPath = inFile.Package + "." + inFile.Module; fullPath = CleanType(fullPath); } string nl = LineEndDetector.GetNewLineMarker(sci.EOLMode); string statement = "import " + fullPath + ";" + nl; // locate insertion point int line = (ASContext.Context.InPrivateSection) ? cFile.PrivateSectionIndex : 0; if (cFile.InlinedRanges != null) { foreach (InlineRange range in cFile.InlinedRanges) { if (position > range.Start && position < range.End) { line = sci.LineFromPosition(range.Start) + 1; break; } } } int firstLine = line; bool found = false; int packageLine = -1; string txt; int indent = 0; int skipIfDef = 0; Match mImport; var importComparer = new CaseSensitiveImportComparer(); while (line < curLine) { txt = sci.GetLine(line++).TrimStart(); if (txt.StartsWithOrdinal("package")) { packageLine = line; firstLine = line; } // skip Haxe #if blocks else if (txt.StartsWithOrdinal("#if ") && txt.IndexOfOrdinal("#end") < 0) skipIfDef++; else if (skipIfDef > 0) { if (txt.StartsWithOrdinal("#end")) skipIfDef--; else continue; } // insert imports after a package declaration else if (txt.Length > 6 && txt.StartsWithOrdinal("import") && txt[6] <= 32) { packageLine = -1; found = true; indent = sci.GetLineIndentation(line - 1); // insert in alphabetical order mImport = ASFileParserRegexes.Import.Match(txt); if (mImport.Success && importComparer.Compare(mImport.Groups["package"].Value, fullPath) > 0) { line--; break; } } else if (found) { line--; break; } if (packageLine >= 0 && !IsHaxe && txt.IndexOf('{') >= 0) { packageLine = -1; indent = sci.GetLineIndentation(line - 1) + PluginBase.MainForm.Settings.IndentSize; firstLine = line; } } // insert if (line == curLine) line = firstLine; position = sci.PositionFromLine(line); firstLine = sci.FirstVisibleLine; sci.SetSel(position, position); sci.ReplaceSel(statement); sci.SetLineIndentation(line, indent); sci.LineScroll(0, firstLine - sci.FirstVisibleLine + 1); ASContext.Context.RefreshContextCache(fullPath); return sci.GetLine(line).Length; }
public int Compare(ClassModel x, ClassModel y) => CaseSensitiveImportComparer.CompareImports(x.Name, y.Name);