public DeclaredVariables(string source, List <string> fullNamespaceList, bool visibleScopesOnly) { _declaredVariables = new List <Variable>(); /* * Get the local variables declared in the source. */ source = JScriptFormattingTools.RemoveNamespaceDeclarations(source); if (visibleScopesOnly) { source = JScriptFormattingTools.RemoveInaccessibleScopes(source); } FindVariableDeclaratons(source); /* * Convert the JScript typenames to their framework classes. */ foreach (Variable v in _declaredVariables) { // Fixup any language type names v.Type = JScriptFormattingTools.ToCTSType(v.Type); } }
private void AddField( Dictionary <String, LookupListItem> foundItems, MemberInfo item) { FieldInfo fi = (FieldInfo)item; if (fi.IsPrivate) { return; } if (!foundItems.ContainsKey(fi.Name)) { LookupListItem li = new LookupListItem(); li.DisplayText = fi.Name; li.InsertText = fi.Name; li.ToolTipText = String.Format("{0} {1}", JScriptFormattingTools.GetTypeSignature(fi.FieldType), fi.Name); if (fi.IsLiteral) { if (fi.IsPublic) { li.Category = QuickSharp.CodeAssist.Constants.CONSTANT; } else { li.Category = QuickSharp.CodeAssist.Constants.CONSTANT_FRIEND; } } else { if (fi.IsPublic) { li.Category = QuickSharp.CodeAssist.Constants.FIELD; } else if (fi.IsFamily) { li.Category = QuickSharp.CodeAssist.Constants.EXCEPTION_PROTECTED; } else if (fi.IsPrivate) { li.Category = QuickSharp.CodeAssist.Constants.FIELD_PRIVATE; } else { li.Category = QuickSharp.CodeAssist.Constants.FIELD_FRIEND; } } foundItems.Add(li.DisplayText, li); } }
private void AddProperty( Dictionary <String, LookupListItem> foundItems, MemberInfo item) { PropertyInfo pi = (PropertyInfo)item; if (!foundItems.ContainsKey(pi.Name)) { LookupListItem li = new LookupListItem(); li.DisplayText = pi.Name; li.InsertText = pi.Name; li.Category = QuickSharp.CodeAssist.Constants.PROPERTIES; li.ToolTipText = String.Format("{0} {1}", JScriptFormattingTools.GetTypeSignature(pi.PropertyType), pi.Name); foundItems.Add(pi.Name, li); } else { foundItems[pi.Name].ToolTipText = String.Format("{0} {1}", JScriptFormattingTools.GetTypeSignature(pi.PropertyType), pi.Name); } }
public string GetVariableCollectionType(string entity) { /* * For arrays we return the item that the object is a * collection of. For anything else we need to swap in * the base type and append 'Item'. */ if (IsArray) { return(JScriptFormattingTools.ToCTSType(ArrayType)); } else { string[] split = entity.Split('.'); split[0] = Type; return(String.Join(".", split) + ".Item"); } }
/* * Create a LookupListItem from a type. */ protected LookupListItem GetItem(Type type) { string typeName = CSharpFormattingTools.GetTypeSignature(type); string fullName = CSharpFormattingTools.GetTypeSignature(type, true); LookupListItem item = new LookupListItem(); item.DisplayText = typeName; item.InsertText = type.ContainsGenericParameters ? CSharpFormattingTools.RemoveGenericSignature(typeName) : typeName; // Classify the type - order is important here if (type.IsClass && type.IsSubclassOf(typeof(System.Delegate))) { item.Category = QuickSharp.CodeAssist.Constants.DELEGATE; item.ToolTipText = String.Format("delegate {0}", fullName); } else if (type.IsEnum) { item.Category = QuickSharp.CodeAssist.Constants.ENUM; item.ToolTipText = String.Format("enum {0}", fullName); } else if (type.IsValueType) { item.Category = QuickSharp.CodeAssist.Constants.VALUETYPE; item.ToolTipText = String.Format("struct {0}", fullName); } else if (type.IsInterface) { item.Category = QuickSharp.CodeAssist.Constants.INTERFACE; item.ToolTipText = String.Format("interface {0}", fullName); } else { if (type.IsSealed) { item.Category = QuickSharp.CodeAssist.Constants.CLASS_SEALED; } else { item.Category = QuickSharp.CodeAssist.Constants.CLASS; } item.ToolTipText = String.Format("class {0}", fullName); BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance; ConstructorInfo[] cia = type.GetConstructors(bindingAttr); foreach (ConstructorInfo ci in cia) { LookupMenuItem lmi = new LookupMenuItem(); lmi.DisplayText = JScriptFormattingTools. GetConstructorSignature(ci, type); lmi.InsertText = JScriptFormattingTools. GetMinimalConstructorSignature(ci, type); item.MenuItems.Add(lmi); } } return(item); }
private LookupList GetJScriptLookupList( QuickSharp.Editor.ScintillaEditForm document) { UpdateLists(); if ((settingsManager.ColorizeTypes || settingsManager.ColorizeVariables) && settingsManager.ColorizeOnLookup) { ColourizeVariablesAndTypes(document); } /* * Get the search target from the current line. */ Line line = document.Editor.Lines.Current; string text = line.Text.Substring(0, line.SelectionStartPosition - line.StartPosition).TrimStart(); /* * Check for embedded option or empty comment. */ if (text.StartsWith("//")) { if (text.Length > 2 && "$?&".IndexOf(text[2]) != -1) { return(EmbeddedOptionHelper.GetEmbbededOptionFileList(text)); } else { return(null); } } /* * Cleanup the source. */ text = JScriptFormattingTools.RemoveUnwantedText(text); text = JScriptFormattingTools.RemoveUnwantedBracketText(text); text = JScriptFormattingTools.RemoveUnwantedParentheses(text); LookupTarget target = new LookupTarget(text); List <LookupListItem> lookupItemList; string source = document.GetContent() as string; source = source.Substring(0, document.Editor.CurrentPos); source = JScriptFormattingTools.RemoveUnwantedText(source); source = JScriptFormattingTools.RemoveUnwantedBracketText(source); /* * Looking for namespaces as part of an 'import' * declaration... */ lookupItemList = GetChildNamespaces(target, text); if (lookupItemList != null) { return(new LookupList(target.LookAhead, lookupItemList)); } /* * Looking for members of a namespace... */ if (target.Entity != String.Empty) { List <LookupListItem> types = FindNamespaceTypeLookupItems(target.Entity); List <LookupListItem> namespaces = FindNamespaceChildLookupItems(target.Entity); if (types != null || namespaces != null) { lookupItemList = new List <LookupListItem>(); if (types != null) { lookupItemList.AddRange(types); } if (namespaces != null) { lookupItemList.AddRange(namespaces); } } } if (lookupItemList != null) { return(new LookupList(target.LookAhead, lookupItemList)); } /* * Get the local variables declared within the scope visible * from the lookup location (the caret)... */ DeclaredVariables declaredVariables = new DeclaredVariables(source, fullNamespaceList, true); /* * Looking for anything in scope... */ if (String.IsNullOrEmpty(target.Entity)) { lookupItemList = GetVisibleTypes( source, declaredVariables, true, true); if (lookupItemList != null) { // Add the root namespaces foreach (string ns in rootNamespaceList) { LookupListItem item = new LookupListItem(); item.DisplayText = ns; item.InsertText = ns; item.Category = QuickSharp.CodeAssist.Constants.NAMESPACE; item.ToolTipText = String.Format("namespace {0}", ns); lookupItemList.Add(item); } return(new LookupList(target.LookAhead, lookupItemList)); } } /* * The target cannot be blank after this point; if we haven't found * anything using a blank target then there's nothing to find. */ if (String.IsNullOrEmpty(target.Entity)) { return(null); } /* * Looking for members of a variable... */ Variable variable = declaredVariables.GetVariable(target.Entity); if (variable != null) { String[] split = target.Entity.Split('.'); if (target.IsIndexed) { target.Entity = variable.GetVariableCollectionType(target.Entity); } else { split[0] = variable.Type; target.Entity = String.Join(".", split); } lookupItemList = GetTypeMembers( source, target, false, false); if (lookupItemList != null) { return(new LookupList(target.LookAhead, lookupItemList)); } } /* * Looking for members of a class... */ lookupItemList = GetTypeMembers(source, target, true, false); return(new LookupList(target.LookAhead, lookupItemList)); }
private void AddMethod( Dictionary <String, LookupListItem> foundItems, MemberInfo item) { MethodInfo mi = (MethodInfo)item; if (mi.IsSpecialName) { return; } if (mi.IsPrivate) { return; } if (mi.Name == "Finalize") { return; } if (!foundItems.ContainsKey(mi.Name)) { bool isExtensionMethod = mi.GetCustomAttributes( typeof(ExtensionAttribute), false).Length > 0; LookupListItem lli = new LookupListItem(); lli.DisplayText = mi.Name; lli.InsertText = mi.Name; lli.ToolTipText = String.Format("{0} {1}_OVR_", JScriptFormattingTools.GetTypeSignature(mi.ReturnType), JScriptFormattingTools.GetMethodSignature(mi)); if (isExtensionMethod) { lli.Category = QuickSharp.CodeAssist.Constants.METHOD_EXTENSION; } else if (mi.IsPublic) { lli.Category = QuickSharp.CodeAssist.Constants.METHOD; } else if (mi.IsFamily) { lli.Category = QuickSharp.CodeAssist.Constants.METHOD_PROTECTED; } else { lli.Category = QuickSharp.CodeAssist.Constants.METHOD_FRIEND; } LookupMenuItem lmi = new LookupMenuItem(); lmi.DisplayText = String.Format("{0} {1}", JScriptFormattingTools.GetTypeSignature(mi.ReturnType), JScriptFormattingTools.GetMethodSignature(mi)); lmi.InsertText = JScriptFormattingTools.GetMinimalMethodSignature(mi); lli.MenuItems.Add(lmi); foundItems.Add(mi.Name, lli); } else { // Overloaded method LookupListItem lli = foundItems[mi.Name]; LookupMenuItem lmi = new LookupMenuItem(); lmi.DisplayText = String.Format("{0} {1}", JScriptFormattingTools.GetTypeSignature(mi.ReturnType), JScriptFormattingTools.GetMethodSignature(mi)); lmi.InsertText = JScriptFormattingTools.GetMinimalMethodSignature(mi); lli.MenuItems.Add(lmi); } }