summaryrefslogtreecommitdiff
path: root/tools/aapt2/java/JavaClassGenerator_test.cpp
diff options
context:
space:
mode:
authorWinson <chiuwinson@google.com>2020-01-28 09:58:43 -0800
committerWinson <chiuwinson@google.com>2020-02-19 08:23:01 -0800
commit3dc4af47691882801c6e2ad6b5410498953a1ec7 (patch)
tree7a95b60213d34e7682148a4e7dadca2c3469c1dc /tools/aapt2/java/JavaClassGenerator_test.cpp
parent33eacc6c05f52e12990e54b61e1534d6ee794961 (diff)
Add ParseResult infrastructure
ParseInput is passed into all parsing methods and simply acts as a shared container which can hold a generic success or error value. When it is transformed into a result value, it must be returned to its parent immediately, who can decide what to do with it. ParseResult is the type returned when a ParseInput is set to success or error. It casts itself to a strong type representing the returned value, and is used by specifying ParseResult<ResultType> instead of just ResultType for the method return type. ParseTypeImpl is just the implementation of the two above which handles moving between them. It also adds some debug functionality in case the error catching code is incorrect or insufficient and it would be preferably to always have a stack trace. It is important to use this infrastructure in a thread-local manner, such that you don't re-use an input already in use and always bubble up on any success or error. A constrained example: class Parser { val shared = ParseTypeImpl<>() fun parse(file: File): Pair<Output, Output> { // Reset the shared object val input = shared.reset() // Pass it to be used by the parsing method var result = parseOutput(input, file.read()) // Verify the result if (result.isError()) { // Bubble up error if necessary throw Exception(result.errorMessage, result.exception) } // Save the result (as it will be lost when the input is reused) val one = result.result // Parse something else result = parseOutput(input, file.read()) // Same verification if (result.isError()) { // Bubble up error if necessary throw Exception(result.errorMessage, result.exception) } val two = result.result return one to two } fun parseOutput(input: Input, read: Object): ParseResult<Output> { return if (read == null) { input.error("Something went wrong") } else { input.success(read) } } } Bug: 135203078 Change-Id: I532d0047e67f80fd925b481dac8823ab45ad0194
Diffstat (limited to 'tools/aapt2/java/JavaClassGenerator_test.cpp')
0 files changed, 0 insertions, 0 deletions