Package de.fraunhofer.aisec.cpg.helpers
Class Util
- java.lang.Object
-
- de.fraunhofer.aisec.cpg.helpers.Util
-
public class Util extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtil.Connectstatic classUtil.Edgestatic classUtil.Quantifier
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.function.Predicate<T>distinctBy(java.util.function.Function<? super T,?> by)static <T> java.util.function.Predicate<T>distinctByIdentity()static booleaneogConnect(Util.Connect cn, Util.Edge en, Node n, Node... refs)static booleaneogConnect(Util.Connect cn, Util.Edge en, Node n, Util.Connect cr, Node... refs)static booleaneogConnect(Util.Edge en, Node n, Node... refs)static booleaneogConnect(Util.Edge en, Node n, Util.Connect cr, Node... refs)static booleaneogConnect(Util.Quantifier q, Util.Connect cn, Util.Edge en, Node n, Node... refs)static booleaneogConnect(Util.Quantifier q, Util.Connect cn, Util.Edge en, Node n, Util.Connect cr, Node... refs)Checks if the Nodenconnects to the nodes inrefsover the CPGS EOG graph edges that depict the evaluation order.static booleaneogConnect(Util.Quantifier q, Util.Edge en, Node n, Node... refs)static booleaneogConnect(Util.Quantifier q, Util.Edge en, Node n, Util.Connect cr, Node... refs)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 typeList.static java.lang.StringgetExtension(@NonNull java.io.File file)static java.lang.StringinputStreamToString(java.io.InputStream inputStream)static java.util.List<Node>subnodesOfCode(Node node, java.lang.String searchCode)Filters the nodes in the AST subtree at rootnodefor Nodes with the specified code.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.static <S extends Node>
java.util.List<S>subnodesOfType(java.util.Collection<? extends Node> roots, java.lang.Class<S> specificClass)
-
-
-
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 typeList.- 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 subtreespecificClass- 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 rootnodefor 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.Connect cn, Util.Edge en, Node n, Util.Connect cr, Node... refs)
-
eogConnect
public static boolean eogConnect(Util.Quantifier q, Util.Connect cn, Util.Edge en, Node n, Node... refs)
-
eogConnect
public static boolean eogConnect(Util.Quantifier q, Util.Edge en, Node n, Util.Connect cr, Node... refs)
-
eogConnect
public static boolean eogConnect(Util.Connect cn, Util.Edge en, Node n, Node... refs)
-
eogConnect
public static boolean eogConnect(Util.Quantifier q, Util.Edge en, Node n, Node... refs)
-
eogConnect
public static boolean eogConnect(Util.Edge en, Node n, Util.Connect cr, 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 Nodenconnects to the nodes inrefsover 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 SUBTREEen- - The Edge direction and therefore the borders of n to connect to refsn- - Node of interestcr- - NODE if refs nodes itself are the nodes to connect or SUBTREE if the EOG borders are of interestrefs- - 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)
-
-