builtins.path and builtins.filterSource use a filter function which return boolean value.
If it returns true on a directory, the directory will be visited AND included into output
If it returns false on a directory, the directory will be NOT visited AND NOT included.
So a single bool is responsible for two actions.
There is no way to visit directory but exclude it from output.
Either builtins.filterSource (path: type: lib.hasSuffix ".java" path) ~/project
which do not visit directories
Or builtins.filterSource (path: type: type == "directory" || lib.hasSuffix ".java" path) ~/project
which includes all directory tree into produced output
There is nothing which work like find ~/project -type f -name '*.java'