Skip to content

Commit

Permalink
Merge pull request #193 from Fraunhofer-AISEC/fix/null-annotations
Browse files Browse the repository at this point in the history
Fix for null annotations
  • Loading branch information
JulianSchuette authored Aug 13, 2020
2 parents e3f4db4 + 14ea792 commit f2f4f85
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public <T> 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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -80,6 +80,7 @@ public void setStatic(boolean isStatic) {
this.isStatic = isStatic;
}

@Nullable
public RecordDeclaration getRecordDeclaration() {
return recordDeclaration;
}
Expand Down
42 changes: 23 additions & 19 deletions src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +70,7 @@ public class Node extends IVisitable<Node> {
protected String file;

/** Incoming control flow edges. */
@NonNull
@Relationship(value = "EOG", direction = "INCOMING")
protected List<Node> prevEOG = new ArrayList<>();

Expand All @@ -87,13 +84,15 @@ public class Node extends IVisitable<Node> {
@Relationship(value = "CFG", direction = "OUTGOING")
protected List<Node> nextCFG = new ArrayList<>();

@NonNull
@Relationship(value = "DFG", direction = "INCOMING")
protected Set<Node> prevDFG = new HashSet<>();

@NonNull
@Relationship(value = "DFG")
protected Set<Node> nextDFG = new HashSet<>();

protected Set<TypedefDeclaration> typedefs = new HashSet<>();
@NonNull protected Set<TypedefDeclaration> typedefs = new HashSet<>();

/**
* If a node is marked as being a dummy, it means that it was created artificially and does not
Expand All @@ -116,7 +115,7 @@ public class Node extends IVisitable<Node> {

/** List of annotations associated with that node. */
@SubGraph("AST")
protected List<Annotation> annotations;
protected List<Annotation> annotations = new ArrayList<>();

public Long getId() {
return id;
Expand Down Expand Up @@ -156,11 +155,12 @@ public void setLocation(@Nullable PhysicalLocation location) {
this.location = location;
}

@NonNull
public List<Node> getPrevEOG() {
return this.prevEOG;
}

public void setPrevEOG(List<Node> prevEOG) {
public void setPrevEOG(@NonNull List<Node> prevEOG) {
this.prevEOG = prevEOG;
}

Expand All @@ -178,11 +178,12 @@ public List<Node> getNextCFG() {
return this.nextCFG;
}

@NonNull
public Set<Node> getNextDFG() {
return nextDFG;
}

public void setNextDFG(Set<Node> nextDFG) {
public void setNextDFG(@NonNull Set<Node> nextDFG) {
this.nextDFG = nextDFG;
}

Expand All @@ -198,11 +199,12 @@ public void removeNextDFG(Node next) {
}
}

@NonNull
public Set<Node> getPrevDFG() {
return prevDFG;
}

public void setPrevDFG(Set<Node> prevDFG) {
public void setPrevDFG(@NonNull Set<Node> prevDFG) {
this.prevDFG = prevDFG;
}

Expand All @@ -222,11 +224,12 @@ public void addTypedef(TypedefDeclaration typedef) {
this.typedefs.add(typedef);
}

@NonNull
public Set<TypedefDeclaration> getTypedefs() {
return typedefs;
}

public void setTypedefs(Set<TypedefDeclaration> typedefs) {
public void setTypedefs(@NonNull Set<TypedefDeclaration> typedefs) {
this.typedefs = typedefs;
}

Expand Down Expand Up @@ -259,6 +262,15 @@ public boolean isImplicit() {
return this.implicit;
}

@NonNull
public List<Annotation> getAnnotations() {
return annotations;
}

public void addAnnotations(@NonNull Collection<Annotation> annotations) {
this.annotations.addAll(annotations);
}

/**
* If a node should be removed from the graph, just removing it from the AST is not enough (see
* issue #60). It will most probably be referenced somewhere via DFG or EOG edges. Thus, if it
Expand Down Expand Up @@ -326,12 +338,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(name, this.getClass());
}

public void setAnnotations(List<Annotation> annotations) {
this.annotations = annotations;
}

public List<Annotation> getAnnotations() {
return annotations;
}
}

0 comments on commit f2f4f85

Please sign in to comment.