Refactor exception class hierarchy for reduced footprint and faster application start
AssigneeInternational Busines Machines Corporation
InventorBerthold Martin Lebert
Life of this patent
Estimating the term…
Abstract
A method, system, and program product for removing exception classes that match a pattern is disclosed. Exception classes are searched for those of the exception classes that match that pattern. The parent classes of matched exception classes are refactored to accept an exception type argument. Code that throws the matched exceptions is rewritten by replacing the exception class with the parent class and adding a corresponding exception type. Code that catches the thrown exceptions is rewritten by changing a catch clause to catch a parent exception class and inserting a case statement for the exception type in that catch clause. The matched exception classes are removed.
Claims22
A method comprising:
- searching exception classes stored in computer memory for those of the exception classes that match a pattern;
- refactoring the parent classes of the matched exception classes to accept an exception type argument;
- rewriting a section of code that throws the matched exceptions by replacing the exception class with the parent class and adding a corresponding exception type;
- changing a list of thrown exceptions in a method declaration;
- rewriting a section of code that catches the thrown exceptions by changing a catch clause to catch a parent exception class and inserting a case statement for the exception type in that catch clause;
- and
- removing the matched exception classes;
- wherein the matched exception classes are refactored by:
- adding a public field that encodes a type of the exception;
- adding constructor methods that take the type of the exception as an argument;
- creating constants for each numeric exception type and using the constants with throwing and catching the exceptions;
- and
- creating an array with the name of the exception classes for use in the text representation of the exception classes.
A computer program product for removing exception classes, the computer program product including a non-transitory computer readable storage medium having computer readable code embodied therewith, the computer readable program code comprising:
- computer readable program code utilizing a computer processor to search exception classes for those of the exception classes that match a pattern;
- computer readable program code that refactors the parent classes of the matched exception classes to accept an exception type argument;
- computer readable program code that rewrites a section of code that throws the matched exceptions by replacing the exception class with the parent class and adding a corresponding exception type;
- computer readable program code that changes a list of thrown exceptions in a method declaration;
- computer readable program code that rewrites a section of code that catches the thrown exceptions by changing a catch clause to catch a parent excepting class and inserting a case statement for the exception type in that catch clause;
- and
- computer readable program code that removes the matched exception classes;
- wherein the matched exception classes are refactored by:
- adding a public field that encodes a type of the exception;
- adding constructor methods that take the type of the exception as an argument;
- creating constants for each numeric exception type and using the constants with throwing and catching the exceptions;
- and
- creating an array with the name of the exception classes for use in the text representation of the exception classes.
A system comprising:
- a computer including a computer processor for removing exception classes;
- and
- an exception class removing engine to remove exception classes, wherein the removing comprises:
- searching exception classes for those of the exception classes that match a pattern;
- refactoring the parent classes of the matched exception classes to accept an exception type argument;
- rewriting a section of code that throws the matched exceptions by replacing the exception class with the parent class and adding a corresponding exception type;
- changing a list of thrown exceptions in a method declaration;
- rewriting a section of code that catches the thrown exceptions by changing a catch clause to catch a parent exception class and inserting a case statement for the exception type in that catch clause;
- and
- removing the matched exception classes;
- wherein the matched exception classes are refactored by:
- adding a public field that encodes a type of the exception;
- adding constructor methods that take the type of the exception as an argument;
- creating constants for each numeric exception type and using the constants with throwing and catching the exceptions;
- and
- creating an array with the name of the exception classes for use in the text representation of the exception classes.
Dependencies are inferred from the claim text.