Example #1
0
        /// <summary>
        /// Open a file in the classpath (physical or virtual) or a specific context
        /// </summary>
        public FileModel OpenFile(string filename, IASContext context)
        {
            if (context == null || context.Classpath == null)
            {
                return(null);
            }
            FileModel model = null;

            foreach (PathModel aPath in context.Classpath)
            {
                if (aPath.HasFile(filename))
                {
                    model = aPath.GetFile(filename);
                    break;
                }
            }
            if (model != null)
            {
                if (File.Exists(model.FileName))
                {
                    ASContext.MainForm.OpenEditableDocument(model.FileName, false);
                }
                else
                {
                    ASComplete.OpenVirtualFile(model);
                    model = ASContext.Context.CurrentModel;
                }
            }
            return(model);
        }
Example #2
0
        void InitializeClasspaths()
        {
            IASContext context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);

            if (context == null)
            {
                return;
            }
            string projectDir = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath);

            foreach (PathModel classpath in context.Classpath)
            {
                if (classpath.IsVirtual)
                {
                    continue;
                }
                string path     = classpath.Path;
                string fullPath = path;
                if (!Path.IsPathRooted(path))
                {
                    fullPath = Path.GetFullPath(path);
                }
                if (fullPath.StartsWith(projectDir))
                {
                    projectClasspaths.AddRange(GetClasspaths(path, projectDir));
                }
                else
                {
                    externalClasspaths.AddRange(GetClasspaths(path));
                }
            }
        }
 private FileModel GetFileModel(string filename)
 {
     // Going to try just doing this operation on our background thread - if there
     // are any strange exceptions, this should be synchronized
     IASContext ctx = context;
     return (ctx != null) ? ctx.GetFileModel(filename) : null;
 }
        /// <summary>
        /// Gets all files related to the project
        /// </summary>
        private static List <String> GetAllProjectRelatedFiles(IProject project)
        {
            List <String> files  = new List <String>();
            string        filter = GetSearchPatternFromLang(project.Language.ToLower());

            if (string.IsNullOrEmpty(filter))
            {
                return(files);
            }
            IASContext context = ASContext.GetLanguageContext(project.Language);

            if (context == null)
            {
                return(files);
            }
            foreach (PathModel pathModel in context.Classpath)
            {
                string path     = pathModel.Path;
                String absolute = project.GetAbsolutePath(path);
                if (Directory.Exists(path))
                {
                    files.AddRange(Directory.GetFiles(absolute, filter, SearchOption.AllDirectories));
                }
            }
            // If no source paths are defined, get files directly from project path
            if (project.SourcePaths.Length == 0)
            {
                String projRoot = Path.GetDirectoryName(project.ProjectPath);
                files.AddRange(Directory.GetFiles(projRoot, filter, SearchOption.AllDirectories));
            }
            return(files);
        }
Example #5
0
        /// <summary>
        /// Retrieve a PathModel from the cache or create a new one
        /// </summary>
        /// <param name="path"></param>
        /// <param name="context">Associated language context</param>
        /// <returns></returns>
        static public PathModel GetModel(string path, IASContext context)
        {
            if (context == null || context.Settings == null)
            {
                return(null);
            }

            string    modelName = context.Settings.LanguageId + "|" + path.ToUpper();
            PathModel aPath;

            if (pathes.ContainsKey(modelName))
            {
                aPath = pathes[modelName];
                if (aPath.IsTemporaryPath || !aPath.IsValid || aPath.FilesCount == 0)
                {
                    pathes[modelName] = aPath = new PathModel(path, context);
                }
                else
                {
                    aPath.Touch();
                }
            }
            else
            {
                pathes[modelName] = aPath = new PathModel(path, context);
            }
            return(aPath);
        }
Example #6
0
        /// <summary>
        /// Checks if files is related to the project
        /// TODO support SWCs -> refactor test as IProject method
        /// </summary>
        public static Boolean IsProjectRelatedFile(IProject project, String file)
        {
            if (project == null)
            {
                return(false);
            }
            IASContext context = ASContext.GetLanguageContext(project.Language);

            if (context == null)
            {
                return(false);
            }
            foreach (PathModel pathModel in context.Classpath)
            {
                string absolute = project.GetAbsolutePath(pathModel.Path);
                if (file.StartsWith(absolute))
                {
                    return(true);
                }
            }
            // If no source paths are defined, is it under the project?
            if (project.SourcePaths.Length == 0)
            {
                String projRoot = Path.GetDirectoryName(project.ProjectPath);
                if (file.StartsWith(projRoot))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #7
0
        static void SetFeatures(IASContext mock, IASContext context)
        {
            mock.Settings.LanguageId.Returns(context.Settings.LanguageId);
            mock.Features.Returns(context.Features);
            mock.CurrentModel.Returns(context.CurrentModel);
            var visibleExternalElements = context.GetVisibleExternalElements();

            mock.GetVisibleExternalElements().Returns(visibleExternalElements);
            mock.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src));
            });
            mock.IsImported(null, Arg.Any <int>()).ReturnsForAnyArgs(it =>
            {
                var member = it.ArgAt <MemberModel>(0);
                return(member != null && context.IsImported(member, it.ArgAt <int>(1)));
            });
            mock.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.IsFileValid.Returns(context.IsFileValid);
            mock.GetDefaultValue(null).ReturnsForAnyArgs(it => context.GetDefaultValue(it.ArgAt <string>(0)));
            mock.DecomposeTypes(null).ReturnsForAnyArgs(it => context.DecomposeTypes(it.ArgAt <IEnumerable <string> >(0) ?? new string[0]));
            mock.Classpath.Returns(context.Classpath);
            mock.CreateFileModel(null).ReturnsForAnyArgs(it => context.CreateFileModel(it.ArgAt <string>(0)));
            var allProjectClasses = context.GetAllProjectClasses();

            mock.GetAllProjectClasses().Returns(allProjectClasses);
        }
Example #8
0
        public static void SetHaxeFeatures(this IASContext mock)
        {
            var currentModel = new FileModel {
                Context = mock, Version = 4, haXe = true
            };
            var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            BuildClassPath(context);
            context.CurrentModel = currentModel;
            mock.Settings.LanguageId.Returns(context.Settings.LanguageId);
            mock.Features.Returns(context.Features);
            mock.CurrentModel.Returns(currentModel);
            var visibleExternalElements = context.GetVisibleExternalElements();

            mock.GetVisibleExternalElements().Returns(visibleExternalElements);
            mock.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src));
            });
            mock.IsImported(null, Arg.Any <int>()).ReturnsForAnyArgs(it =>
            {
                var member = it.ArgAt <MemberModel>(0);
                return(member != null && context.IsImported(member, it.ArgAt <int>(1)));
            });
            mock.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.IsFileValid.Returns(context.IsFileValid);
        }
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context   = context;
     this.pathModel = pathModel;
     hashName       = pathModel.Path;
     foundFiles     = new List <string>();
     explored       = new List <string>();
 }
Example #10
0
 private void DetectContext()
 {
     current = ASContext.Context;
     if (PluginBase.CurrentProject != null)
     {
         current = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);
     }
 }
Example #11
0
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context = context;
     this.pathModel = pathModel;
     hashName = pathModel.Path;
     foundFiles = new List<string>();
     explored = new List<string>();
 }
Example #12
0
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context        = context;
     this.pathModel      = pathModel;
     hashName            = pathModel.Path;
     hiddenPackagePrefix = context.Features.hiddenPackagePrefix;
     foundFiles          = new List <string>();
     explored            = new List <string>();
 }
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context = context;
     this.pathModel = pathModel;
     hashName = pathModel.Path;
     hiddenPackagePrefix = context.Features.hiddenPackagePrefix;
     foundFiles = new List<string>();
     explored = new List<string>();
 }
Example #14
0
        static public void ParseCacheFile(PathModel inPath, string file, IASContext inContext)
		{
            lock (typeof(ASFileParser))
            {
                cachedPath = inPath;
                ParseFile(file, inContext);
                cachedPath = null;
            }
		}
Example #15
0
        public void Execute()
        {
            Sci = PluginBase.MainForm.CurrentDocument.SciControl;

            IASContext context = ASContext.Context;
            Int32      pos     = Sci.CurrentPos;

            ASGenerator.GenerateDelegateMethods(Sci, result.Member, selectedMembers, result.Type, result.inClass);
        }
Example #16
0
        public static void SetHaxeFeatures(this IASContext mock)
        {
            var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            BuildClassPath(context);
            context.CurrentModel = new FileModel {
                Context = mock, Version = 4, haXe = true
            };
            SetFeatures(mock, context);
        }
Example #17
0
        public static void SetAs3Features(this IASContext mock)
        {
            var context = new AS3Context.Context(new AS3Context.AS3Settings());

            BuildClassPath(context);
            context.CurrentModel = new FileModel {
                Context = mock, Version = 3
            };
            SetFeatures(mock, context);
        }
Example #18
0
        /// <summary>
        /// The actual process implementation
        /// </summary>
        protected override void ExecutionImplementation()
        {
            IASContext         context = ASContext.Context;
            ScintillaControl   sci     = PluginBase.MainForm.CurrentDocument.SciControl;
            Int32              pos     = sci.CurrentPos;
            List <MemberModel> imports = new List <MemberModel>(context.CurrentModel.Imports.Count);

            imports.AddRange(context.CurrentModel.Imports.Items);
            ImportsComparerLine comparerLine = new ImportsComparerLine();

            imports.Sort(comparerLine);
            sci.SetSel(sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineFrom), sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineTo));
            String publicClassText  = sci.SelText;
            String privateClassText = "";

            if (context.CurrentModel.Classes.Count > 1)
            {
                sci.SetSel(pos, pos);
                sci.SetSel(sci.PositionFromLine(context.CurrentModel.Classes[1].LineFrom), sci.PositionFromLine(sci.LineCount));
                privateClassText = sci.SelText;
            }
            if (imports.Count > 1 || (imports.Count > 0 && this.TruncateImports))
            {
                sci.BeginUndoAction();
                foreach (MemberModel import in imports)
                {
                    sci.GotoLine(import.LineFrom);
                    this.ImportIndents.Add(new KeyValuePair <MemberModel, Int32>(import, sci.GetLineIndentation(import.LineFrom)));
                    sci.LineDelete();
                }
                if (this.TruncateImports)
                {
                    for (Int32 j = 0; j < imports.Count; j++)
                    {
                        MemberModel import = imports[j];
                        String[]    parts  = import.Type.Split('.');
                        if (parts.Length > 0 && parts[parts.Length - 1] != "*")
                        {
                            parts[parts.Length - 1] = "*";
                        }
                        import.Type = String.Join(".", parts);
                    }
                }
                imports.Reverse();
                Imports separatedImports = this.SeparateImports(imports, context.CurrentModel.PrivateSectionIndex);
                this.InsertImports(separatedImports.PackageImports, publicClassText, sci, separatedImports.PackageImportsIndent);
                if (context.CurrentModel.Classes.Count > 1)
                {
                    this.InsertImports(separatedImports.PrivateImports, privateClassText, sci, separatedImports.PrivateImportsIndent);
                }
                sci.SetSel(pos, pos);
                sci.EndUndoAction();
            }
            this.FireOnRefactorComplete();
        }
Example #19
0
 public static void BuildClassPath(this IASContext context)
 {
     if (context is AS3Context.Context)
     {
         BuildClassPath((AS3Context.Context)context);
     }
     else if (context is HaXeContext.Context)
     {
         BuildClassPath((HaXeContext.Context)context);
     }
 }
 public PathExplorer(IASContext context, PathModel pathModel)
 {
     this.context = context;
     this.pathModel = pathModel;
     foundFiles = new List<string>();
     explored = new List<string>();
     if (context.Settings.LanguageId == "AS2")
     {
         explored.Add(Path.Combine(pathModel.Path, "aso"));
         explored.Add(Path.Combine(pathModel.Path, "FP7"));
         explored.Add(Path.Combine(pathModel.Path, "FP8"));
         explored.Add(Path.Combine(pathModel.Path, "FP9"));
     }
 }
Example #21
0
    public static void Execute()
    {
        if (Globals.SciControl == null)
        {
            return;
        }
        ScintillaControl sci = Globals.SciControl;

        //Project project = (Project) PluginBase.CurrentProject;
        //if (project == null) return;

        MainForm mainForm = (MainForm)Globals.MainForm;

        ITabbedDocument document = mainForm.CurrentDocument;

        String    dir     = Path.GetDirectoryName(document.FileName);
        Hashtable details = ASComplete.ResolveElement(sci, null);

        IASContext context = ASContext.Context;
        ClassModel cClass  = context.CurrentClass;
        string     package = context.CurrentModel.Package;

        sci.BeginUndoAction();

        if (sci.SelText == "")
        {
            sci.SelectionStart = sci.PositionFromLine(cClass.LineFrom);
            sci.SelectionEnd   = sci.PositionFromLine(cClass.LineTo + 1);
        }

        String content = Regex.Replace(
            sci.SelText,
            @"^",
            "\t",
            RegexOptions.Multiline);

        String contents = "package " + package + " {\n" + content + "\n}";

        TraceManager.Add(contents);
        //TraceManager.Add(cClass.LineTo.ToString());

        Encoding encoding = sci.Encoding;
        String   file     = dir + "\\" + cClass.Name + ".as";

        FileHelper.WriteFile(file, contents, encoding);

        sci.Clear();
        sci.EndUndoAction();
    }
Example #22
0
        /// <summary>
        /// Generate meta tags
        /// </summary>
        private void MakeItLive()
        {
            ScintillaNet.ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;
            if (sci == null)
            {
                return;
            }

            IASContext context = ASCompletion.Context.ASContext.Context;

            if (context.CurrentClass == null || context.CurrentClass.IsVoid() || context.CurrentClass.LineFrom == 0)
            {
                return;
            }

            // make member live
            int         originalPos = sci.CurrentPos;
            int         pos;
            int         line;
            string      indent;
            MemberModel member = context.CurrentMember;
            FlagType    mask   = FlagType.Function | FlagType.Dynamic;

            if (member != null && (member.Flags & mask) == mask)
            {
                line   = context.CurrentMember.LineFrom;
                indent = LineIndentPosition(sci, line);
                pos    = sci.PositionFromLine(line) + indent.Length;
                string insert = "[LiveCodeUpdateListener(method=\"" + member.Name + "\")]\n" + indent;
                sci.SetSel(pos, pos);
                sci.ReplaceSel(insert);
                originalPos += insert.Length;
            }

            // make class live
            if (!Regex.IsMatch(sci.Text, "\\[Live\\]"))
            {
                line   = context.CurrentClass.LineFrom;
                indent = LineIndentPosition(sci, line);
                pos    = sci.PositionFromLine(line) + indent.Length;
                string insert = "[Live]\n" + indent;
                sci.SetSel(pos, pos);
                sci.ReplaceSel(insert);
                originalPos += insert.Length;
            }

            sci.SetSel(originalPos, originalPos);
        }
Example #23
0
        private void CreateItemsList()
        {
            projectTypes.Clear();
            openedTypes.Clear();
            dictionary.Clear();

            IASContext context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);

            if (context == null)
            {
                return;
            }
            foreach (PathModel path in context.Classpath)
            {
                path.ForeachFile(FileModelDelegate);
            }
        }
Example #24
0
        public PathModel(string path, IASContext context)
        {
            Owner = context;
            Path = path.TrimEnd(new char[] { '\\', '/' });

            files = new Dictionary<string, FileModel>();
            LastAccess = DateTime.Now;

            if (Owner != null)
            {
                if (Directory.Exists(Path)) IsValid = Path.Length > 3 /*no root drive*/;
                else if (System.IO.Path.GetExtension(path).Length > 1)
                {
                    IsValid = File.Exists(Path);
                    IsVirtual = true;
                }
            }
        }
Example #25
0
        private void baseBrowse_Click(object sender, EventArgs e)
        {
            ClassBrowser browser = new ClassBrowser();
            IASContext   context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);

            try
            {
                browser.ClassList = context.GetAllProjectClasses();
            }
            catch { }
            browser.ExcludeFlag = FlagType.Interface;
            browser.IncludeFlag = FlagType.Class;
            if (browser.ShowDialog(this) == DialogResult.OK)
            {
                this.baseBox.Text = browser.SelectedClass;
            }
            this.okButton.Focus();
        }
Example #26
0
        /// <summary>
        /// Retrieve a PathModel from the cache or create a new one
        /// </summary>
        /// <param name="path"></param>
        /// <param name="context">Associated language context</param>
        /// <returns></returns>
        static public PathModel GetModel(string path, IASContext context)
        {
            if (context == null || context.Settings == null) 
                return null;

            string modelName = context.Settings.LanguageId + "|" + path.ToUpper();
            PathModel aPath;
            if (pathes.ContainsKey(modelName))
            {
                aPath = pathes[modelName] as PathModel;
                if (aPath.IsTemporaryPath || !aPath.IsValid || aPath.FilesCount == 0)
                {
                    pathes[modelName] = aPath = new PathModel(path, context);
                }
                else aPath.Touch();
            }
            else pathes[modelName] = aPath = new PathModel(path, context);
            return aPath;
        }
        public static void SetAS3Features(this IASContext context)
        {
            var currentModel = new FileModel {
                Context = context, Version = 3
            };
            var asContext = new AS3Context.Context(new AS3Context.AS3Settings());

            BuildClassPath(asContext);
            asContext.CurrentModel = currentModel;
            context.Features.Returns(asContext.Features);
            context.CurrentModel.Returns(currentModel);
            var visibleExternalElements = asContext.GetVisibleExternalElements();

            context.GetVisibleExternalElements().Returns(x => visibleExternalElements);
            context.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : asContext.GetCodeModel(src));
            });
            context.ResolveType(null, null).ReturnsForAnyArgs(x => asContext.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
        }
Example #28
0
        public PathModel(string path, IASContext context)
        {
            Owner = context;
            Path  = path.TrimEnd(new char[] { '\\', '/' });

            files      = new Dictionary <string, FileModel>();
            LastAccess = DateTime.Now;

            if (Owner != null)
            {
                if (Directory.Exists(Path))
                {
                    IsValid = Path.Length > 3 /*no root drive*/;
                }
                else if (System.IO.Path.GetExtension(path).Length > 1)
                {
                    IsValid   = File.Exists(Path);
                    IsVirtual = true;
                }
            }
        }
        public static void SetHaxeFeatures(this IASContext context)
        {
            var currentModel = new FileModel {
                Context = context, Version = 4, haXe = true
            };
            var haxeContext = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            BuildClassPath(haxeContext);
            haxeContext.CurrentModel = currentModel;
            context.Features.Returns(haxeContext.Features);
            context.CurrentModel.Returns(currentModel);
            var visibleExternalElements = haxeContext.GetVisibleExternalElements();

            context.GetVisibleExternalElements().Returns(x => visibleExternalElements);
            context.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : haxeContext.GetCodeModel(src));
            });
            context.ResolveType(null, null).ReturnsForAnyArgs(x => haxeContext.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
        }
Example #30
0
        static void SetFeatures(IASContext mock, IASContext context)
        {
            mock.Settings.Returns(context.Settings);
            mock.Features.Returns(context.Features);
            mock.CurrentModel.Returns(context.CurrentModel);
            var visibleExternalElements = context.GetVisibleExternalElements();

            mock.GetVisibleExternalElements().Returns(visibleExternalElements);
            mock.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src));
            });
            mock.IsImported(null, Arg.Any <int>()).ReturnsForAnyArgs(it =>
            {
                var member = it.ArgAt <MemberModel>(0) ?? ClassModel.VoidClass;
                return(context.IsImported(member, it.ArgAt <int>(1)));
            });
            mock.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.ResolveToken(null, null).ReturnsForAnyArgs(x => context.ResolveToken(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.ResolveDotContext(null, null, false).ReturnsForAnyArgs(it =>
            {
                var expr = it.ArgAt <ASExpr>(1);
                if (expr == null)
                {
                    return(null);
                }
                return(context.ResolveDotContext(it.ArgAt <ScintillaControl>(0), expr, it.ArgAt <bool>(2)));
            });
            mock.IsFileValid.Returns(context.IsFileValid);
            mock.GetDefaultValue(null).ReturnsForAnyArgs(it => context.GetDefaultValue(it.ArgAt <string>(0)));
            mock.DecomposeTypes(null).ReturnsForAnyArgs(it => context.DecomposeTypes(it.ArgAt <IEnumerable <string> >(0) ?? new string[0]));
            mock.Classpath.Returns(context.Classpath);
            mock.CreateFileModel(null).ReturnsForAnyArgs(it => context.CreateFileModel(it.ArgAt <string>(0)));
            var allProjectClasses = context.GetAllProjectClasses();

            mock.GetAllProjectClasses().Returns(allProjectClasses);
            mock.CodeGenerator.Returns(context.CodeGenerator);
        }
Example #31
0
        /// <summary>
        /// Added interface
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void implementBrowse_Click(object sender, EventArgs e)
        {
            ClassBrowser browser = new ClassBrowser();
            MemberList   known   = null;

            browser.IncludeFlag = FlagType.Interface;
            IASContext context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);

            try
            {
                known = context.GetAllProjectClasses();
                known.Merge(ASContext.Context.GetVisibleExternalElements(true));
            }
            catch (Exception error)
            {
                Debug.WriteLine(error.StackTrace);
            }

            browser.ClassList = known;

            if (browser.ShowDialog(this) == DialogResult.OK)
            {
                if (browser.SelectedClass != null)
                {
                    foreach (string item in this.implementList.Items)
                    {
                        if (item == browser.SelectedClass)
                        {
                            return;
                        }
                    }
                    this.implementList.Items.Add(browser.SelectedClass);
                }
            }
            this.implementRemove.Enabled     = this.implementList.Items.Count > 0;
            this.implementList.SelectedIndex = this.implementList.Items.Count - 1;
            this.superCheck.Enabled          = this.implementList.Items.Count > 0;
            ValidateClass();
        }
Example #32
0
 public RegisteredContext(IASContext context, string language, string inlinedLanguage)
 {
     Context = context;
     Language = language.ToLower();
     Inlined = (inlinedLanguage != null) ? inlinedLanguage.ToLower() : null;
     //TraceManager.Add("Register context: " + language + " (" + inlinedLanguage + ")");
 }
Example #33
0
 string Generate(string sourceText, GeneratorJobType job, IASContext context)
 {
     sci.Text = sourceText;
     SnippetHelper.PostProcessSnippets(sci, 0);
     var currentModel = ASContext.Context.CurrentModel;
     new ASFileParser().ParseSrc(currentModel, sci.Text);
     var currentClass = currentModel.Classes[0];
     ASContext.Context.CurrentClass.Returns(currentClass);
     var currentMember = currentClass.Members[0];
     ASContext.Context.CurrentMember.Returns(currentMember);
     ASContext.Context.GetVisibleExternalElements().Returns(x => context.GetVisibleExternalElements());
     ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x =>
     {
         var src = x[0] as string;
         return string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src);
     });
     ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt<string>(0), x.ArgAt<FileModel>(1)));
     ASGenerator.contextToken = sci.GetWordFromPosition(sci.CurrentPos);
     ASGenerator.GenerateJob(job, currentMember, ASContext.Context.CurrentClass, null, null);
     return sci.Text;
 }
Example #34
0
 private string ProcessFileTemplate(string args)
 {
     Int32 eolMode = (Int32)MainForm.Settings.EOLMode;
     String lineBreak = LineEndDetector.GetNewLineMarker(eolMode);
     ClassModel cmodel;
     List<String> imports = new List<string>();
     string extends = "";
     string implements = "";
     string access = "";
     string inheritedMethods = "";
     string paramString = "";
     string superConstructor = "";
     string classMetadata = "";
     int index;
     // resolve imports
     if (lastFileOptions.interfaces != null && lastFileOptions.interfaces.Count > 0)
     {
         bool isHaxe2 = PluginBase.CurrentSDK != null && PluginBase.CurrentSDK.Name.ToLower().Contains("haxe 2");
         implements = " implements ";
         string[] _implements;
         index = 0;
         foreach (string item in lastFileOptions.interfaces)
         {
             if (item.Split('.').Length > 1) imports.Add(item);
             _implements = item.Split('.');
             implements += (index > 0 ? (isHaxe2 ? ", implements " : ", ") : "") + _implements[_implements.Length - 1];
             if (lastFileOptions.createInheritedMethods)
             {
                 processOnSwitch = lastFileFromTemplate; 
                 // let ASCompletion generate the implementations when file is opened
             }
             index++;
         }
     }
     if (lastFileOptions.superClass != "")
     {
         String super = lastFileOptions.superClass;
         if (lastFileOptions.superClass.Split('.').Length > 1) imports.Add(super);
         string[] _extends = super.Split('.');
         extends = " extends " + _extends[_extends.Length - 1];
         processContext = ASContext.GetLanguageContext(lastFileOptions.Language);
         if (lastFileOptions.createConstructor && processContext != null && constructorArgs == null)
         {
             cmodel = processContext.GetModel(super.LastIndexOf('.') < 0 ? "" : super.Substring(0, super.LastIndexOf('.')), _extends[_extends.Length - 1], "");
             if (!cmodel.IsVoid())
             {
                 foreach (MemberModel member in cmodel.Members)
                 {
                     if (member.Name == cmodel.Constructor)
                     {
                         paramString = member.ParametersString();
                         AddImports(imports, member, cmodel);
                         superConstructor = "super(";
                         index = 0;
                         if (member.Parameters != null)
                         foreach (MemberModel param in member.Parameters)
                         {
                             if (param.Name.StartsWith('.')) break;
                             var pname = TemplateUtils.GetParamName(param);
                             superConstructor += (index > 0 ? ", " : "") + pname;
                             index++;
                         }
                         superConstructor += ");\n" + (lastFileOptions.Language == "as3" ? "\t\t\t" : "\t\t");
                         break;
                     }
                 }
             }
         }
         processContext = null;
     }
     if (constructorArgs != null)
     {
         paramString = constructorArgs;
         foreach (String type in constructorArgTypes)
         {
             if (!imports.Contains(type))
             {
                 imports.Add(type);
             }
         }
     }
     if (lastFileOptions.Language == "as3")
     {
         access = lastFileOptions.isPublic ? "public " : "internal ";
         access += lastFileOptions.isDynamic ? "dynamic " : "";
         access += lastFileOptions.isFinal ? "final " : "";
     }
     else if (lastFileOptions.Language == "haxe")
     {
         access = lastFileOptions.isPublic ? "public " : "private ";
         access += lastFileOptions.isDynamic ? "dynamic " : "";
         if (lastFileOptions.isFinal) classMetadata += "@:final\n";
     }
     else
     {
         access = lastFileOptions.isDynamic ? "dynamic " : "";
     }
     string importsSrc = "";
     string prevImport = null;
     imports.Sort();
     foreach (string import in imports)
     {
         if (prevImport != import)
         {
             prevImport = import;
             if (import.LastIndexOf('.') == -1) continue;
             if (import.Substring(0, import.LastIndexOf('.')) == lastFileOptions.Package) continue;
             importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + "import " + import + ";" + lineBreak;
         }
     }
     if (importsSrc.Length > 0)
     {
         importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + lineBreak;
     }
     args = args.Replace("$(Import)", importsSrc);
     args = args.Replace("$(Extends)", extends);
     args = args.Replace("$(Implements)", implements);
     args = args.Replace("$(Access)", access);
     args = args.Replace("$(InheritedMethods)", inheritedMethods);
     args = args.Replace("$(ConstructorArguments)", paramString);
     args = args.Replace("$(Super)", superConstructor);
     args = args.Replace("$(ClassMetadata)", classMetadata);
     return args;
 }
Example #35
0
		static public FileModel ParseFile(string file, IASContext inContext)
		{
			FileModel fileModel = new FileModel(file);
            fileModel.Context = inContext;
			return ParseFile(fileModel);
		}
Example #36
0
        /// <summary>
        /// Create virtual FileModel objects from Abc bytecode
        /// </summary>
        /// <param name="abcs"></param>
        /// <param name="path"></param>
        /// <param name="context"></param>
        public static void Convert(ContentParser parser, PathModel path, IASContext context)
        {
            inSWF = Path.GetExtension(path.Path).ToLower() == ".swf";

            // extract documentation
            ParseDocumentation(parser);

            // extract models
            Dictionary<string, FileModel> models = new Dictionary<string, FileModel>();
            FileModel privateClasses = new FileModel(Path.Combine(path.Path, "__Private.as"));
            privateClasses.Version = 3;
            privateClasses.Package = "private";
            genericTypes = new Dictionary<string, FileModel>();
            imports = new Dictionary<string, string>();
            conflicts = new Dictionary<string, string>();

            foreach (Abc abc in parser.Abcs)
            {
                // types
                foreach (Traits trait in abc.classes)
                {
                    Traits instance = trait.itraits;
                    if (instance == null)
                        continue;
                    imports.Clear();
                    conflicts.Clear();

                    FileModel model = new FileModel("");
                    model.Context = context;
                    model.Package = reSafeChars.Replace(instance.name.uri, "_");
                    model.HasPackage = true;
                    string filename = reSafeChars.Replace(trait.name.ToString(), "_").TrimEnd('$');
                    filename = Path.Combine(model.Package.Replace('.', Path.DirectorySeparatorChar), filename);
                    model.FileName = Path.Combine(path.Path, filename);
                    model.Version = 3;

                    ClassModel type = new ClassModel();
                    model.Classes = new List<ClassModel>();
                    model.Classes.Add(type);

                    type.InFile = model;
                    type.Type = instance.name.ToTypeString();
                    type.Name = instance.name.localName;
                    type.Flags = FlagType.Class;
                    conflicts.Add(type.Name, type.QualifiedName);

                    if (instance.flags == TraitMember.Function)
                        type.Flags |= FlagType.Interface;

                    thisDocs = GetDocs(model.Package);
                    if (thisDocs != null)
                    {
                        docPath = (model.Package.Length > 0 ? model.Package + ":" : "globalClassifier:") + type.Name;
                        if (thisDocs.ContainsKey(docPath))
                        {
                            ASDocItem doc = thisDocs[docPath];
                            applyASDoc(doc, type);
                            if (doc.Meta != null) model.MetaDatas = doc.Meta;
                        }
                        if (model.Package.Length == 0) docPath = type.Name;
                    }

                    if (instance.baseName.uri == model.Package)
                        type.ExtendsType = ImportType(instance.baseName.localName);
                    else type.ExtendsType = ImportType(instance.baseName);

                    if (instance.interfaces != null && instance.interfaces.Length > 0)
                    {
                        type.Implements = new List<string>();
                        foreach (QName name in instance.interfaces)
                            type.Implements.Add(ImportType(name));
                    }

                    if (model.Package == "private")
                    {
                        model.Package = "";
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                    }
                    else if (model.Package == "__AS3__.vec")
                    {
                        model.Package = "";
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                        string genType = type.Name;
                        if (type.Name.IndexOf("$") > 0)
                        {
                            string[] itype = type.Name.Split('$');
                            genType = itype[0];
                            type.Name = itype[0] + "$" + itype[1];
                            type.IndexType = itype[1];
                        }
                        if (genericTypes.ContainsKey(genType))
                        {
                            model.Classes.Clear();
                            type.InFile = genericTypes[genType];
                            genericTypes[genType].Classes.Add(type);
                        }
                        else genericTypes[genType] = model;
                    }
                    else if (type.Name.StartsWith("_"))
                    {
                        type.Access = Visibility.Private;
                        type.Namespace = "private";
                    }
                    else
                    {
                        type.Access = Visibility.Public;
                        type.Namespace = "public";
                    }

                    type.Members = GetMembers(trait.members, FlagType.Static, instance.name);
                    type.Members.Add(GetMembers(instance.members, FlagType.Dynamic, instance.name));

                    if ((type.Flags & FlagType.Interface) > 0)
                    {
                        // TODO properly support interface multiple inheritance
                        type.ExtendsType = null;
                        if (type.Implements != null && type.Implements.Count > 0)
                        {
                            type.ExtendsType = type.Implements[0];
                            type.Implements.RemoveAt(0);
                            if (type.Implements.Count == 0) type.Implements = null;
                        }

                        foreach (MemberModel member in type.Members)
                        {
                            member.Access = Visibility.Public;
                            member.Namespace = "";
                        }
                    }

                    // constructor
                    if (instance.init != null && (type.Flags & FlagType.Interface) == 0)
                    {
                        List<MemberInfo> temp = new List<MemberInfo>(new MemberInfo[] { instance.init });
                        MemberList result = GetMembers(temp, 0, instance.name);
                        if (result.Count > 0)
                        {
                            MemberModel ctor = result[0];
                            ctor.Flags |= FlagType.Constructor;
                            ctor.Access = Visibility.Public;
                            ctor.Type = type.Type;
                            ctor.Namespace = "public";
                            type.Members.Merge(result);
                            type.Constructor = ctor.Name;
                        }
                        result = null;
                        temp = null;
                    }
                    else type.Constructor = type.Name;

                    if (type.Access == Visibility.Private)
                    {
                        model = privateClasses;
                        type.InFile = model;
                    }

                    if (model.Classes.Count > 0 || model.Members.Count > 0)
                    {
                        AddImports(model, imports);
                        models[model.FileName] = model;
                    }
                }

                // packages
                if (abc.scripts == null)
                    continue;
                foreach (Traits trait in abc.scripts)
                {
                    FileModel model = null;
                    foreach (MemberInfo info in trait.members)
                    {
                        if (info.kind == TraitMember.Class)
                            continue;

                        MemberModel member = GetMember(info, 0);
                        if (member == null) continue;

                        if (model == null || model.Package != info.name.uri)
                        {
                            AddImports(model, imports);

                            string package = info.name.uri ?? "";
                            string filename = package.Length > 0 ? "package.as" : "toplevel.as";
                            filename = Path.Combine(package.Replace('.', Path.DirectorySeparatorChar), filename);
                            filename = Path.Combine(path.Path, filename);
                            if (models.ContainsKey(filename))
                                model = models[filename];
                            else
                            {
                                model = new FileModel("");
                                model.Context = context;
                                model.Package = package;
                                model.HasPackage = true;
                                model.FileName = filename;
                                model.Version = 3;
                                models[filename] = model;
                            }
                        }

                        thisDocs = GetDocs(model.Package);
                        if (thisDocs != null)
                        {
                            docPath = "globalOperation:" + (model.Package.Length > 0 ? model.Package + ":" : "")
                                + member.Name;
                            if (member.Access == Visibility.Public && !String.IsNullOrEmpty(member.Namespace)
                                && member.Namespace != "public")
                                docPath += member.Namespace + ":";
                            if ((member.Flags & FlagType.Setter) > 0) docPath += ":set";
                            else if ((member.Flags & FlagType.Getter) > 0) docPath += ":get";

                            if (thisDocs.ContainsKey(docPath)) applyASDoc(thisDocs[docPath], member);
                        }

                        member.InFile = model;
                        member.IsPackageLevel = true;
                        model.Members.Add(member);
                    }

                    AddImports(model, imports);
                }
            }

            if (privateClasses.Classes.Count > 0) models[privateClasses.FileName] = privateClasses;

            // some SWCs need manual fixes
            CustomFixes(path.Path, models);

            // fake SWC (like 'playerglobal_rb.swc', only provides documentation)
            if (models.Keys.Count == 1)
            {
                foreach (FileModel model in models.Values)
                    if (model.GetPublicClass().QualifiedName == "Empty")
                    {
                        models.Clear();
                        break;
                    }
            }

            path.SetFiles(models);
        }
Example #37
0
 string Generate(string sourceText, string[] autoRemove, IASContext context)
 {
     sci.Text = sourceText;
     SnippetHelper.PostProcessSnippets(sci, 0);
     ASContext.CommonSettings.EventListenersAutoRemove = autoRemove;
     var currentModel = ASContext.Context.CurrentModel;
     new ASFileParser().ParseSrc(currentModel, sci.Text);
     var currentClass = currentModel.Classes[0];
     ASContext.Context.CurrentClass.Returns(currentClass);
     var currentMember = currentClass.Members[0];
     ASContext.Context.CurrentMember.Returns(currentMember);
     ASContext.Context.GetVisibleExternalElements().Returns(x => context.GetVisibleExternalElements());
     ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x =>
     {
         var src = x[0] as string;
         return string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src);
     });
     var eventModel = new ClassModel { Name = "Event", Type = "flash.events.Event" };
     ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(x => eventModel);
     ASGenerator.contextToken = sci.GetWordFromPosition(sci.CurrentPos);
     var re = string.Format(ASGenerator.patternEvent, ASGenerator.contextToken);
     var m = Regex.Match(sci.GetLine(sci.CurrentLine), re, RegexOptions.IgnoreCase);
     ASGenerator.contextMatch = m;
     ASGenerator.contextParam = ASGenerator.CheckEventType(m.Groups["event"].Value);
     ASGenerator.GenerateJob(GeneratorJobType.ComplexEvent, currentMember, ASContext.Context.CurrentClass, null, null);
     return sci.Text;
 }
Example #38
0
 string Generate(string sourceText, IASContext context)
 {
     sci.Text = sourceText;
     SnippetHelper.PostProcessSnippets(sci, 0);
     var currentModel = ASContext.Context.CurrentModel;
     new ASFileParser().ParseSrc(currentModel, sci.Text);
     var currentClass = currentModel.Classes[0];
     ASContext.Context.CurrentClass.Returns(currentClass);
     ASContext.Context.CurrentMember.Returns(currentClass.Members[0]);
     ASContext.Context.GetVisibleExternalElements().Returns(x => context.GetVisibleExternalElements());
     ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x =>
     {
         var src = x[0] as string;
         return string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src);
     });
     ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt<string>(0), x.ArgAt<FileModel>(1)));
     var expr = ASComplete.GetExpressionType(sci, sci.CurrentPos);
     var currentMember = expr.Context.LocalVars[0];
     ASGenerator.contextMember = currentMember;
     ASGenerator.GenerateJob(GeneratorJobType.PromoteLocal, currentMember, ASContext.Context.CurrentClass, null, null);
     return sci.Text;
 }
Example #39
0
 /// <summary>
 /// Open a file in the classpath (physical or virtual) or a specific context
 /// </summary>
 public FileModel OpenFile(string filename, IASContext context)
 {
     if (context == null || context.Classpath == null)
         return null;
     FileModel model = null;
     foreach (PathModel aPath in context.Classpath)
         if (aPath.HasFile(filename))
         {
             model = aPath.GetFile(filename);
             break;
         }
     if (model != null)
     {
         if (File.Exists(model.FileName))
             ASContext.MainForm.OpenEditableDocument(model.FileName, false);
         else
         {
             ASComplete.OpenVirtualFile(model);
             model = ASContext.Context.CurrentModel;
         }
     }
     return model;
 }
Example #40
0
        public static void SetHaxeFeatures(this IASContext context)
        {
            var haxeContext = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            context.Features.Returns(haxeContext.Features);
        }
Example #41
0
        private string ProcessFileTemplate(string args)
        {
            Int32         eolMode          = (Int32)MainForm.Settings.EOLMode;
            String        lineBreak        = LineEndDetector.GetNewLineMarker(eolMode);
            List <String> imports          = new List <string>();
            string        extends          = "";
            string        implements       = "";
            string        access           = "";
            string        inheritedMethods = "";
            string        paramString      = "";
            string        superConstructor = "";
            string        classMetadata    = "";
            int           index;

            // resolve imports
            if (lastFileOptions.interfaces != null && lastFileOptions.interfaces.Count > 0)
            {
                string implementContinuation;
                implements = " implements ";
                index      = 0;

                if (lastFileOptions.Language == "haxe")
                {
                    bool isHaxe2 = PluginBase.CurrentSDK != null && PluginBase.CurrentSDK.Name.ToLower().Contains("haxe 2");
                    implementContinuation = isHaxe2 ? ", implements " : " implements ";
                }
                else
                {
                    implementContinuation = ", ";
                }

                foreach (string item in lastFileOptions.interfaces)
                {
                    if (item.Contains('.'))
                    {
                        imports.Add(item);
                    }
                    implements += (index > 0 ? implementContinuation : "") + item.Split('.').Last();
                    if (lastFileOptions.createInheritedMethods)
                    {
                        processOnSwitch = lastFileFromTemplate;
                        // let ASCompletion generate the implementations when file is opened
                    }
                    index++;
                }
            }
            if (lastFileOptions.superClass != "")
            {
                var superClassFullName = lastFileOptions.superClass;
                if (superClassFullName.Contains("."))
                {
                    imports.Add(superClassFullName);
                }
                var superClassShortName = superClassFullName.Split('.').Last();
                var fileName            = Path.GetFileNameWithoutExtension(lastFileFromTemplate);
                extends        = fileName == superClassShortName ? $" extends {superClassFullName}" : $" extends {superClassShortName}";
                processContext = ASContext.GetLanguageContext(lastFileOptions.Language);
                if (lastFileOptions.createConstructor && processContext != null && constructorArgs == null)
                {
                    var lastDotIndex = superClassFullName.LastIndexOf('.');
                    var cmodel       = processContext.GetModel(lastDotIndex < 0 ? "" : superClassFullName.Substring(0, lastDotIndex), superClassShortName, "");
                    if (!cmodel.IsVoid())
                    {
                        if ((cmodel.Flags & FlagType.TypeDef) != 0)
                        {
                            var tmp = cmodel;
                            while (!tmp.IsVoid())
                            {
                                if (!string.IsNullOrEmpty(tmp.Constructor))
                                {
                                    cmodel = tmp;
                                    break;
                                }
                                tmp.ResolveExtends();
                                tmp = tmp.Extends;
                            }
                        }
                        foreach (MemberModel member in cmodel.Members)
                        {
                            if (member.Name == cmodel.Constructor)
                            {
                                paramString = member.ParametersString();
                                AddImports(imports, member, cmodel);
                                superConstructor = "super(";
                                index            = 0;
                                if (member.Parameters != null)
                                {
                                    foreach (MemberModel param in member.Parameters)
                                    {
                                        if (param.Name.StartsWith('.'))
                                        {
                                            break;
                                        }
                                        var pname = TemplateUtils.GetParamName(param);
                                        superConstructor += (index > 0 ? ", " : "") + pname;
                                        index++;
                                    }
                                }
                                superConstructor += ");\n" + (lastFileOptions.Language == "as3" ? "\t\t\t" : "\t\t");
                                break;
                            }
                        }
                    }
                }
                processContext = null;
            }
            if (constructorArgs != null)
            {
                paramString = constructorArgs;
                foreach (String type in constructorArgTypes)
                {
                    if (!imports.Contains(type))
                    {
                        imports.Add(type);
                    }
                }
            }
            if (lastFileOptions.Language == "as3")
            {
                access  = lastFileOptions.isPublic ? "public " : "internal ";
                access += lastFileOptions.isDynamic ? "dynamic " : "";
                access += lastFileOptions.isFinal ? "final " : "";
            }
            else if (lastFileOptions.Language == "haxe")
            {
                access  = lastFileOptions.isPublic ? "public " : "private ";
                access += lastFileOptions.isDynamic ? "dynamic " : "";
                if (lastFileOptions.isFinal)
                {
                    classMetadata += "@:final\n";
                }
            }
            else
            {
                access = lastFileOptions.isDynamic ? "dynamic " : "";
            }
            string importsSrc = "";
            string prevImport = null;

            imports.Sort();
            foreach (string import in imports)
            {
                if (prevImport != import)
                {
                    prevImport = import;
                    if (import.LastIndexOf('.') == -1)
                    {
                        continue;
                    }
                    if (import.Substring(0, import.LastIndexOf('.')) == lastFileOptions.Package)
                    {
                        continue;
                    }
                    importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + "import " + import + ";" + lineBreak;
                }
            }
            if (importsSrc.Length > 0)
            {
                importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + lineBreak;
            }
            args = args.Replace("$(Import)", importsSrc);
            args = args.Replace("$(Extends)", extends);
            args = args.Replace("$(Implements)", implements);
            args = args.Replace("$(Access)", access);
            args = args.Replace("$(InheritedMethods)", inheritedMethods);
            args = args.Replace("$(ConstructorArguments)", paramString);
            args = args.Replace("$(Super)", superConstructor);
            args = args.Replace("$(ClassMetadata)", classMetadata);
            return(args);
        }
Example #42
0
        /// <summary>
        /// Init completion engine context
        /// </summary>
        /// <param name="mainForm">Reference to MainForm</param>
        static internal void GlobalInit(PluginMain pluginMain)
        {
            dirSeparatorChar = Path.DirectorySeparatorChar;
            dirSeparator = dirSeparatorChar.ToString();
            dirAltSeparatorChar = Path.AltDirectorySeparatorChar;
            dirAltSeparator = dirAltSeparatorChar.ToString();
            doPathNormalization = (dirSeparator != dirAltSeparator);

            // language contexts
            plugin = pluginMain;
            validContexts = new List<IASContext>();
            context = null;
            try
            {
                context = defaultContext = new ASContext();
            }
            catch(Exception ex)
            {
                ErrorManager.ShowError(ex);
            }
        }
Example #43
0
 /// <summary>
 /// Adds a language context
 /// </summary>
 /// <param name="contextReference">Language context</param>
 /// <param name="language">Language id (ie. Scintilla.ConfigurationLanguage)</param>
 static public void RegisterLanguage(IASContext contextReference, string language)
 {
     allContexts.Add(new RegisteredContext(contextReference, language, null));
 }
Example #44
0
        private static List <String> GetAllProjectRelatedFiles(IProject project, bool onlySourceFiles, Boolean ignoreSdkFiles)
        {
            List <String> files  = new List <String>();
            string        filter = project.DefaultSearchFilter;

            if (string.IsNullOrEmpty(filter))
            {
                return(files);
            }
            string[] filters = project.DefaultSearchFilter.Split(';');
            if (!onlySourceFiles)
            {
                IASContext context = ASContext.GetLanguageContext(project.Language);
                if (context == null)
                {
                    return(files);
                }
                foreach (PathModel pathModel in context.Classpath)
                {
                    string absolute = project.GetAbsolutePath(pathModel.Path);
                    if (Directory.Exists(absolute))
                    {
                        if (ignoreSdkFiles && IsUnderSDKPath(absolute))
                        {
                            continue;
                        }
                        foreach (string filterMask in filters)
                        {
                            files.AddRange(Directory.GetFiles(absolute, filterMask, SearchOption.AllDirectories));
                        }
                    }
                }
            }
            else
            {
                var lookupPaths = project.SourcePaths.
                                  Concat(ProjectManager.PluginMain.Settings.GetGlobalClasspaths(project.Language)).
                                  Select(project.GetAbsolutePath).Distinct();
                foreach (string path in lookupPaths)
                {
                    if (Directory.Exists(path))
                    {
                        if (ignoreSdkFiles && IsUnderSDKPath(path))
                        {
                            continue;
                        }
                        foreach (string filterMask in filters)
                        {
                            files.AddRange(Directory.GetFiles(path, filterMask, SearchOption.AllDirectories));
                        }
                    }
                }
            }
            // If no source paths are defined, get files directly from project path
            if (project.SourcePaths.Length == 0)
            {
                String projRoot = Path.GetDirectoryName(project.ProjectPath);
                foreach (string filterMask in filters)
                {
                    files.AddRange(Directory.GetFiles(projRoot, filterMask, SearchOption.AllDirectories));
                }
            }
            return(files);
        }
Example #45
0
 /// <summary>
 /// Adds an inlined language context (ie. Javascript in Html)
 /// </summary>
 /// <param name="contextReference">Language context</param>
 /// <param name="language">File language id (ie. Scintilla.ConfigurationLanguage)</param>
 /// <param name="inlined">Inlined language id</param>
 static public void RegisterInlineLanguage(IASContext contextReference, string language, string inlined)
 {
     allContexts.Add(new RegisteredContext(contextReference, language, inlined));
 }
Example #46
0
        public static void SetAs3Features(this IASContext context)
        {
            var asContext = new AS3Context.Context(new AS3Context.AS3Settings());

            context.Features.Returns(asContext.Features);
        }
Example #47
0
        /// <summary>
        /// Currently edited document
        /// </summary>
        static internal void SetCurrentFile(ITabbedDocument doc, bool shouldIgnore)
        {
            // reset previous contexts
            if (validContexts.Count > 0)
            {
                foreach (IASContext oldcontext in validContexts)
                    oldcontext.CurrentFile = null;
            }
            validContexts = new List<IASContext>();
            context = defaultContext;
            context.CurrentFile = null;

            // check document
            string filename = "";
            if (doc != null && doc.FileName != null)
            {
                filename = doc.FileName;
                if (doPathNormalization)
                    filename = filename.Replace(dirAltSeparator, dirSeparator);
            }
            else shouldIgnore = true;

            FileModel.Ignore.FileName = filename ?? "";
            // find the doc context(s)
            if (!shouldIgnore)
            {
                string lang = doc.SciControl.ConfigurationLanguage.ToLower();
                string ext = Path.GetExtension(filename);
                if (!string.IsNullOrEmpty(ext) && lang == "xml")
                    lang = ext.Substring(1).ToLower();
                foreach (RegisteredContext reg in allContexts)
                {
                    if (reg.Language == lang)
                    {
                        validContexts.Add(reg.Context);
                        reg.Context.CurrentFile = filename;
                    }
                }
                currentLine = -1;
                SetCurrentLine(doc.SciControl.CurrentLine);
            }
            // no context
            if (context == defaultContext) Panel.UpdateView(FileModel.Ignore);
            else Context.CheckModel(true);
        }
Example #48
0
 private void DetectContext()
 {
     current = ASContext.Context;
     if (PluginBase.CurrentProject != null)
         current = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language);
 }
Example #49
0
        public PathModel(string path, IASContext context)
        {
            Owner = context;
            Path = path.TrimEnd(new char[] { '\\', '/' });
            Files = new Dictionary<string, FileModel>();
            LastAccess = DateTime.Now;

            updater = new Timer();
            updater.Interval = 2000;
            updater.Tick += new EventHandler(updater_Tick);
            toExplore = new List<string>();
            toRemove = new List<string>();
            
            // generic models container
            if (context == null)
            {
                IsValid = true;
            }
            // watched path
            else if (Directory.Exists(Path) && Path.Length > 3)
            {
                IsValid = true;
                if (Owner != null)
                {
                    try
                    {
                        watcher = new FileSystemWatcher();
                        watcher.Path = System.IO.Path.GetDirectoryName(Path);
                        basePath = path;
                        masks = Owner.GetExplorerMask();
                        watcher.IncludeSubdirectories = true;
                        watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.Size;
                        watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
                        watcher.Changed += new FileSystemEventHandler(watcher_Changed);
                        watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
                        watcher.EnableRaisingEvents = true;
                        watcher.InternalBufferSize = 4096 * 8;
                    }
                    catch
                    {
                        watcher = null;
                        IsValid = false;
                    }
                }
            }
            else if (File.Exists(Path) && Owner != null)
            {
                IsValid = true;
                IsVirtual = true;
                try
                {
                    watcher = new FileSystemWatcher();
                    basePath = watcher.Path = System.IO.Path.GetDirectoryName(Path);
                    masks = new string[] { System.IO.Path.GetFileName(path) };
                    watcher.IncludeSubdirectories = false;
                    watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.Size;
                    watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
                    watcher.Changed += new FileSystemEventHandler(watcher_Changed);
                    watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
                    watcher.EnableRaisingEvents = true;
                }
                catch
                {
                    watcher = null;
                    IsValid = false;
                }
            }
        }