/// <summary> /// Prepare AS2 intrinsic known vars/methods/classes /// </summary> protected override void InitTopLevelElements() { string filename = "toplevel.tjs"; topLevel = new FileModel(filename); // search top-level declaration foreach (PathModel aPath in classPath) { if (File.Exists(Path.Combine(aPath.Path, filename))) { filename = Path.Combine(aPath.Path, filename); topLevel = GetCachedFileModel(filename); break; } } if (File.Exists(filename)) { // MTASC toplevel-style declaration: ClassModel tlClass = topLevel.GetPublicClass(); if (!tlClass.IsVoid()) { topLevel.Members = tlClass.Members; tlClass.Members = null; topLevel.Classes = new List <ClassModel>(); } } // not found else { } if (topLevel.Members.Search("global", 0, 0) == null) { topLevel.Members.Add(new MemberModel("global", docType, FlagType.Variable, Visibility.Public)); } if (topLevel.Members.Search("this", 0, 0) == null) { topLevel.Members.Add(new MemberModel("this", "", FlagType.Variable, Visibility.Public)); } if (topLevel.Members.Search("super", 0, 0) == null) { topLevel.Members.Add(new MemberModel("super", "", FlagType.Variable, Visibility.Public)); } if (topLevel.Members.Search(features.voidKey, 0, 0) == null) { topLevel.Members.Add(new MemberModel(features.voidKey, "", FlagType.Class | FlagType.Intrinsic, Visibility.Public)); } topLevel.Members.Sort(); foreach (MemberModel member in topLevel.Members) { member.Flags |= FlagType.Intrinsic; } }
private static void ExploreMetadatas(FileModel fileModel, List <ICompletionListItem> mix, List <string> excludes, string ns, bool isCurrentModel) { if (fileModel == null || fileModel.MetaDatas == null) { return; } ClassModel model = fileModel.GetPublicClass(); string className = model.IsVoid() ? Path.GetFileNameWithoutExtension(fileModel.FileName) : model.Name; foreach (ASMetaData meta in fileModel.MetaDatas) { string add = null; string type = null; switch (meta.Kind) { case ASMetaKind.Event: add = ":e"; break; case ASMetaKind.Style: string inherit; if (meta.Params == null || !meta.Params.TryGetValue("inherit", out inherit) || inherit != "no" || isCurrentModel) { add = ":s"; if (meta.Params == null || !meta.Params.TryGetValue("type", out type)) { type = "Object"; } } break; case ASMetaKind.Effect: add = ":x"; if (meta.Params != null) { type = meta.Params["event"]; } break; case ASMetaKind.Exclude: if (meta.Params != null) { excludes.Add(meta.Params["name"]); } break; case ASMetaKind.Include: FileModel incModel = ParseInclude(fileModel, meta); ExploreMetadatas(incModel, mix, excludes, ns, isCurrentModel); break; } if (add != null && meta.Params.ContainsKey("name")) { mix.Add(new HtmlAttributeItem(meta.Params["name"] + add, type, className, ns)); } } }
private static void ExploreMetadatas(FileModel fileModel, List <ICompletionListItem> mix, List <string> excludes, string ns) { if (fileModel == null || fileModel.MetaDatas == null) { return; } ClassModel model = fileModel.GetPublicClass(); string className = model.IsVoid() ? Path.GetFileNameWithoutExtension(fileModel.FileName) : model.Name; foreach (ASMetaData meta in fileModel.MetaDatas) { string add = null; string type = null; switch (meta.Kind) { case ASMetaKind.Event: add = ":e"; break; case ASMetaKind.Style: add = ":s"; if (meta.Params != null) { type = meta.Params["type"]; } break; case ASMetaKind.Effect: add = ":x"; if (meta.Params != null) { type = meta.Params["event"]; } break; case ASMetaKind.Exclude: if (meta.Params != null) { excludes.Add(meta.Params["name"]); } break; case ASMetaKind.Include: FileModel incModel = ParseInclude(fileModel, meta); ExploreMetadatas(incModel, mix, excludes, ns); break; } if (add != null) { mix.Add(new HtmlAttributeItem(meta.Params["name"] + add, type, className, ns)); } } }
/// <summary> /// Called if a FileModel needs filtering /// - modify parsed model /// </summary> /// <param name="model"></param> /// <returns></returns> static public void FilterSource(FileModel model, MxmlFilterContext ctx) { ctx.model = model; model.InlinedIn = "xml"; model.InlinedRanges = ctx.as3ranges; if (model.MetaDatas == null) { model.MetaDatas = new List <ASMetaData>(); } foreach (string key in ctx.namespaces.Keys) { ASMetaData meta = new ASMetaData("Namespace"); meta.Params = new Dictionary <string, string>(); meta.Params.Add(key, ctx.namespaces[key]); model.MetaDatas.Add(meta); } ClassModel aClass = model.GetPublicClass(); if (aClass == ClassModel.VoidClass) { return; } aClass.Comments = "<" + ctx.baseTag + "/>"; Dictionary <string, string> resolved = new Dictionary <string, string>(); foreach (MemberModel mxmember in ctx.mxmlMembers) { string tag = mxmember.Type; string type = null; if (resolved.ContainsKey(tag)) { type = resolved[tag]; } else { type = MxmlComplete.ResolveType(ctx, tag); resolved[tag] = type; } MemberModel member = aClass.Members.Search(mxmember.Name, FlagType.Variable, Visibility.Public); if (member != null) { member.Comments = "<" + tag + "/>"; member.Type = type; } } }
/// <summary> /// Prepare haXe intrinsic known vars/methods/classes /// </summary> protected override void InitTopLevelElements() { string filename = "toplevel.hx"; topLevel = new FileModel(filename); // search top-level declaration foreach (PathModel aPath in classPath) { if (File.Exists(Path.Combine(aPath.Path, filename))) { filename = Path.Combine(aPath.Path, filename); topLevel = GetCachedFileModel(filename); break; } } if (File.Exists(filename)) { // copy declarations as file-level ClassModel tlClass = topLevel.GetPublicClass(); if (!tlClass.IsVoid()) { topLevel.Members = tlClass.Members; tlClass.Members = null; topLevel.Classes = new List <ClassModel>(); } } // not found else { //ErrorHandler.ShowInfo("Top-level elements class not found. Please check your Program Settings."); } topLevel.Members.Add(new MemberModel("this", "", FlagType.Variable, Visibility.Public)); topLevel.Members.Add(new MemberModel("super", "", FlagType.Variable, Visibility.Public)); topLevel.Members.Add(new MemberModel("Void", "", FlagType.Intrinsic, Visibility.Public)); topLevel.Members.Sort(); foreach (MemberModel member in topLevel.Members) { member.Flags |= FlagType.Intrinsic; } }
private static bool GetAutoCompletionValuesFromMetaData(ClassModel model, string attribute, ClassModel tagClass, ClassModel tmpClass, out List <ICompletionListItem> result) { if (model != null && model.MetaDatas != null) { foreach (ASMetaData meta in model.MetaDatas) { string name = null; if (!meta.Params.TryGetValue("name", out name) || name != attribute) { continue; } string type = null; switch (meta.Kind) { case ASMetaKind.Event: string eventType; if (!meta.Params.TryGetValue("type", out eventType)) { eventType = "flash.events.Event"; } result = GetAutoCompletionValuesFromEventType(eventType); return(true); case ASMetaKind.Style: string inherit; if (meta.Params != null && meta.Params.TryGetValue("inherit", out inherit) && inherit == "no" && tagClass != tmpClass) { continue; } if (meta.Params != null) { meta.Params.TryGetValue("type", out type); } break; case ASMetaKind.Effect: if (meta.Params != null) { type = meta.Params["event"]; } break; case ASMetaKind.Exclude: break; case ASMetaKind.Include: // TODO: Check this case... Debug.Assert(false, "Please, check this case"); FileModel incModel = ParseInclude(model.InFile, meta); return(GetAutoCompletionValuesFromMetaData(incModel.GetPublicClass(), attribute, tagClass, tmpClass, out result)); } if (meta.Params != null && meta.Params.ContainsKey("enumeration")) { var retVal = new List <ICompletionListItem>(); foreach (string value in meta.Params["enumeration"].Split(',')) { var tValue = value.Trim(); if (tValue != string.Empty) { retVal.Add(new HtmlAttributeItem(tValue)); } } result = retVal; return(true); } result = GetAutoCompletionValuesFromType(type); return(true); } } result = null; return(false); }