Class Util

java.lang.Object
de.fraunhofer.aisec.cpg.helpers.Util

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

    • Util

      public Util()
  • Method Details

    • subnodesOfCode

      public static java.util.List<de.fraunhofer.aisec.cpg.graph.Node> subnodesOfCode​(de.fraunhofer.aisec.cpg.graph.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.Connect cn, Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, Util.Connect cr, de.fraunhofer.aisec.cpg.graph.Node... refs)
    • eogConnect

      public static boolean eogConnect​(Util.Quantifier q, Util.Connect cn, Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, de.fraunhofer.aisec.cpg.graph.Node... refs)
    • eogConnect

      public static boolean eogConnect​(Util.Quantifier q, Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, Util.Connect cr, de.fraunhofer.aisec.cpg.graph.Node... refs)
    • eogConnect

      public static boolean eogConnect​(Util.Connect cn, Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, de.fraunhofer.aisec.cpg.graph.Node... refs)
    • eogConnect

      public static boolean eogConnect​(Util.Quantifier q, Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, de.fraunhofer.aisec.cpg.graph.Node... refs)
    • eogConnect

      public static boolean eogConnect​(Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, Util.Connect cr, de.fraunhofer.aisec.cpg.graph.Node... refs)
    • eogConnect

      public static boolean eogConnect​(Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, de.fraunhofer.aisec.cpg.graph.Node... refs)
    • eogConnect

      public static boolean eogConnect​(Util.Quantifier q, Util.Connect cn, Util.Edge en, de.fraunhofer.aisec.cpg.graph.Node n, Util.Connect cr, de.fraunhofer.aisec.cpg.graph.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)
    • warnWithFileLocation

      public static <S> void warnWithFileLocation​(@NonNull LanguageFrontend lang, S astNode, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)
    • errorWithFileLocation

      public static <S> void errorWithFileLocation​(@NonNull LanguageFrontend lang, S astNode, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)
    • warnWithFileLocation

      public static void warnWithFileLocation​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)
    • errorWithFileLocation

      public static void errorWithFileLocation​(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)
    • splitLeavingParenthesisContents

      public static java.util.List<java.lang.String> splitLeavingParenthesisContents​(java.lang.String toSplit, java.lang.String delimiters)
      Split a String into multiple parts by using one or more delimiter characters. Any delimiters that are surrounded by matching opening and closing brackets are skipped. E.g. "a,(b,c)" will result in a list containing "a" and "(b,c)" when splitting on commas. Empty parts are ignored, so when splitting "a,,,,(b,c)", the same result is returned as in the previous example.
      Parameters:
      toSplit - The input String
      delimiters - A String containing all characters that should be treated as delimiters
      Returns:
      A list of all parts of the input, as divided by any delimiter
    • removeRedundantParentheses

      public static java.lang.String removeRedundantParentheses​(java.lang.String original)
      Removes pairs of parentheses that do not provide any further separation. E.g. "(foo)" results in "foo" and "(((foo))((bar)))" in "(foo)(bar)", whereas "(foo)(bar)" stays the same.
      Parameters:
      original - The String to clean
      Returns:
      The modified version without excess parentheses
    • containsOnOuterLevel

      public static boolean containsOnOuterLevel​(java.lang.String input, char marker)
    • attachCallParameters

      public static void attachCallParameters​(FunctionDeclaration target, java.util.List<Expression> arguments)
      Establish dataflow from call arguments to the target FunctionDeclaration parameters
      Parameters:
      target - The call's target FunctionDeclaration
      arguments - The call's arguments to be connected to the target's parameters
    • getSimpleName

      public static java.lang.String getSimpleName​(java.lang.String delimiter, java.lang.String name)
    • detachCallParameters

      public static void detachCallParameters​(FunctionDeclaration target, java.util.List<Expression> arguments)
      Parameters:
      target -
      arguments -
    • createInferredParameters

      public static java.util.List<ParamVariableDeclaration> createInferredParameters​(java.util.List<Type> signature)
    • 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.
    • getAdjacentDFGNodes

      public static java.util.List<de.fraunhofer.aisec.cpg.graph.Node> getAdjacentDFGNodes​(de.fraunhofer.aisec.cpg.graph.Node n, boolean incoming)
      This function returns the set of adjacent DFG nodes that is contained in the nodes subgraph.
      Parameters:
      n - Node of interest
      incoming - whether the node connected by an incoming or, if false, outgoing DFG edge
      Returns:
    • addDFGEdgesForMutuallyExclusiveBranchingExpression

      public static void addDFGEdgesForMutuallyExclusiveBranchingExpression​(de.fraunhofer.aisec.cpg.graph.Node n, de.fraunhofer.aisec.cpg.graph.Node branchingExp, de.fraunhofer.aisec.cpg.graph.Node branchingDecl)
      Connects the node n with the node branchingExp if present or with the node branchingDecl. The assumption is that only branchingExp or branchingDecl are present, e.g. C++.
      Parameters:
      n -
      branchingExp -
      branchingDecl -