/// <summary> /// Provides custom title for find results view tab /// </summary> /// <returns></returns> public override string GetResultsTitle(OccurenceSection section) { string form = "location"; string title; int foundCount = section.TotalCount; if (foundCount > 0) { if (foundCount > 1) { form = NounUtil.GetPlural(form); } title = foundCount == section.FilteredCount ? string.Format("Found {0} {1}", foundCount, form) : string.Format("Displaying {0} of {1} found {2}", section.FilteredCount, foundCount, form); } else { title = string.Format("No locations found"); } return(title); }
private static string FormatClosureDescription([NotNull] JetHashSet <IDeclaredElement> elements) { int parameters = 0, vars = 0; var hasThis = false; foreach (var element in elements) { if (element is IParameter || element is IQueryAnonymousTypeProperty) { parameters++; } else if (element is ILocalVariable) { vars++; } else if (element is IFunction) { hasThis = true; } } var buf = new StringBuilder(); if (parameters > 0) { buf.Append(FormatOrderedByStartOffset(elements.Where(element => element is IParameter || element is IQueryAnonymousTypeProperty))) .Append(' ') .Append(NounUtil.ToPluralOrSingular("parameter", parameters)); } if (vars > 0) { if (parameters > 0) { buf.Append(hasThis ? ", " : " and "); } buf.Append(FormatOrderedByStartOffset( elements.Where(element => element is ILocalVariable))) .Append(' ') .Append(NounUtil.ToPluralOrSingular("variable", vars)); } if (hasThis) { if (parameters > 0 || vars > 0) { buf.Append(" and "); } buf.Append("'this' reference"); } return(buf.ToString()); }
public override ICollection <TreeSection> GetTreeSections([NotNull] IOccurrenceBrowserDescriptor descriptor) { return(descriptor.OccurrenceSections.Select( x => { var caption = $"Found {x.Items.Count} linked {NounUtil.ToPluralOrSingular("type", x.Items.Count)}"; return new TreeSection(x.Model, caption); }) .ToList()); }
public override string GetResultsTitle(OccurrenceSection section) { if (section.TotalCount == 0) { return(NoLinkedTypesFoundText); } var typeOrTypes = NounUtil.ToPluralOrSingular("type", section.TotalCount); return(section.FilteredCount == section.TotalCount ? $"Found {section.TotalCount} linked {typeOrTypes}" : $"Displaying {section.FilteredCount} of {section.TotalCount} linked {typeOrTypes}"); }
public override string GetResultsTitle(OccurenceSection section) { string singular = "registered component"; int totalCount = section.TotalCount; string str; if (totalCount > 0) { if (totalCount > 1) { singular = NounUtil.GetPlural(singular); } str = totalCount == section.FilteredCount ? string.Format("Found {0} {1}", totalCount, singular) : string.Format("Displaying {0} of {1} found {2}", section.FilteredCount, totalCount, singular); } else { str = string.Format("No registered components", new object[0]); } return(str); }
public void AddInspectorHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, IDeclaredElement declaredElement, string baseDisplayName, string baseTooltip, string moreText, IconModel iconModel, IEnumerable <BulbMenuItem> items, List <CodeLensEntryExtraActionModel> extraActions) { string displayName = null; var solution = element.GetSolution(); Assertion.Assert(solution.Locks.IsReadAccessAllowed(), "ReadLock required"); var field = (declaredElement as IField).NotNull(); var type = field.Type; var containingType = field.GetContainingType(); if (containingType == null) { base.AddHighlighting(consumer, element, field, baseDisplayName, baseTooltip, moreText, iconModel, items, extraActions); return; } var(guidN, propertyNames) = GetAssetGuidAndPropertyName(solution, field); if (guidN == null || propertyNames.Length == 0) { base.AddHighlighting(consumer, element, field, baseDisplayName, baseTooltip, moreText, iconModel, items, extraActions); return; } var guid = guidN.Value; var presentationType = GetUnityPresentationType(type); if (!myDeferredCacheController.CompletedOnce.Value || ShouldShowUnknownPresentation(presentationType)) { base.AddHighlighting(consumer, element, field, baseDisplayName, baseTooltip, moreText, iconModel, items, extraActions); return; } if (presentationType == UnityPresentationType.UnityEvent) { var count = myUnityEventsElementContainer.GetUsageCountForEvent(field, out var estimated); var sb = new StringBuilder(); if (count == 0 && !estimated) { sb.Append("No methods"); } else { sb.Append(count); if (estimated) { sb.Append('+'); } sb.Append(" "); sb.Append("method"); if (estimated || count > 1) { sb.Append("s"); } } consumer.AddHighlighting(new UnityInspectorCodeInsightsHighlighting(element.GetNameDocumentRange(), sb.ToString(), GetTooltip(count, estimated, false), "Methods", this, declaredElement, iconModel, presentationType)); return; } var initializer = (element as IFieldDeclaration).NotNull("element as IFieldDeclaration != null").Initial; var initValue = (initializer as IExpressionInitializer)?.Value?.ConstantValue.Value; var initValueUnityPresentation = GetUnitySerializedPresentation(presentationType, initValue); int changesCount; bool isEstimated = false; bool isUniqueChange = false; if (myInspectorValuesContainer.IsIndexResultEstimated(guid, containingType, propertyNames)) { changesCount = myInspectorValuesContainer.GetAffectedFiles(guid, propertyNames) - myInspectorValuesContainer.GetAffectedFilesWithSpecificValue(guid, propertyNames, initValueUnityPresentation); displayName = $"Changed in {changesCount}+ assets"; isEstimated = true; } else { changesCount = 0; var initValueCount = myInspectorValuesContainer.GetValueCount(guid, propertyNames, initValueUnityPresentation); if (initValueCount == 0 && myInspectorValuesContainer.GetUniqueValuesCount(guid, propertyNames) == 1) // only modified value { isUniqueChange = true; var value = myInspectorValuesContainer.GetUniqueValueDifferTo(guid, propertyNames, null); displayName = value.GetPresentation(solution, field, false); } else if (initValueCount > 0 && myInspectorValuesContainer.GetUniqueValuesCount(guid, propertyNames) == 2) { isUniqueChange = true; // original value & only one modified value var anotherValueWithLocation = myInspectorValuesContainer.GetUniqueValueDifferTo(guid, propertyNames, initValueUnityPresentation); displayName = anotherValueWithLocation.GetPresentation(solution, field, false); } if (displayName == null || displayName.Equals("...")) { changesCount = myInspectorValuesContainer.GetAffectedFiles(guid, propertyNames) - myInspectorValuesContainer.GetAffectedFilesWithSpecificValue(guid, propertyNames, initValueUnityPresentation); if (changesCount == 0) { displayName = "Unchanged"; } else { var word = NounUtil.ToPluralOrSingularQuick(changesCount, "asset", "assets"); displayName = $"Changed in {changesCount} {word}"; } } } consumer.AddHighlighting(new UnityInspectorCodeInsightsHighlighting(element.GetNameDocumentRange(), displayName, GetTooltip(changesCount, isEstimated, isUniqueChange), "Property Inspector values", this, declaredElement, iconModel, presentationType)); }
private static void AddProxyClass(IClassDeclaration classDeclaration, CSharpElementFactory factory) { var builderType = string.Format("{0}Builder", classDeclaration.DeclaredName); var code = new StringBuilder(string.Format("public class {0} {{", builderType)); code.AppendLine(); var cls = classDeclaration.DeclaredElement as IClass; if (cls == null) { return; } var ctor = cls.Constructors.OrderByDescending(x => x.Parameters.Count).FirstOrDefault(); if (ctor == null) { return; } var fields = new StringBuilder(); var methods = new StringBuilder(); foreach (var parameter in ctor.Parameters) { var typePresentableName = parameter.Type.GetPresentableName(cls.PresentationLanguage); var shortName = parameter.ShortName; var capitalizedShortName = shortName.Capitalize(); fields.AppendLine("private {0} _{1};", typePresentableName, shortName); methods.AppendLine("public {2} With{1}({0} value){{ ", typePresentableName, capitalizedShortName, builderType); methods.AppendLine(" _{0} = value;", shortName); methods.AppendLine("return this;"); methods.AppendLine("}"); methods.AppendLine(); if (parameter.Type.IsGenericIEnumerable()) { var genericParameter = typePresentableName.Split(new[] { '<', '>' })[1]; var listType = string.Format("List<{0}>", genericParameter); var singularName = NounUtil.GetSingular(capitalizedShortName); methods.AppendLine("public {0} Add{1}({2} value){{", builderType, singularName, genericParameter); methods.AppendLine(" if(_{0} == null){{", shortName); methods.AppendLine(" _{0} = new {1}();", shortName, listType); methods.AppendLine(" }"); methods.AppendLine(" var collection = _{0} as ICollection<{1}>;", shortName, genericParameter); methods.AppendLine(" if (collection == null || collection.IsReadOnly){"); methods.AppendLine(" throw new InvalidOperationException(\"Add{0}() method cannot be used with this collection type\");", singularName); methods.AppendLine(" }"); methods.AppendLine(" collection.Add(value);"); methods.AppendLine(" return this;"); methods.AppendLine("}"); methods.AppendLine(); } } code.Append(fields); code.Append(methods); code.AppendLine("public {0} Build(){{", classDeclaration.DeclaredName); code.AppendFormat("return new {0}(", classDeclaration.DeclaredName); code.Append(ctor.Parameters.Select(x => string.Format("_{0}", x.ShortName)).ToArray().Join(", ")); code.AppendLine(");"); code.AppendLine("}"); code.Append("}"); var memberDeclaration = factory.CreateTypeMemberDeclaration(code.ToString()) as IClassDeclaration; var namespaceDeclaration = classDeclaration.GetContainingNamespaceDeclaration(); namespaceDeclaration.AddTypeDeclarationAfter(memberDeclaration, classDeclaration); }