# what projects use sun.misc.Unsafe in Java?
UnsafeProjects: output set of string;
# imports of sun.misc.Unsafe
UnsafeImport: output sum[string] of int;
# uses of sun.misc.Unsafe type
UnsafeType: output sum[string] of int;
# uses of Unsafe.getUnsafe() static method call
GetUnsafe: output sum[string] of int;
imported := false;
visit(input, visitor {
before node: CodeRepository -> {
# only look at the latest snapshot
# and only include Java files
snapshot := getsnapshot(node, "SOURCE_JAVA_JLS");
foreach (i: int; def(snapshot[i]))
visit(snapshot[i]);
stop;
}
before node: ASTRoot -> {
imported = false;
exists (i: int; node.imports[i] == "sun.misc.Unsafe" || node.imports[i] == "sun.misc.*") {
UnsafeImport[input.id] << 1;
UnsafeProjects << input.id;
imported = true;
}
}
before node: Type ->
if (node.name == "sun.misc.Unsafe" || (node.name == "Unsafe" && imported)) {
UnsafeType[input.id] << 1;
UnsafeProjects << input.id;
}
before node: Expression ->
if (node.kind == ExpressionKind.METHODCALL && node.method == "getUnsafe") {
GetUnsafe[input.id] << 1;
UnsafeProjects << input.id;
}
});