Make source file baby parser fails silently

Summary:
The java source file parser should refuse to run on non
.java file. Also, as we expect some autogenerated source files to
break Java official syntax, we catch parsing error silently and
cancel location recording for them.

Reviewed By: jvillard

Differential Revision: D21089587

fbshipit-source-id: 35f1a1e28
master
David Pichardie 5 years ago committed by Facebook GitHub Bot
parent d30b0959a1
commit ccb2d23c5b

@ -372,7 +372,9 @@ and skip_comments action = parse
(** We scan source file [file] and record location of each class declaration *)
let collect_class_location (program:JClasspath.program) (file:SourceFile.t) =
let cin = In_channel.create (SourceFile.to_abs_path file) in
let path = SourceFile.to_abs_path file in
if String.is_suffix path ~suffix:".java" then (
let cin = In_channel.create path in
let stack = [] in
let record_location ~classname ~col ~line =
let loc : Location.t = { line; col; file } in
@ -385,17 +387,18 @@ and skip_comments action = parse
In_channel.close cin )
with
| Failure s ->
raise
(Failure
(Printf.sprintf "Error parsing source file %s\n%s" (SourceFile.to_abs_path file) s))
Logging.debug Capture Verbose "Error parsing source file %s\n%s"
(SourceFile.to_abs_path file) s;
In_channel.close cin
| Missing_opening_bracket ->
raise
(Failure (Printf.sprintf "Missing opening bracket error while parsing source file %s\n"
(SourceFile.to_abs_path file)))
Logging.debug Capture Verbose
"Missing opening bracket error while parsing source file %s\n"
(SourceFile.to_abs_path file);
In_channel.close cin
| Missing_opening_parenthesis ->
raise
(Failure
(Printf.sprintf "Missing opening parenthesis error while parsing source file %s\n"
(SourceFile.to_abs_path file)))
Logging.debug Capture Verbose
"Missing opening parenthesis error while parsing source file %s\n"
(SourceFile.to_abs_path file);
In_channel.close cin
)
}

Loading…
Cancel
Save