/// <summary>
 /// Selects a search match
 /// </summary>
 public static void SelectMatch(ScintillaControl sci, SearchMatch match)
 {
     Int32 start = sci.MBSafePosition(match.Index); // wchar to byte position
     Int32 end = start + sci.MBSafeTextLength(match.Value); // wchar to byte text length
     Int32 line = sci.LineFromPosition(start);
     sci.EnsureVisible(line);
     sci.SetSel(start, end);
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the next valid match but fixes position with selected text's length
 /// </summary>
 public static SearchMatch GetNextDocumentMatch(ScintillaControl sci, List<SearchMatch> matches, Boolean forward, Boolean fixedPosition)
 {
     SearchMatch nearestMatch = matches[0];
     Int32 currentPosition = sci.MBSafeCharPosition(sci.CurrentPos);
     if (fixedPosition) currentPosition -= sci.MBSafeTextLength(sci.SelText);
     for (Int32 i = 0; i < matches.Count; i++)
     {
         if (forward)
         {
             if (currentPosition > matches[matches.Count - 1].Index)
             {
                 return matches[0];
             }
             if (matches[i].Index >= currentPosition)
             {
                 return matches[i];
             }
         }
         else
         {
             if (sci.SelText.Length > 0 && currentPosition <= matches[0].Index + matches[0].Value.Length)
             {
                 return matches[matches.Count - 1];
             }
             if (currentPosition < matches[0].Index + matches[0].Value.Length)
             {
                 return matches[matches.Count - 1];
             }
             if (sci.SelText.Length == 0 && currentPosition == matches[i].Index + matches[i].Value.Length)
             {
                 return matches[i];
             }
             if (matches[i].Index > nearestMatch.Index && matches[i].Index + matches[i].Value.Length < currentPosition)
             {
                 nearestMatch = matches[i];
             }
         }
     }
     return nearestMatch;
 }
Esempio n. 3
0
 private static bool RemoveOneLocalDeclaration(ScintillaControl sci, MemberModel contextMember)
 {
     string type = "";
     if (contextMember.Type != null && (contextMember.Flags & FlagType.Inferred) == 0)
     {
         type = FormatType(contextMember.Type);
         if (type.IndexOf('*') > 0)
             type = type.Replace("/*", @"/\*\s*").Replace("*/", @"\s*\*/");
         type = @":\s*" + type;
     }
     Regex reDecl = new Regex(String.Format(@"[\s\(]((var|const)\s+{0}\s*{1})\s*", contextMember.Name, type));
     for (int i = contextMember.LineFrom; i <= contextMember.LineTo + 10; i++)
     {
         string text = sci.GetLine(i);
         Match m = reDecl.Match(text);
         if (m.Success)
         {
             int index = sci.MBSafeTextLength(text.Substring(0, m.Groups[1].Index));
             int position = sci.PositionFromLine(i) + index;
             int len = sci.MBSafeTextLength(m.Groups[1].Value);
             sci.SetSel(position, position + len);
             if (contextMember.Type == null || (contextMember.Flags & FlagType.Inferred) != 0) sci.ReplaceSel(contextMember.Name + " ");
             else sci.ReplaceSel(contextMember.Name);
             UpdateLookupPosition(position, contextMember.Name.Length - len);
             return true;
         }
     }
     return false;
 }
Esempio n. 4
0
 /// <summary>
 /// Highlight a regexp match group
 /// </summary>
 /// <param name="sci"></param>
 /// <param name="matches"></param>
 private void AddHighlight(ScintillaControl sci, SearchMatch match)
 {
     Int32 start = sci.MBSafePosition(match.Index); // wchar to byte position
     Int32 end = start + sci.MBSafeTextLength(match.Value); // wchar to byte text length
     Int32 line = sci.LineFromPosition(start);
     Int32 position = start;
     Int32 es = sci.EndStyled;
     Int32 mask = 1 << sci.StyleBits;
     sci.SetIndicStyle(0, (Int32)ScintillaNet.Enums.IndicatorStyle.Max);
     sci.SetIndicFore(0, 0xff0000);
     sci.StartStyling(position, mask);
     sci.SetStyling(end - start, mask);
     sci.StartStyling(es, mask - 1);
 }
Esempio n. 5
0
        /// <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 bool DoesMatchPointToTarget(ScintillaNet.ScintillaControl Sci, SearchMatch match, ASResult target, DocumentHelper associatedDocumentHelper)
        {
            if (Sci == null || target == null)
            {
                return(false);
            }
            FileModel targetInFile = null;

            if (target.InFile != null)
            {
                targetInFile = target.InFile;
            }
            else if (target.Member != null && target.InClass == null)
            {
                targetInFile = target.Member.InFile;
            }

            Boolean matchMember = targetInFile != null && target.Member != null;
            Boolean matchType   = target.Member == null && target.IsStatic && target.Type != null;

            if (!matchMember && !matchType)
            {
                return(false);
            }

            ASResult result = null;

            // get type at match position
            if (match.Index < Sci.Text.Length) // TODO: find out rare cases of incorrect index reported
            {
                result = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value));
                if (associatedDocumentHelper != null)
                {
                    // because the declaration lookup opens a document, we should register it with the document helper to be closed later
                    associatedDocumentHelper.RegisterLoadedDocument(PluginBase.MainForm.CurrentDocument);
                }
            }
            // check if the result matches the target
            if (result == null || (result.InFile == null && result.Type == null))
            {
                return(false);
            }
            if (matchMember)
            {
                if (result.Member == null)
                {
                    return(false);
                }

                var resultInFile = result.InClass != null ? result.InFile : result.Member.InFile;

                return(resultInFile.BasePath == targetInFile.BasePath &&
                       resultInFile.FileName == targetInFile.FileName &&
                       result.Member.LineFrom == target.Member.LineFrom &&
                       result.Member.Name == target.Member.Name);
            }
            else // type
            {
                if (result.Type == null)
                {
                    return(false);
                }
                if (result.Type.QualifiedName == target.Type.QualifiedName)
                {
                    return(true);
                }
                return(false);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Checks if the given match actually is the declaration.
        /// </summary>
        public static bool IsMatchTheTarget(ScintillaNet.ScintillaControl Sci, SearchMatch match, ASResult target)
        {
            if (Sci == null || target == null || target.InFile == null || target.Member == null)
            {
                return(false);
            }
            String originalFile = Sci.FileName;
            // get type at match position
            ASResult declaration = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value));

            return((declaration.InFile != null && originalFile == declaration.InFile.FileName) && (Sci.CurrentPos == (Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value))));
        }
Esempio n. 7
0
        private static void GenerateVariableJob(GeneratorJobType job, ScintillaControl sci, MemberModel member, bool detach, ClassModel inClass)
        {
            var position = 0;
            bool isOtherClass = false;
            Visibility visibility = job.Equals(GeneratorJobType.Variable) ? GetDefaultVisibility(inClass) : Visibility.Public;
            FlagType kind = job.Equals(GeneratorJobType.Constant) ? FlagType.Constant : FlagType.Variable;
            // evaluate, if the variable (or constant) should be generated in other class
            ASResult varResult = ASComplete.GetExpressionType(sci, sci.WordEndPosition(sci.CurrentPos, true));
            var memberIsStatic = member != null && (member.Flags & FlagType.Static) > 0;
            var dot = ASContext.Context.Features.dot;
            if (ASContext.CommonSettings.GenerateScope && !varResult.Context.Value.Contains(dot))
            {
                position = sci.CurrentPos;
                var start = sci.WordStartPosition(position, true);
                var length = sci.MBSafeTextLength(contextToken);
                sci.SetSel(start, start + length);
                var scope = memberIsStatic ? inClass.QualifiedName : "this";
                var text = scope + dot + contextToken;
                sci.ReplaceSel(text);
                UpdateLookupPosition(position, text.Length - length);
            }
            int contextOwnerPos = GetContextOwnerEndPos(sci, sci.WordStartPosition(sci.CurrentPos, true));
            MemberModel isStatic = new MemberModel();
            if (contextOwnerPos != -1)
            {
                ASResult contextOwnerResult = ASComplete.GetExpressionType(sci, contextOwnerPos);
                if (contextOwnerResult != null
                    && (contextOwnerResult.Member == null || (contextOwnerResult.Member.Flags & FlagType.Constructor) > 0)
                    && contextOwnerResult.Type != null)
                {
                    isStatic.Flags |= FlagType.Static;
                }
            }
            else if (memberIsStatic)
            {
                isStatic.Flags |= FlagType.Static;
            }

            ASResult returnType = null;
            int lineNum = sci.CurrentLine;
            string line = sci.GetLine(lineNum);

            Match m = Regex.Match(line, "\\b" + Regex.Escape(contextToken) + "\\(");
            if (m.Success)
            {
                returnType = new ASResult();
                returnType.Type = ASContext.Context.ResolveType("Function", null);
            }
            else
            {
                m = Regex.Match(line, @"=\s*[^;\n\r}}]+");
                if (m.Success)
                {
                    int posLineStart = sci.PositionFromLine(lineNum);
                    if (posLineStart + m.Index >= sci.CurrentPos)
                    {
                        line = line.Substring(m.Index);
                        StatementReturnType rType = GetStatementReturnType(sci, inClass, line, posLineStart + m.Index);
                        if (rType != null)
                        {
                            returnType = rType.resolve;
                        }
                    }
                }
            }

            if (varResult.RelClass != null && !varResult.RelClass.IsVoid() && !varResult.RelClass.Equals(inClass))
            {
                AddLookupPosition();
                lookupPosition = -1;

                ASContext.MainForm.OpenEditableDocument(varResult.RelClass.InFile.FileName, false);
                sci = ASContext.CurSciControl;
                isOtherClass = true;

                FileModel fileModel = new FileModel();
                fileModel.Context = ASContext.Context;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(fileModel, sci.Text);

                foreach (ClassModel cm in fileModel.Classes)
                {
                    if (cm.QualifiedName.Equals(varResult.RelClass.QualifiedName))
                    {
                        varResult.RelClass = cm;
                        break;
                    }
                }
                inClass = varResult.RelClass;

                ASContext.Context.UpdateContext(inClass.LineFrom);
            }

            var latest = GetLatestMemberForVariable(job, inClass, visibility, isStatic);

            // if we generate variable in current class..
            if (!isOtherClass && member == null)
            {
                detach = false;
                lookupPosition = -1;
                position = sci.WordStartPosition(sci.CurrentPos, true);
                sci.SetSel(position, sci.WordEndPosition(position, true));
            }
            else // if we generate variable in another class
            {
                if (latest != null)
                {
                    position = FindNewVarPosition(sci, inClass, latest);
                }
                else
                {
                    position = GetBodyStart(inClass.LineFrom, inClass.LineTo, sci);
                    detach = false;
                }
                if (position <= 0) return;
                sci.SetSel(position, position);
            }

            // if this is a constant, we assign a value to constant
            string returnTypeStr = null;
            string eventValue = null;
            if (job == GeneratorJobType.Constant && returnType == null)
            {
                isStatic.Flags |= FlagType.Static;
                eventValue = "String = \"" + Camelize(contextToken) + "\"";
            }
            else if (returnType != null)
            {
                ClassModel inClassForImport;
                if (returnType.InClass != null)
                {
                    inClassForImport = returnType.InClass;
                }
                else if (returnType.RelClass != null)
                {
                    inClassForImport = returnType.RelClass;
                }
                else
                {
                    inClassForImport = inClass;
                }
                List<string> imports = new List<string>();
                if (returnType.Member != null)
                {
                    if (returnType.Member.Type != ASContext.Context.Features.voidKey)
                    {
                        returnTypeStr = FormatType(GetShortType(returnType.Member.Type));
                        imports.Add(GetQualifiedType(returnType.Member.Type, inClassForImport));
                    }
                }
                else if (returnType != null && returnType.Type != null)
                {
                    returnTypeStr = FormatType(GetShortType(returnType.Type.QualifiedName));
                    imports.Add(GetQualifiedType(returnType.Type.QualifiedName, inClassForImport));
                }
                if (imports.Count > 0)
                {
                    position += AddImportsByName(imports, sci.LineFromPosition(position));
                    sci.SetSel(position, position);
                }
            }
            MemberModel newMember = NewMember(contextToken, isStatic, kind, visibility);
            if (returnTypeStr != null)
            {
                newMember.Type = returnTypeStr;
            }
            else if (eventValue != null)
            {
                newMember.Type = eventValue;
            }
            GenerateVariable(newMember, position, detach);
        }
Esempio n. 8
0
        public static void InsertCode(int position, string src, ScintillaControl sci)
        {
            sci.BeginUndoAction();
            try
            {
                if (ASContext.CommonSettings.StartWithModifiers)
                    src = FixModifiersLocation(src);

                int len = SnippetHelper.InsertSnippetText(sci, position + sci.MBSafeTextLength(sci.SelText), src);
                UpdateLookupPosition(position, len);
                AddLookupPosition(sci);
            }
            finally { sci.EndUndoAction(); }
        }
Esempio n. 9
0
 /// <summary>
 /// Convert multibyte column to byte length
 /// </summary>
 private int MBSafeColumn(ScintillaControl sci, int line, int length)
 {
     String text = sci.GetLine(line) ?? "";
     length = Math.Min(length, text.Length);
     return sci.MBSafeTextLength(text.Substring(0, length));
 }
Esempio n. 10
0
        /// <summary>
        /// Adds highlights to the correct sci control
        /// </summary>
        private void AddHighlights(ScintillaControl sci, List<SearchMatch> matches)
        {
            if (matches == null)
            {
                return;
            }

            foreach (SearchMatch match in matches)
            {
                Int32 start = sci.MBSafePosition(match.Index);
                Int32 end = start + sci.MBSafeTextLength(match.Value);
                Int32 line = sci.LineFromPosition(start);
                Int32 position = start;
                Int32 es = sci.EndStyled;
                Int32 mask = 1 << sci.StyleBits;

                sci.SetIndicStyle(0, (Int32)ScintillaNet.Enums.IndicatorStyle.RoundBox);
                sci.SetIndicFore(0, DataConverter.ColorToInt32(this.settingObject.highlightColor));
                sci.StartStyling(position, mask);
                sci.SetStyling(end - start, mask);
                sci.StartStyling(es, mask - 1);

                if (this.settingObject.addLineMarker)
                {
                    sci.MarkerAdd(line, 2);
                    sci.MarkerSetBack(2, DataConverter.ColorToInt32(this.settingObject.highlightColor));
                }
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Inserts the specified snippet to the document
 /// </summary>
 public static Int32 InsertSnippetText(ScintillaControl sci, Int32 currentPosition, String snippet)
 {
     sci.BeginUndoAction();
     try
     {
         Int32 newIndent; 
         String text = snippet;
         if (sci.SelTextSize > 0)
             currentPosition -= sci.MBSafeTextLength(sci.SelText);
         Int32 line = sci.LineFromPosition(currentPosition);
         Int32 indent = sci.GetLineIndentation(line);
         sci.ReplaceSel("");
         
         Int32 lineMarker = LineEndDetector.DetectNewLineMarker(text, sci.EOLMode);
         String newline = LineEndDetector.GetNewLineMarker(lineMarker);
         if (newline != "\n") text = text.Replace(newline, "\n");
         newline = LineEndDetector.GetNewLineMarker((Int32)PluginBase.MainForm.Settings.EOLMode);
         text = PluginBase.MainForm.ProcessArgString(text).Replace(newline, "\n");
         newline = LineEndDetector.GetNewLineMarker(sci.EOLMode);
         String[] splitted = text.Trim().Split('\n');
         for (Int32 j = 0; j < splitted.Length; j++)
         {
             if (j != splitted.Length - 1) sci.InsertText(sci.CurrentPos, splitted[j] + newline);
             else sci.InsertText(sci.CurrentPos, splitted[j]);
             sci.CurrentPos += sci.MBSafeTextLength(splitted[j]) + newline.Length;
             if (j > 0)
             {
                 line = sci.LineFromPosition(sci.CurrentPos - newline.Length);
                 newIndent = sci.GetLineIndentation(line) + indent;
                 sci.SetLineIndentation(line, newIndent);
             }
         }
         Int32 length = sci.CurrentPos - currentPosition - newline.Length;
         Int32 delta = PostProcessSnippets(sci, currentPosition);
         return length + delta;
     }
     finally
     {
         sci.EndUndoAction();
     }
 }
Esempio n. 12
0
        /// <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>
        static public bool DoesMatchPointToTarget(ScintillaNet.ScintillaControl Sci, SearchMatch match, ASResult target, DocumentHelper associatedDocumentHelper)
        {
            if (Sci == null || target == null || target.inFile == null || target.Member == null)
            {
                return(false);
            }
            // get type at match position
            ASResult result = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value));

            if (associatedDocumentHelper != null)
            {
                // because the declaration lookup opens a document, we should register it with the document helper to be closed later
                associatedDocumentHelper.RegisterLoadedDocument(PluginBase.MainForm.CurrentDocument);
            }
            // check if the result matches the target
            // TODO: this method of checking their equality seems pretty crude -- is there a better way?
            if (result == null || result.inFile == null || result.Member == null)
            {
                return(false);
            }
            Boolean doesMatch = result.inFile.BasePath == target.inFile.BasePath && result.inFile.FileName == target.inFile.FileName && result.Member.LineFrom == target.Member.LineFrom && result.Member.Name == target.Member.Name;

            return(doesMatch);
        }
 /// <summary>
 /// Adds highlights to the correct sci control
 /// </summary>
 private void AddHighlights(ScintillaControl sci, List<SearchMatch> matches)
 {
     if (matches == null) return;
     int style = (int)settings.HighlightStyle;
     int color = DataConverter.ColorToInt32(settings.HighlightColor);
     if (settings.HighlightUnderCursorEnabled && prevResult != null)
     {
         if (prevResult.IsPackage) color = DataConverter.ColorToInt32(settings.PackageColor);
         else
         {
             FlagType flags;
             if (prevResult.Type != null && prevResult.Member == null)
             {
                 flags = prevResult.Type.Flags;
                 if ((flags & FlagType.Abstract) > 0) color = DataConverter.ColorToInt32(settings.AbstractColor);
                 else if ((flags & FlagType.TypeDef) > 0) color = DataConverter.ColorToInt32(settings.TypeDefColor);
                 else if ((flags & FlagType.Enum) > 0) color = DataConverter.ColorToInt32(settings.EnumColor);
                 else if ((flags & FlagType.Class) > 0) color = DataConverter.ColorToInt32(settings.ClassColor);
             }
             else if (prevResult.Member != null)
             {
                 flags = prevResult.Member.Flags;
                 if ((flags & FlagType.Constant) > 0) color = DataConverter.ColorToInt32(settings.ConstantColor);
                 else if ((flags & FlagType.ParameterVar) > 0) color = DataConverter.ColorToInt32(settings.MemberFunctionColor);
                 else if ((flags & FlagType.LocalVar) > 0) color = DataConverter.ColorToInt32(settings.LocalVariableColor);
                 else if ((flags & FlagType.Static) == 0)
                 {
                     if ((flags & FlagType.Variable) > 0) color = DataConverter.ColorToInt32(settings.VariableColor);
                     else if ((flags & (FlagType.Setter | FlagType.Getter)) > 0) color = DataConverter.ColorToInt32(settings.AccessorColor);
                     else if ((flags & FlagType.Function) > 0) color = DataConverter.ColorToInt32(settings.MethodColor);
                 }
                 else
                 {
                     if ((flags & FlagType.Variable) > 0) color = DataConverter.ColorToInt32(settings.StaticVariableColor);
                     else if ((flags & (FlagType.Setter | FlagType.Getter)) > 0) color = DataConverter.ColorToInt32(settings.StaticAccessorColor);
                     else if ((flags & FlagType.Function) > 0) color = DataConverter.ColorToInt32(settings.StaticMethodColor);
                 }
             }
         }
     }
     int es = sci.EndStyled;
     int mask = 1 << sci.StyleBits;
     bool addLineMarker = settings.AddLineMarker;
     foreach (SearchMatch match in matches)
     {
         int start = sci.MBSafePosition(match.Index);
         int end = start + sci.MBSafeTextLength(match.Value);
         int line = sci.LineFromPosition(start);
         int position = start;
         sci.SetIndicStyle(0, style);
         sci.SetIndicFore(0, color);
         sci.StartStyling(position, mask);
         sci.SetStyling(end - start, mask);
         sci.StartStyling(es, mask - 1);
         if (addLineMarker)
         {
             sci.MarkerAdd(line, MARKER_NUMBER);
             sci.MarkerSetBack(MARKER_NUMBER, color);
         }
     }
     prevPos = sci.CurrentPos;
 }
Esempio n. 14
0
        public static bool MakePrivate(ScintillaControl Sci, MemberModel member, ClassModel inClass)
        {
            ContextFeatures features = ASContext.Context.Features;
            string visibility = GetPrivateKeyword(inClass);
            if (features.publicKey == null || visibility == null) return false;
            Regex rePublic = new Regex(String.Format(@"\s*({0})\s+", features.publicKey));

            string line;
            Match m;
            int index, position;
            for (int i = member.LineFrom; i <= member.LineTo; i++)
            {
                line = Sci.GetLine(i);
                m = rePublic.Match(line);
                if (m.Success)
                {
                    index = Sci.MBSafeTextLength(line.Substring(0, m.Groups[1].Index));
                    position = Sci.PositionFromLine(i) + index;
                    Sci.SetSel(position, position + features.publicKey.Length);
                    Sci.ReplaceSel(visibility);
                    UpdateLookupPosition(position, features.publicKey.Length - visibility.Length);
                    return true;
                }
            }
            return false;
        }
Esempio n. 15
0
 /// <summary>
 /// Checks if the given match actually is the declaration.
 /// </summary>
 public static bool IsMatchTheTarget(ScintillaControl Sci, SearchMatch match, ASResult target)
 {
     if (Sci == null || target == null || target.InFile == null || target.Member == null)
     {
         return false;
     }
     String originalFile = Sci.FileName;
     // get type at match position
     ASResult declaration = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value));
     return (declaration.InFile != null && originalFile == declaration.InFile.FileName) && (Sci.CurrentPos == (Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value)));
 }
Esempio n. 16
0
        public static bool RenameMember(ScintillaControl Sci, MemberModel member, string newName)
        {
            ContextFeatures features = ASContext.Context.Features;
            string kind = features.varKey;

            if ((member.Flags & FlagType.Getter) > 0)
                kind = features.getKey;
            else if ((member.Flags & FlagType.Setter) > 0)
                kind = features.setKey;
            else if (member.Flags == FlagType.Function)
                kind = features.functionKey;

            Regex reMember = new Regex(String.Format(@"{0}\s+({1})[\s:]", kind, member.Name));

            string line;
            Match m;
            int index, position;
            for (int i = member.LineFrom; i <= member.LineTo; i++)
            {
                line = Sci.GetLine(i);
                m = reMember.Match(line);
                if (m.Success)
                {
                    index = Sci.MBSafeTextLength(line.Substring(0, m.Groups[1].Index));
                    position = Sci.PositionFromLine(i) + index;
                    Sci.SetSel(position, position + member.Name.Length);
                    Sci.ReplaceSel(newName);
                    UpdateLookupPosition(position, 1);
                    return true;
                }
            }
            return false;
        }
Esempio n. 17
0
        /// <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 bool DoesMatchPointToTarget(ScintillaControl Sci, SearchMatch match, ASResult target, DocumentHelper associatedDocumentHelper)
        {
            if (Sci == null || target == null) return false;
            FileModel targetInFile = null;

            if (target.InFile != null)
                targetInFile = target.InFile;
            else if (target.Member != null && target.InClass == null)
                targetInFile = target.Member.InFile;

            Boolean matchMember = targetInFile != null && target.Member != null;
            Boolean matchType = target.Member == null && target.IsStatic && target.Type != null;
            if (!matchMember && !matchType) return false;

            ASResult result = null;
            // get type at match position
            if (match.Index < Sci.Text.Length) // TODO: find out rare cases of incorrect index reported
            {
                result = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value));
                if (associatedDocumentHelper != null)
                {
                    // because the declaration lookup opens a document, we should register it with the document helper to be closed later
                    associatedDocumentHelper.RegisterLoadedDocument(PluginBase.MainForm.CurrentDocument);
                }
            }
            // check if the result matches the target
            if (result == null || (result.InFile == null && result.Type == null)) return false;
            if (matchMember)
            {
                if (result.Member == null) return false;

                var resultInFile = result.InClass != null ? result.InFile : result.Member.InFile;

                return resultInFile.BasePath == targetInFile.BasePath
                    && resultInFile.FileName == targetInFile.FileName
                    && result.Member.LineFrom == target.Member.LineFrom
                    && result.Member.Name == target.Member.Name;
            }
            else // type
            {
                if (result.Type == null) return false;
                if (result.Type.QualifiedName == target.Type.QualifiedName) return true;
                return false;
            }
        }
Esempio n. 18
0
 /// <summary>
 /// Adds highlights to the correct sci control
 /// </summary>
 private void AddHighlights(ScintillaControl sci, List<SearchMatch> matches)
 {
     ITabbedDocument doc = DocumentManager.FindDocument(sci);
     Language language = MainForm.Instance.SciConfig.GetLanguage(sci.ConfigurationLanguage);
     foreach (SearchMatch match in matches)
     {
         Int32 start = sci.MBSafePosition(match.Index);
         Int32 end = start + sci.MBSafeTextLength(match.Value);
         Int32 line = sci.LineFromPosition(start);
         Int32 position = start;
         Int32 es = sci.EndStyled;
         Int32 mask = 1 << sci.StyleBits;
         // Define indics in both controls...
         doc.SplitSci1.SetIndicStyle(0, (Int32)ScintillaNet.Enums.IndicatorStyle.RoundBox);
         doc.SplitSci1.SetIndicFore(0, language.editorstyle.HighlightBackColor);
         doc.SplitSci2.SetIndicStyle(0, (Int32)ScintillaNet.Enums.IndicatorStyle.RoundBox);
         doc.SplitSci2.SetIndicFore(0, language.editorstyle.HighlightBackColor);
         sci.StartStyling(position, mask);
         sci.SetStyling(end - start, mask);
         sci.StartStyling(es, mask - 1);
     }
 }
Esempio n. 19
0
        private static void GenerateFunctionJob(GeneratorJobType job, ScintillaControl sci, MemberModel member, bool detach, ClassModel inClass)
        {
            var position = 0;
            bool isOtherClass = false;
            Visibility visibility = job.Equals(GeneratorJobType.FunctionPublic) ? Visibility.Public : GetDefaultVisibility(inClass);
            int wordPos = sci.WordEndPosition(sci.CurrentPos, true);
            List<FunctionParameter> functionParameters = ParseFunctionParameters(sci, wordPos);
            // evaluate, if the function should be generated in other class
            ASResult funcResult = ASComplete.GetExpressionType(sci, sci.WordEndPosition(sci.CurrentPos, true));
            var memberIsStatic = member != null && (member.Flags & FlagType.Static) > 0;
            var dot = ASContext.Context.Features.dot;
            if (ASContext.CommonSettings.GenerateScope && !funcResult.Context.Value.Contains(dot))
            {
                position = sci.CurrentPos;
                var start = sci.WordStartPosition(position, true);
                var length = sci.MBSafeTextLength(contextToken);
                sci.SetSel(start, start + length);
                var scope = memberIsStatic ? inClass.QualifiedName : "this";
                var text = scope + dot + contextToken;
                sci.ReplaceSel(text);
                UpdateLookupPosition(position, text.Length - length);
            }
            int contextOwnerPos = GetContextOwnerEndPos(sci, sci.WordStartPosition(sci.CurrentPos, true));
            MemberModel isStatic = new MemberModel();
            if (contextOwnerPos != -1)
            {
                ASResult contextOwnerResult = ASComplete.GetExpressionType(sci, contextOwnerPos);
                if (contextOwnerResult != null
                    && (contextOwnerResult.Member == null || (contextOwnerResult.Member.Flags & FlagType.Constructor) > 0)
                    && contextOwnerResult.Type != null)
                {
                    isStatic.Flags |= FlagType.Static;
                }
            }
            else if (memberIsStatic)
            {
                isStatic.Flags |= FlagType.Static;
            }
            if (funcResult.RelClass != null && !funcResult.RelClass.IsVoid() && !funcResult.RelClass.Equals(inClass))
            {
                AddLookupPosition();
                lookupPosition = -1;

                ASContext.MainForm.OpenEditableDocument(funcResult.RelClass.InFile.FileName, true);
                sci = ASContext.CurSciControl;
                isOtherClass = true;

                FileModel fileModel = new FileModel();
                fileModel.Context = ASContext.Context;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(fileModel, sci.Text);

                foreach (ClassModel cm in fileModel.Classes)
                {
                    if (cm.QualifiedName.Equals(funcResult.RelClass.QualifiedName))
                    {
                        funcResult.RelClass = cm;
                        break;
                    }
                }
                inClass = funcResult.RelClass;

                ASContext.Context.UpdateContext(inClass.LineFrom);
            }

            string blockTmpl;
            if ((isStatic.Flags & FlagType.Static) > 0)
            {
                blockTmpl = TemplateUtils.GetBoundary("StaticMethods");
            }
            else if ((visibility & Visibility.Public) > 0)
            {
                blockTmpl = TemplateUtils.GetBoundary("PublicMethods");
            }
            else
            {
                blockTmpl = TemplateUtils.GetBoundary("PrivateMethods");
            }
            var latest = TemplateUtils.GetTemplateBlockMember(sci, blockTmpl);
            if (latest == null || (!isOtherClass && member == null))
            {
                latest = GetLatestMemberForFunction(inClass, visibility, isStatic);
                // if we generate function in current class..
                if (!isOtherClass)
                {
                    MethodsGenerationLocations location = ASContext.CommonSettings.MethodsGenerationLocations;
                    if (member == null)
                    {
                        detach = false;
                        lookupPosition = -1;
                        position = sci.WordStartPosition(sci.CurrentPos, true);
                        sci.SetSel(position, sci.WordEndPosition(position, true));
                    }
                    else if (latest != null && location == MethodsGenerationLocations.AfterSimilarAccessorMethod)
                    {
                        position = sci.PositionFromLine(latest.LineTo + 1) - (sci.EOLMode == 0 ? 2 : 1);
                        sci.SetSel(position, position);
                    }
                    else
                    {
                        position = sci.PositionFromLine(member.LineTo + 1) - (sci.EOLMode == 0 ? 2 : 1);
                        sci.SetSel(position, position);
                    }
                }
                else // if we generate function in another class..
                {
                    if (latest != null)
                    {
                        position = sci.PositionFromLine(latest.LineTo + 1) - (sci.EOLMode == 0 ? 2 : 1);
                    }
                    else
                    {
                        position = GetBodyStart(inClass.LineFrom, inClass.LineTo, sci);
                        detach = false;
                    }
                    sci.SetSel(position, position);
                }
            }
            else
            {
                position = sci.PositionFromLine(latest.LineTo + 1) - (sci.EOLMode == 0 ? 2 : 1);
                sci.SetSel(position, position);
            }

            // add imports to function argument types
            if (functionParameters.Count > 0)
            {
                List<string> typesUsed = new List<string>();
                foreach (FunctionParameter parameter in functionParameters)
                {
                    try
                    {
                        typesUsed.Add(parameter.paramQualType);
                    }
                    catch (Exception) { }
                }
                int o = AddImportsByName(typesUsed, sci.LineFromPosition(position));
                position += o;
                if (latest == null)
                    sci.SetSel(position, sci.WordEndPosition(position, true));
                else
                    sci.SetSel(position, position);
            }
            List<MemberModel> parameters = new List<MemberModel>();
            foreach (FunctionParameter parameter in functionParameters)
            {
                parameters.Add(new MemberModel(parameter.paramName, parameter.paramType, FlagType.ParameterVar, 0));
            }
            var newMember = NewMember(contextToken, isStatic, FlagType.Function, visibility);
            newMember.Parameters = parameters;
            GenerateFunction(newMember, position, detach, inClass);
        }