I'm currently working on some legacy Java code and need to
do some refactoring on it.
That is a string parsing task. The original program treats
the input message step by step, in another word, word by word.
When some formatting errors occur, the program tries to log
the problem.
What I want to do is extracting all logging code from the source,
because there are too many trivial statements for logging.
And I want to normalize these logs.
1. warning, continue
2. error, stop there and return true
3. error, stop and return false
I'm going to introduce a ParsingException and ParsingErrorMessage.
ParsingErrorMessage is a class working as a Linked List,
which has the following fields:
1. The original message
2. The current substring
3. The message type ( error or warning or others )
4. The position
5. The error/warning message to log
When an error occurs, I throw a ParsingException and catch it somewhere.
I think I will finally introduce regex into it.
However, because the programmer of the old project
was familiar with regex, I believe there could
be something here not suitable to use regex.
I'll discuss this with him later when he has time.
What I'm thinking is:
1. normalizing the output message.
2. reducing trivial code.
3. having a better structure or processing flow.
4. extracting some reusable components and applying some OOP philosophies.