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 voidaddDFGEdgesForMutuallyExclusiveBranchingExpression(Node n, Node branchingExp, Node branchingDecl)Connects the nodenwith the nodebranchingExpif present or with the nodebranchingDecl.static voidattachCallParameters(FunctionDeclaration target, java.util.List<Expression> arguments)Establish dataflow from call arguments to the targetFunctionDeclarationparametersstatic booleancontainsOnOuterLevel(java.lang.String input, char marker)static java.util.List<ParamVariableDeclaration>createParameters(java.util.List<Type> signature)static voiddetachCallParameters(FunctionDeclaration target, java.util.List<Expression> arguments)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 <S> voiderrorWithFileLocation(@NonNull LanguageFrontend lang, S astNode, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)static voiderrorWithFileLocation(@NonNull Node node, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)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.util.List<Node>getAdjacentDFGNodes(Node n, boolean incoming)This function returns the set of adjacent DFG nodes that is contained in the nodes subgraph.static java.lang.StringgetExtension(@NonNull java.io.File file)static java.lang.StringgetSimpleName(java.lang.String delimiter, java.lang.String name)static java.lang.StringinputStreamToString(java.io.InputStream inputStream)static java.lang.StringremoveRedundantParentheses(java.lang.String original)Removes pairs of parentheses that do not provide any further separation.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.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> voidwarnWithFileLocation(@NonNull LanguageFrontend lang, S astNode, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)static voidwarnWithFileLocation(@NonNull Node node, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)
-
-
-
Method Detail
-
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)
-
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 Node node, org.slf4j.Logger log, java.lang.String format, java.lang.Object... arguments)
-
errorWithFileLocation
public static void errorWithFileLocation(@NonNull 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 Stringdelimiters- 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 targetFunctionDeclarationparameters- Parameters:
target- The call's targetFunctionDeclarationarguments- 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)
Inverse operation ofattachCallParameters(de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration, java.util.List<de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression>)- Parameters:
target-arguments-
-
createParameters
public static java.util.List<ParamVariableDeclaration> createParameters(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 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.
-
getAdjacentDFGNodes
public static java.util.List<Node> getAdjacentDFGNodes(Node n, boolean incoming)
This function returns the set of adjacent DFG nodes that is contained in the nodes subgraph.- Parameters:
n- Node of interestincoming- whether the node connected by an incoming or, if false, outgoing DFG edge- Returns:
-
addDFGEdgesForMutuallyExclusiveBranchingExpression
public static void addDFGEdgesForMutuallyExclusiveBranchingExpression(Node n, Node branchingExp, Node branchingDecl)
Connects the nodenwith the nodebranchingExpif present or with the nodebranchingDecl. The assumption is that onlybranchingExporbranchingDeclare present, e.g. C++.- Parameters:
n-branchingExp-branchingDecl-
-
-