Class Util


  • public class Util
    extends java.lang.Object
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • filterCast

        public static <T,​S extends T> java.util.List<S> filterCast​(java.util.List<T> genericList,
                                                                         java.lang.Class<S> specificClass)
        Filters a list of elements with common type T for all elements of instance S, returning a list of type List.
        Type Parameters:
        T - Generic List type.
        S - Class type to filter for.
        Parameters:
        genericList - List with elements fo type T.
        specificClass - Class type to filter for.
        Returns:
        a specific List as all elements are cast to the specified class type.
      • subnodesOfType

        public static <S extends Node> java.util.List<S> subnodesOfType​(Node node,
                                                                        java.lang.Class<S> specificClass)
        Given a root node in the AST graph, all AST children of the node are filtered for a specific CPG Node type and returned.
        Type Parameters:
        S - Type variable that allows returning a list of specific type
        Parameters:
        node - root of the searched AST subtree
        specificClass - Class type to be searched for
        Returns:
        a List of searched types
      • subnodesOfType

        public static <S extends Node> java.util.List<S> subnodesOfType​(java.util.Collection<? extends Node> roots,
                                                                        java.lang.Class<S> specificClass)
      • subnodesOfCode

        public static java.util.List<Node> subnodesOfCode​(Node node,
                                                          java.lang.String searchCode)
        Filters the nodes in the AST subtree at root node for Nodes with the specified code.
        Parameters:
        node - root of the subtree that is searched.
        searchCode - exact code that a node needs to have.
        Returns:
        a list of nodes with the specified String.
      • eogConnect

        public static boolean eogConnect​(Util.Edge en,
                                         Node n,
                                         Node... refs)
      • eogConnect

        public static boolean eogConnect​(Util.Quantifier q,
                                         Util.Connect cn,
                                         Util.Edge en,
                                         Node n,
                                         Util.Connect cr,
                                         Node... refs)
        Checks if the Node n connects to the nodes in refs over the CPGS EOG graph edges that depict the evaluation order. The parameter q defines if all edges of interest to node must connect to an edge in refs or one is enough, cn and cr define whether the passed AST nodes themselves are used to search the connections or the EOG Border nodes in the AST subnode. Finally, en defines whether the EOG edges go * from n to r in refs or the inverse.
        Parameters:
        q - - The quantifier, all or any node of n must connect to refs, defaults to ALL.
        cn - - NODE if n itself is the node to connect or SUBTREE if the EOG borders are of interest. Defaults to SUBTREE
        en - - The Edge direction and therefore the borders of n to connect to refs
        n - - Node of interest
        cr - - NODE if refs nodes itself are the nodes to connect or SUBTREE if the EOG borders are of interest
        refs - - Multiple reference nodes that can be passed as varargs
        Returns:
        true if all/any of the connections from node connect to n.
      • inputStreamToString

        public static java.lang.String inputStreamToString​(java.io.InputStream inputStream)
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • distinctByIdentity

        public static <T> java.util.function.Predicate<T> distinctByIdentity()
      • distinctBy

        public static <T> java.util.function.Predicate<T> distinctBy​(java.util.function.Function<? super T,​?> by)
      • getExtension

        public static java.lang.String getExtension​(@NonNull java.io.File file)