forked from paulirwin/JavaToCSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensions.cs
More file actions
48 lines (41 loc) · 1.57 KB
/
Copy pathExtensions.cs
File metadata and controls
48 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using JavaAst = com.github.javaparser.ast;
namespace JavaToCSharp
{
public static class Extensions
{
/// <summary>
/// Converts a Java Iterable to a .NET IEnumerable<T> and filters the elements of type T.
/// </summary>
/// <typeparam name="T">Type of items to be returned.</typeparam>
/// <param name="iterable">The java Iterable to be enumerated.</param>
/// <returns>A filtered enumeration of items of type T</returns>
public static IEnumerable<T> OfType<T>(this java.lang.Iterable iterable)
{
var iterator = iterable.iterator();
while (iterator.hasNext())
{
if (iterator.next() is T item)
{
yield return item;
}
}
}
public static List<T> ToList<T>(this java.util.List list)
{
if (list == null)
return null;
var newList = new List<T>();
for (int i = 0; i < list.size(); i++)
{
newList.Add((T)list.get(i));
}
return newList;
}
public static bool HasFlag<T>(this java.util.EnumSet values, T flag) => values.contains(flag);
public static TSyntax WithJavaComments<TSyntax>(this TSyntax syntax, JavaAst.Node node, string singleLineCommentEnd = null)
where TSyntax : SyntaxNode =>
CommentsHelper.AddCommentsTrivias(syntax, node, singleLineCommentEnd);
}
}