Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflection_Engine: Final tidy up #2944

Merged
merged 8 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/Datasets/Reflection_Engine/Query/Url.json

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions Data_Engine/Query/Count.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,45 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using BH.oM.Data.Collections;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Engine.Data
{
public static partial class Query
{

/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Get the number of items in the Priority Queue Data.")]
[Input("queue", "A priority queue with data from which to obtain the number of items from.")]
[Output("count", "The number of items in the priority queue's data.")]
public static int Count<T>(this PriorityQueue<T> queue) where T : IComparable<T>
{
return queue.Data.Count();
}

/***************************************************/

[Description("Get the number of nodes in the graph.")]
[Input("graph", "The graph from which to obtain the number of nodes it contains.")]
[Output("count", "The number of nodes in the graph.")]
public static int Count<T>(this Graph<T> graph)
{
return graph.Nodes.Count();
}

/***************************************************/

[Description("Get the number of children contained by the tree. Takes the sum of the number of values each child of the tree has.")]
[Input("tree", "The tree to obtain the number of child values from.")]
[Output("count", "The total number of values held by the children of the tree. Returns 1 if there are no children on the tree.")]
public static int Count<T>(this Tree<T> tree)
{
if (tree.Children.Count == 0)
Expand All @@ -56,12 +69,25 @@ public static int Count<T>(this Tree<T> tree)

/***************************************************/

[Description("Get the total number of objects contained within the Venn Diagram. The count will be the sum of the objects contained solely within each set plus those in the intersection.")]
[Input("diagram", "The Venn Diagram to count the number of objects for.")]
[Output("count", "The total number of items in the diagram.")]
public static int Count<T>(this VennDiagram<T> diagram)
{
return diagram.Intersection.Count + diagram.OnlySet1.Count + diagram.OnlySet2.Count;
}

/***************************************************/

[PreviousVersion("6.0", "BH.Engine.Reflection.Query.Item(System.Collections.Generic.List<System.Object>)")]
[PreviousVersion("6.0", "BH.Engine.Reflection.Query.ICount(System.Collections.Generic.List<System.Object>)")]
[Description("Get the count of items in the list. Returns the total number of objects held within the list.")]
[Input("list", "The list of objects to obtain the count from.")]
[Output("count", "The number of items in the list.")]
public static int Count<T>(this List<T> list)
{
return list.Count;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions Data_Engine/Versioning_60.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MessageForDeleted": {
"BH.Engine.Reflection.Query.Item(System.Object)": "This method was a fallback method which has been made private to avoid confusion in script use. The return value of this method is always set to 0, so if you were using this method in your script, please replace it with the value of 0."
}
}
68 changes: 0 additions & 68 deletions Reflection_Engine/Compute/SplitByIndicies.cs

This file was deleted.

64 changes: 0 additions & 64 deletions Reflection_Engine/Query/Count.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@
using System.Linq;
using Mono.Cecil;
using Mono.Reflection;
using BH.oM.Base.Attributes;
using System.ComponentModel;

namespace BH.Engine.Reflection
{
public static partial class Compute
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[PreviousVersion("6.0", "BH.Engine.Reflection.Compute.UnqualifiedName(System.String)")]
[Description("Obtain the unqualified name for a given qualified name from a type.")]
[Input("qualifiedName", "The qualified name to query the unqualified name from.")]
[Output("unqualifiedName", "The unqualified name for the given name.")]
public static string UnqualifiedName(string qualifiedName)
{
if (qualifiedName == null)
Expand Down Expand Up @@ -83,6 +89,33 @@ private static List<int> FindLevelZero(string text, char splitChar, char levelUp

return indices;
}

private static List<string> SplitByIndices(string text, List<int> indices)
{
if (text == null)
{
Base.Compute.RecordError("Cannot split a null string.");
return new List<string>();
}

if (indices == null)
{
Base.Compute.RecordWarning("The 'indices' input is null and was replaced by an empty list");
indices = new List<int>();
}

int previousIndex = 0;
List<string> result = new List<string>();

foreach (int index in indices.OrderBy(x => x))
{
result.Add(text.Substring(previousIndex, index - previousIndex));
previousIndex = index + 1;
}
result.Add(text.Substring(previousIndex));

return result;
}
}
}

Expand Down
22 changes: 16 additions & 6 deletions Reflection_Engine/Query/Url.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using BH.oM.Base.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

Expand All @@ -34,6 +35,9 @@ public static partial class Query
/**** Interface Methods ****/
/***************************************************/

[Description("Obtain the URL to the code of the given object. The URL returned will link directly to the source code for that object if it exists.")]
[Input("obj", "An object to obtain the URL for.")]
[Output("url", "The URL of the source code for the object. Null if no source code URL could be ascertained.")]
public static string IUrl(this object obj)
{
if (obj == null)
Expand All @@ -59,6 +63,9 @@ public static string IUrl(this object obj)
/**** Public Methods ****/
/***************************************************/

[Description("Obtain the URL to the code of the given type. The URL returned will link directly to the source code for that type if it exists.")]
[Input("type", "The type to obtain the URL for.")]
[Output("url", "The URL of the source code for the type. Null if no source code URL could be ascertained.")]
public static string Url(this Type type)
{
if (type == null)
Expand All @@ -68,15 +75,15 @@ public static string Url(this Type type)
if (ass == null)
return null;

AssemblyUrlAttribute att = ass.GetCustomAttribute<AssemblyUrlAttribute>();
AssemblyDescriptionAttribute att = ass.GetCustomAttribute<AssemblyDescriptionAttribute>();
if (att == null)
return null;

string url = att.Url;
string url = att.Description;
if (url == "")
return null;

List<string> path = new List<string>() { url, "blob/master/" };
List<string> path = new List<string>() { url, "blob/main/" };
path.Add(ass.GetName().Name);
path.AddRange(type.Namespace.Split('.').Skip(3));
if (type.IsEnum)
Expand All @@ -91,6 +98,9 @@ public static string Url(this Type type)

/***************************************************/

[Description("Obtain the URL to the code of the given method. The URL returned will link directly to the source code for that method if it exists.")]
[Input("method", "The method to obtain the URL for.")]
[Output("url", "The URL of the source code for the method. Null if no source code URL could be ascertained.")]
public static string Url(this MethodBase method)
{
if (method == null)
Expand All @@ -100,13 +110,13 @@ public static string Url(this MethodBase method)
if (ass == null)
return null;

AssemblyUrlAttribute att = ass.GetCustomAttribute<AssemblyUrlAttribute>();
AssemblyDescriptionAttribute att = ass.GetCustomAttribute<AssemblyDescriptionAttribute>();
if (att == null)
return null;

string url = att.Url;
string url = att.Description;

List<string> path = new List<string>() { url, "blob/master/" };
List<string> path = new List<string>() { url, "blob/main/" };
path.Add(ass.GetName().Name);
path.AddRange(method.DeclaringType.Namespace.Split('.').Skip(3));
path.Add(method.DeclaringType.Name);
Expand Down
5 changes: 5 additions & 0 deletions Reflection_Engine/Versioning_60.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MessageForDeleted": {
"BH.Engine.Reflection.Compute.SplitByIndices(System.String, System.Collections.Generic.List<System.Int32>)": "This method was assisting in the unqualified name query method. Usage of this method shows this method has not been used outside of the calling method, and so has been made private to avoid UI clutter. If this method is required again, please reach out to the development team."
}
}