Skip to content

Commit

Permalink
add BlockStmt and @nullable for IfStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
LoiNguyenCS committed Oct 26, 2023
1 parent 4292f41 commit b44badd
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.github.javaparser.ast.expr.ObjectCreationExpr;
import com.github.javaparser.ast.expr.SimpleName;
import com.github.javaparser.ast.expr.SwitchExpr;
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.stmt.CatchClause;
import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
import com.github.javaparser.ast.stmt.ForStmt;
Expand Down Expand Up @@ -51,6 +52,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.Stack;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.signature.qual.ClassGetSimpleName;
import org.checkerframework.checker.signature.qual.DotSeparatedIdentifiers;
import org.checkerframework.checker.signature.qual.FullyQualifiedName;
Expand Down Expand Up @@ -320,10 +322,6 @@ public Visitable visit(ForStmt node, Void p) {
}

@Override
@SuppressWarnings(
"nullness") // this method could return null, and the setElstStmt method could accept a null
// value as parameter. So this SupressWarnings is to avoid the complains of
// CheckerFramework
public Visitable visit(IfStmt n, Void arg) {
HashSet<String> localVarInCon = new HashSet<>();
localVariables.push(localVarInCon);
Expand All @@ -337,9 +335,15 @@ public Visitable visit(IfStmt n, Void arg) {
localVariables.push(localVarInCon);
Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg);
localVariables.pop();
if (condition == null || thenStmt == null) return null;
if (condition == null || thenStmt == null) {
return null;
}
n.setCondition(condition);
n.setElseStmt(elseStmt);
@SuppressWarnings(
"nullness") // elseStmt could actually be null, according to the document of setElseStmt.
// This part is to avoid the false warnings of Checker Framework
@NonNull Statement nullableElseStme = elseStmt;
n.setElseStmt(nullableElseStme);
n.setThenStmt(thenStmt);
return n;
}
Expand Down Expand Up @@ -389,6 +393,15 @@ public Visitable visit(CatchClause node, Void p) {
return node;
}

@Override
public Visitable visit(BlockStmt node, Void p) {
HashSet<String> currentLocalVariables = new HashSet<>();
localVariables.push(currentLocalVariables);
super.visit(node, p);
localVariables.pop();
return node;
}

@Override
public Visitable visit(VariableDeclarator decl, Void p) {
// if there is no list of local variables, then the current VariableDeclarator visited is a
Expand Down

0 comments on commit b44badd

Please sign in to comment.