using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using JavaAst = com.github.javaparser.ast;
namespace JavaToCSharp
{
public static class Extensions
{
///
/// Converts a Java Iterable to a .NET IEnumerable<T> and filters the elements of type T.
///
/// Type of items to be returned.
/// The java Iterable to be enumerated.
/// A filtered enumeration of items of type T
public static IEnumerable OfType(this java.lang.Iterable iterable)
{
var iterator = iterable.iterator();
while (iterator.hasNext())
{
if (iterator.next() is T item)
{
yield return item;
}
}
}
public static List ToList(this java.util.List list)
{
if (list == null)
return null;
var newList = new List();
for (int i = 0; i < list.size(); i++)
{
newList.Add((T)list.get(i));
}
return newList;
}
public static bool HasFlag(this java.util.EnumSet values, T flag) => values.contains(flag);
public static TSyntax WithJavaComments(this TSyntax syntax, JavaAst.Node node, string singleLineCommentEnd = null)
where TSyntax : SyntaxNode =>
CommentsHelper.AddCommentsTrivias(syntax, node, singleLineCommentEnd);
}
}