From 14ea7925b60771c2103f3837af39be0266c2adc7 Mon Sep 17 00:00:00 2001 From: Julian Schuette Date: Thu, 13 Aug 2020 16:39:18 +0200 Subject: [PATCH] Handle annotations equivalent to nextEog/nextDfg --- .../cpg/frontends/cpp/CXXLanguageFrontend.java | 2 +- .../aisec/cpg/graph/ConstructorDeclaration.java | 2 +- .../aisec/cpg/graph/MethodDeclaration.java | 3 ++- .../java/de/fraunhofer/aisec/cpg/graph/Node.java | 13 ++++--------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java b/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java index 4f1e2bd0e4..5cfe36af01 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java @@ -372,7 +372,7 @@ public PhysicalLocation getLocationFromRawNode(T astNode) { public void processAttributes(@NonNull Node node, @NonNull IASTAttributeOwner owner) { if (this.config.processAnnotations) { // set attributes - node.setAnnotations(handleAttributes(owner)); + node.addAnnotations(handleAttributes(owner)); } } diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java index 816a2a126e..7a6efb08bd 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java @@ -55,7 +55,7 @@ public static ConstructorDeclaration from(MethodDeclaration methodDeclaration) { c.setBody(methodDeclaration.getBody()); c.setLocation(methodDeclaration.getLocation()); c.setParameters(methodDeclaration.getParameters()); - c.setAnnotations(methodDeclaration.getAnnotations()); + c.addAnnotations(methodDeclaration.getAnnotations()); c.setIsDefinition(methodDeclaration.isDefinition()); if (!c.isDefinition()) { diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java index 20361ebbd1..f1f8456d08 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java @@ -59,7 +59,7 @@ public static MethodDeclaration from( md.setParameters(functionDeclaration.getParameters()); md.setBody(functionDeclaration.getBody()); md.setType(functionDeclaration.getType()); - md.setAnnotations(functionDeclaration.getAnnotations()); + md.addAnnotations(functionDeclaration.getAnnotations()); md.setRecordDeclaration(recordDeclaration); md.setIsDefinition(functionDeclaration.isDefinition()); @@ -80,6 +80,7 @@ public void setStatic(boolean isStatic) { this.isStatic = isStatic; } + @Nullable public RecordDeclaration getRecordDeclaration() { return recordDeclaration; } diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java index 21cf2a0875..e468976451 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java @@ -29,11 +29,7 @@ import de.fraunhofer.aisec.cpg.helpers.LocationConverter; import de.fraunhofer.aisec.cpg.processing.IVisitable; import de.fraunhofer.aisec.cpg.sarif.PhysicalLocation; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; +import java.util.*; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.checkerframework.checker.nullness.qual.NonNull; @@ -96,8 +92,7 @@ public class Node extends IVisitable { @Relationship(value = "DFG") protected Set nextDFG = new HashSet<>(); - @NonNull - protected Set typedefs = new HashSet<>(); + @NonNull protected Set typedefs = new HashSet<>(); /** * If a node is marked as being a dummy, it means that it was created artificially and does not @@ -272,8 +267,8 @@ public List getAnnotations() { return annotations; } - public void setAnnotations(@NonNull List annotations) { - this.annotations = annotations; + public void addAnnotations(@NonNull Collection annotations) { + this.annotations.addAll(annotations); } /**