Ejemplo n.º 1
0
        private void ExtractFilesFromArchive()
        {
            string[] masks = context.GetExplorerMask();
            for (int i = 0; i < masks.Length; i++)
            {
                masks[i] = masks[i].Substring(masks[i].IndexOf('*') + 1);
            }

            Stream       fileStream = File.OpenRead(pathModel.Path);
            ZipFile      zipFile    = new ZipFile(fileStream);
            ASFileParser parser     = new ASFileParser();
            Dictionary <string, FileModel> models = new Dictionary <string, FileModel>();

            foreach (ZipEntry entry in zipFile)
            {
                string ext = Path.GetExtension(entry.Name).ToLower();
                foreach (string mask in masks)
                {
                    if (ext == mask)
                    {
                        string    src   = UnzipFile(zipFile, entry);
                        FileModel model = new FileModel(Path.Combine(pathModel.Path, entry.Name));
                        model.Context = pathModel.Owner;
                        parser.ParseSrc(model, src);
                        models.Add(model.FileName, model);
                    }
                }
            }
            zipFile.Close();
            fileStream.Close();

            pathModel.SetFiles(models);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Entry point to execute renaming.
        /// </summary>
        protected override void ExecutionImplementation()
        {
            var sci       = PluginBase.MainForm.CurrentDocument.SciControl;
            var fileModel = ASContext.Context.CurrentModel;
            var parser    = new ASFileParser();

            parser.ParseSrc(fileModel, sci.Text);
            var search = new FRSearch(sci.SelText)
            {
                SourceFile = sci.FileName
            };
            var mathes        = search.Matches(sci.Text);
            var currentMember = fileModel.Context.CurrentMember;
            var lineFrom      = currentMember.LineFrom;
            var lineTo        = currentMember.LineTo;

            mathes.RemoveAll(it => it.Line <lineFrom || it.Line> lineTo);
            var target = mathes.FindAll(it => sci.MBSafePosition(it.Index) == sci.SelectionStart);

            if (mathes.Count > 1)
            {
                CompletionList = new List <ICompletionListItem> {
                    new CompletionListItem(target, sci, OnItemClick)
                };
                CompletionList.Insert(0, new CompletionListItem(mathes, sci, OnItemClick));
                sci.DisableAllSciEvents = true;
                PluginCore.Controls.CompletionList.Show(CompletionList, true);
            }
            else
            {
                GenerateExtractVariable(target);
            }
        }
Ejemplo n.º 3
0
        public void Check()
        {
            if (this == FileModel.Ignore)
            {
                return;
            }

            if (OutOfDate)
            {
                OutOfDate = false;
                if (File.Exists(FileName) && (CachedModel || LastWriteTime < System.IO.File.GetLastWriteTime(FileName)))
                {
                    try
                    {
                        ASFileParser.ParseFile(this);
                    }
                    catch
                    {
                        OutOfDate = false;
                        Imports.Clear();
                        Classes.Clear();
                        Members.Clear();
                        PrivateSectionIndex = 0;
                        Package             = "";
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void Check()
        {
            if (this == Ignore)
            {
                return;
            }

            if (OutOfDate)
            {
                OutOfDate = false;
                if (FileName != "" && File.Exists(FileName) && LastWriteTime < File.GetLastWriteTime(FileName))
                {
                    try
                    {
                        ASFileParser.ParseFile(this);
                        OnFileUpdate?.Invoke(this);
                    }
                    catch
                    {
                        OutOfDate = false;
                        Imports.Clear();
                        Classes.Clear();
                        Members.Clear();
                        PrivateSectionIndex = 0;
                        Package             = "";
                    }
                }
            }
        }
Ejemplo n.º 5
0
        static void BuildClassPath(AS3Context.Context context)
        {
            context.BuildClassPath();
            var intrinsicPath = $"{PathHelper.LibraryDir}{Path.DirectorySeparatorChar}AS3{Path.DirectorySeparatorChar}intrinsic";

            context.Classpath.AddRange(Directory.GetDirectories(intrinsicPath).Select(it => new PathModel(it, context)));
            foreach (var it in context.Classpath)
            {
                if (it.IsVirtual)
                {
                    context.ExploreVirtualPath(it);
                }
                else
                {
                    var path = it.Path;
                    foreach (var searchPattern in context.GetExplorerMask())
                    {
                        foreach (var fileName in Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories))
                        {
                            it.AddFile(ASFileParser.ParseFile(new FileModel(fileName)
                            {
                                Context = context, Version = 3
                            }));
                        }
                    }
                    context.RefreshContextCache(path);
                }
            }
        }
Ejemplo n.º 6
0
        static void BuildClassPath(HaXeContext.Context context)
        {
            var platformsFile = Path.Combine("Settings", "Platforms");

            PlatformData.Load(Path.Combine(PathHelper.AppDir, platformsFile));
            PluginBase.CurrentProject = new HaxeProject("haxe")
            {
                CurrentSDK = Environment.GetEnvironmentVariable("HAXEPATH")
            };
            context.BuildClassPath();
            foreach (var it in context.Classpath)
            {
                var path = it.Path;
                foreach (var searchPattern in context.GetExplorerMask())
                {
                    foreach (var fileName in Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories))
                    {
                        it.AddFile(ASFileParser.ParseFile(new FileModel(fileName)
                        {
                            Context = context, haXe = true, Version = 4
                        }));
                    }
                }
                context.RefreshContextCache(path);
            }
        }
Ejemplo n.º 7
0
        private static FileModel ParseInclude(FileModel fileModel, ASMetaData meta)
        {
            Match m = reIncPath.Match(meta.RawParams);

            if (m.Success)
            {
                string path = m.Groups[2].Value;
                if (path.Length == 0)
                {
                    return(null);
                }

                // retrieve from cache
                if (includesCache.ContainsKey(path))
                {
                    return(includesCache[path]);
                }

                // relative path?
                string fileName = path;
                if (!Path.IsPathRooted(fileName))
                {
                    if (fileName[0] == '/' || fileName[0] == '\\')
                    {
                        fileName = Path.Combine(fileModel.BasePath, fileName);
                    }
                    else
                    {
                        fileName = Path.Combine(Path.GetDirectoryName(fileModel.FileName), fileName);
                    }
                }

                // parse & cache
                if (!File.Exists(fileName))
                {
                    return(null);
                }
                string src = File.ReadAllText(fileName);
                if (src.IndexOf("package") < 0)
                {
                    src = "package {" + src + "}";
                }
                ASFileParser parser = new ASFileParser();
                FileModel    model  = new FileModel(path);
                parser.ParseSrc(model, src);

                includesCache[path] = model;
                return(model);
            }
            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Refresh the file model
        /// </summary>
        /// <param name="updateUI">Update outline view</param>
        public override void UpdateCurrentFile(bool updateUI)
        {
            if (cFile == null || CurSciControl == null)
            {
                return;
            }
            ASFileParser parser = new ASFileParser();

            parser.ParseSrc(cFile, CurSciControl.Text);
            ScriptToClass(cFile);
            cLine = CurSciControl.LineFromPosition(CurSciControl.CurrentPos);
            UpdateContext(cLine);

            // update outline
            if (updateUI)
            {
                ASContext.Context = this;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Build the file DOM
        /// </summary>
        /// <param name="filename">File path</param>
        protected override void GetCurrentFileModel(string fileName)
        {
            string ext = Path.GetExtension(fileName);

            if (!re_PHPext.IsMatch(ext))
            {
                cFile = FileModel.Ignore;
                UpdateContext(cLine);
            }
            else
            {
                cFile              = new FileModel(fileName);
                cFile.Context      = this;
                cFile.HasFiltering = true;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(cFile, CurSciControl.Text);
                cLine = CurSciControl.CurrentLine;
                UpdateContext(cLine);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create a new file model using the default file parser
        /// </summary>
        /// <param name="filename">Full path</param>
        /// <returns>File model</returns>
        public override FileModel GetFileModel(string fileName)
        {
            if (fileName == null || fileName.Length == 0 || !File.Exists(fileName))
            {
                return(new FileModel(fileName));
            }

            fileName = PathHelper.GetLongPathName(fileName);
            if (mxmlEnabled && fileName.EndsWith(".mxml", StringComparison.OrdinalIgnoreCase))
            {
                FileModel nFile = new FileModel(fileName);
                nFile.Context      = this;
                nFile.HasFiltering = true;
                ASFileParser.ParseFile(nFile);
                return(nFile);
            }
            else
            {
                return(base.GetFileModel(fileName));
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// AS2/AS3 detection
 /// </summary>
 /// <param name="doc">Document to check</param>
 /// <returns>Detected language</returns>
 private string DetectActionscriptVersion(ITabbedDocument doc)
 {
     ASFileParser parser = new ASFileParser();
     FileModel model = new FileModel(doc.FileName);
     parser.ParseSrc(model, doc.SciControl.Text);
     if (model.Version == 1 && PluginBase.CurrentProject != null)
     {
         String lang = PluginBase.CurrentProject.Language;
         if (lang == "*") return "as2";
         else return lang;
     }
     else if (model.Version > 2) return "as3";
     else if (model.Version > 1) return "as2";
     else if (settingObject.LastASVersion != null && settingObject.LastASVersion.StartsWithOrdinal("as"))
     {
         return settingObject.LastASVersion;
     }
     else return "as2";
 }
        public void Execute()
        {
            Sci = PluginBase.MainForm.CurrentDocument.SciControl;
            Sci.BeginUndoAction();
            try
            {
                IASContext context = ASContext.Context;

                string selection = Sci.SelText;
                if (selection == null || selection.Length == 0)
                {
                    return;
                }

                if (selection.TrimStart().Length == 0)
                {
                    return;
                }

                Sci.SetSel(Sci.SelectionStart + selection.Length - selection.TrimStart().Length,
                           Sci.SelectionEnd);
                Sci.CurrentPos = Sci.SelectionEnd;

                Int32 pos = Sci.CurrentPos;

                int lineStart        = Sci.LineFromPosition(Sci.SelectionStart);
                int lineEnd          = Sci.LineFromPosition(Sci.SelectionEnd);
                int firstLineIndent  = Sci.GetLineIndentation(lineStart);
                int entryPointIndent = Sci.Indent;

                for (int i = lineStart; i <= lineEnd; i++)
                {
                    int indent = Sci.GetLineIndentation(i);
                    if (i > lineStart)
                    {
                        Sci.SetLineIndentation(i, indent - firstLineIndent + entryPointIndent);
                    }
                }

                string selText = Sci.SelText;
                Sci.ReplaceSel(NewName + "();");

                cFile = ASContext.Context.CurrentModel;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(cFile, Sci.Text);

                bool isAs3 = cFile.Context.Settings.LanguageId == "AS3";

                FoundDeclaration found = GetDeclarationAtLine(Sci, lineStart);
                if (found == null || found.member == null)
                {
                    return;
                }

                int position = Sci.PositionFromLine(found.member.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
                Sci.SetSel(position, position);

                StringBuilder sb = new StringBuilder();
                sb.Append("$(Boundary)\n\n");
                if ((found.member.Flags & FlagType.Static) > 0)
                {
                    sb.Append("static ");
                }
                sb.Append(ASGenerator.GetPrivateKeyword());
                sb.Append(" function ");
                sb.Append(NewName);
                sb.Append("():");
                sb.Append(isAs3 ? "void " : "Void ");
                sb.Append("$(CSLB){\n\t");
                sb.Append(selText);
                sb.Append("$(EntryPoint)");
                sb.Append("\n}\n$(Boundary)");

                ASGenerator.InsertCode(position, sb.ToString());
            }
            finally
            {
                Sci.EndUndoAction();
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Background search
        /// </summary>
        private void BackgroundRun()
		{
            pathModel.Updating = true;
            try
            {
                if (pathModel.IsVirtual)
                {
                    string ext = Path.GetExtension(pathModel.Path).ToLower();
                    if (ext == ".jar" || ext == ".zip")
                    {
                        pathModel.WasExplored = true;
                        ExtractFilesFromArchive();
                    }

                    // let the context explore packaged libraries
                    else if (pathModel.Owner != null)
                        try
                        {
                            NotifyProgress(String.Format(TextHelper.GetString("Info.Parsing"), 1), 0, 1);
                            pathModel.Owner.ExploreVirtualPath(pathModel);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, TextHelper.GetString("Info.SWCConversionException"));
                        }
                }
                else
                {
                    pathModel.WasExplored = true;
                    bool writeCache = false;
                    string cacheFileName = null;
                    if (UseCache)
                    {
                        cacheFileName = GetCacheFileName(pathModel.Path);
                        if (File.Exists(cacheFileName))
                        {
                            NotifyProgress(TextHelper.GetString("Info.ParsingCache"), 0, 1);
                            ASFileParser.ParseCacheFile(pathModel, cacheFileName, context);
                        }
                        if (stopExploration) return;
                    }
                    else writeCache = true;

                    // explore filesystem (populates foundFiles)
                    ExploreFolder(pathModel.Path, context.GetExplorerMask());
                    if (stopExploration) return;

                    // create models
                    writeCache |= ParseFoundFiles();

                    // write cache file
                    if (UseCache && writeCache && !stopExploration)
                    try
                    {
                        string cacheDir = Path.GetDirectoryName(cacheFileName);
                        if (!Directory.Exists(cacheDir)) Directory.CreateDirectory(cacheDir);
                        else if (File.Exists(cacheFileName)) File.Delete(cacheFileName);

                        if (pathModel.Files.Values.Count > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            foreach (FileModel model in pathModel.Files.Values)
                            {
                                sb.Append("\n#file-cache ").Append(model.FileName).Append('\n');
                                sb.Append(model.GenerateIntrinsic(true));
                            }
                            string src = sb.ToString();
                            FileHelper.WriteFile(cacheFileName, src, Encoding.UTF8);
                        }
                    }
                    catch { }
                }
            }
            finally { pathModel.Updating = false; }
		}
Ejemplo n.º 14
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 ASResult DeclarationLookupResult(ScintillaNet.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.LineFromPosition(Sci.CurrentPos);
                int lookupCol  = Sci.CurrentPos - Sci.PositionFromLine(lookupLine);
                ASContext.Panel.SetLastLookupPosition(ASContext.Context.CurrentFile, lookupLine, lookupCol);
                // open the file
                if (model != ASContext.Context.CurrentModel)
                {
                    // cached files declarations have no line numbers
                    if (model.CachedModel && model.Context != null)
                    {
                        ASFileParser.ParseFile(model);
                        if (inClass != null && !inClass.IsVoid())
                        {
                            inClass = model.GetClassByName(inClass.Name);
                            if (result.Member != null)
                            {
                                result.Member = inClass.Members.Search(result.Member.Name, 0, 0);
                            }
                        }
                        else
                        {
                            result.Member = model.Members.Search(result.Member.Name, 0, 0);
                        }
                    }
                    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);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// AS2/AS3 detection
 /// </summary>
 /// <param name="doc">Document to check</param>
 /// <returns>Detected language</returns>
 private string DetectActionscriptVersion(ITabbedDocument doc)
 {
     ASFileParser parser = new ASFileParser();
     FileModel model = new FileModel(doc.FileName);
     parser.ParseSrc(model, doc.SciControl.Text);
     if (model.Version == 1 && PluginBase.CurrentProject != null) return PluginBase.CurrentProject.Language;
     else if (model.Version > 2) return "as3";
     else if (model.Version > 1) return "as2";
     else if (settingObject.LastASVersion != null) return settingObject.LastASVersion;
     else return "as2";
 }
        public void Execute()
        {
            Sci = PluginBase.MainForm.CurrentDocument.SciControl;
            Sci.BeginUndoAction();
            try
            {
                IASContext context = ASContext.Context;
                Int32      pos     = Sci.CurrentPos;

                string expression = Sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
                expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
                expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });

                cFile = ASContext.Context.CurrentModel;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(cFile, Sci.Text);

                MemberModel current = cFile.Context.CurrentMember;

                string characterClass = ScintillaControl.Configuration.GetLanguage(Sci.ConfigurationLanguage).characterclass.Characters;

                int funcBodyStart = ASGenerator.GetBodyStart(current.LineFrom, current.LineTo, Sci);
                Sci.SetSel(funcBodyStart, Sci.LineEndPosition(current.LineTo));
                string currentMethodBody = Sci.SelText;

                bool isExprInSingleQuotes = (expression.StartsWith("'") && expression.EndsWith("'"));
                bool isExprInDoubleQuotes = (expression.StartsWith("\"") && expression.EndsWith("\""));
                int  stylemask            = (1 << Sci.StyleBits) - 1;
                int  lastPos = -1;
                char prevOrNextChar;
                Sci.Colourise(0, -1);
                while (true)
                {
                    lastPos = currentMethodBody.IndexOf(expression, lastPos + 1);
                    if (lastPos > -1)
                    {
                        if (lastPos > 0)
                        {
                            prevOrNextChar = currentMethodBody[lastPos - 1];
                            if (characterClass.IndexOf(prevOrNextChar) > -1)
                            {
                                continue;
                            }
                        }
                        if (lastPos + expression.Length < currentMethodBody.Length)
                        {
                            prevOrNextChar = currentMethodBody[lastPos + expression.Length];
                            if (characterClass.IndexOf(prevOrNextChar) > -1)
                            {
                                continue;
                            }
                        }

                        int style = Sci.StyleAt(funcBodyStart + lastPos) & stylemask;
                        if (ASComplete.IsCommentStyle(style))
                        {
                            continue;
                        }
                        else if ((isExprInDoubleQuotes && currentMethodBody[lastPos] == '"' && currentMethodBody[lastPos + expression.Length - 1] == '"') ||
                                 (isExprInSingleQuotes && currentMethodBody[lastPos] == '\'' && currentMethodBody[lastPos + expression.Length - 1] == '\''))
                        {
                        }
                        else if (!ASComplete.IsTextStyle(style))
                        {
                            continue;
                        }

                        Sci.SetSel(funcBodyStart + lastPos, funcBodyStart + lastPos + expression.Length);
                        Sci.ReplaceSel(NewName);
                        currentMethodBody = currentMethodBody.Substring(0, lastPos) + NewName + currentMethodBody.Substring(lastPos + expression.Length);
                        lastPos          += NewName.Length;
                    }
                    else
                    {
                        break;
                    }
                }

                Sci.CurrentPos = funcBodyStart;
                Sci.SetSel(Sci.CurrentPos, Sci.CurrentPos);

                string snippet = "var " + NewName + ":$(EntryPoint) = " + expression + ";\n$(Boundary)";
                SnippetHelper.InsertSnippetText(Sci, Sci.CurrentPos, snippet);
            }
            finally
            {
                Sci.EndUndoAction();
            }
        }