Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Jul 23, 2024
1 parent 3f50938 commit b433ec3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@
import com.sun.tools.javac.tree.JCTree;
import edu.ucr.cs.riple.taint.ucrtainting.handlers.UnannotatedCodeHandler;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.SerializationService;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.location.ClassDeclarationLocation;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.visitors.LocationToJsonVisitor;
import java.io.FileWriter;
import java.io.IOException;
import org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey;
import org.checkerframework.common.accumulation.AccumulationChecker;
import org.checkerframework.framework.qual.StubFiles;
import org.checkerframework.framework.source.SupportedOptions;
import org.checkerframework.framework.type.AnnotatedTypeMirror;
import org.checkerframework.javacutil.TreeUtils;
import org.json.JSONObject;

/** This is the entry point for pluggable type-checking. */
@StubFiles({
Expand Down Expand Up @@ -310,4 +315,18 @@ private boolean shouldBeSkippedForAnnotationMemberSelection(Object source) {
Symbol.ClassSymbol owner = fieldAccess.sym.enclClass();
return owner != null && owner.isAnnotationType();
}

public void serializeClassDeclaration(ClassDeclarationLocation location, FoundRequired pair) {
JSONObject ans = new JSONObject();
ans.put("pair", pair.toString());
ans.put("location", new LocationToJsonVisitor().visitClassDeclaration(location, null));
ans.put("tree", visitor.getCurrentPath().getLeaf().toString());
ans.put("file", visitor.getCurrentPath().getCompilationUnit().getSourceFile().getName());
// append to file /tmp/class_decl.json with try-resources
try (FileWriter file = new FileWriter("/tmp/class_decl.json", true)) {
file.write(ans.toString());
} catch (IOException e) {
System.err.println("Error writing to file");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.sun.tools.javac.util.Context;
import edu.ucr.cs.riple.taint.ucrtainting.FoundRequired;
import edu.ucr.cs.riple.taint.ucrtainting.UCRTaintingAnnotatedTypeFactory;
import edu.ucr.cs.riple.taint.ucrtainting.UCRTaintingChecker;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.Fix;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.TypeIndex;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.location.ClassDeclarationLocation;
Expand Down Expand Up @@ -270,7 +271,9 @@ public static Set<Fix> computeFixesOnClassDeclarationForRawType(
ClassDeclarationLocation classDeclarationLocation =
new ClassDeclarationLocation(classType, inheritedType);
classDeclarationLocation.setTypeIndexSet(TypeIndex.setOf(index + 1, 0));
return Set.of(new Fix(classDeclarationLocation));
((UCRTaintingChecker) typeFactory.getChecker())
.serializeClassDeclaration(classDeclarationLocation, pair);
return Set.of();
} catch (Exception e) {
return Set.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.sun.tools.javac.util.Context;
import edu.ucr.cs.riple.taint.ucrtainting.FoundRequired;
import edu.ucr.cs.riple.taint.ucrtainting.UCRTaintingAnnotatedTypeFactory;
import edu.ucr.cs.riple.taint.ucrtainting.UCRTaintingChecker;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.Fix;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.TypeIndex;
import edu.ucr.cs.riple.taint.ucrtainting.serialization.location.ClassDeclarationLocation;
Expand Down Expand Up @@ -122,9 +123,9 @@ public Fix buildFixForElement(Element element, FoundRequired pair) {
classDeclarationLocation.setTypeIndexSet(
untaintedTypeMatchVisitor.visit(annotatedDeclaredType, pair.required, null));
});
return classDeclarationLocation.getTypeIndexSet().isEmpty()
? null
: new Fix(classDeclarationLocation);
((UCRTaintingChecker) typeFactory.getChecker())
.serializeClassDeclaration(classDeclarationLocation, pair);
return null;
}
AnnotatedTypeMirror elementAnnotatedType = typeFactory.getAnnotatedType(element);
// remove redundant indices.
Expand Down

0 comments on commit b433ec3

Please sign in to comment.