| 1 | /* | |
| 2 | * Copyright 2004 the original author or authors. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package com.ancientprogramming.fixedformat4j.format; | |
| 17 | ||
| 18 | import com.ancientprogramming.fixedformat4j.exception.FixedFormatException; | |
| 19 | ||
| 20 | import java.lang.reflect.Method; | |
| 21 | ||
| 22 | /** | |
| 23 | * Used in cases where data couldn't be parse according to the {@link FormatContext} and {@link FormatInstructions}. | |
| 24 | * | |
| 25 | * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> | |
| 26 | * @since 1.2.0 | |
| 27 | */ | |
| 28 | public class ParseException extends FixedFormatException { | |
| 29 | ||
| 30 | private String completeText; | |
| 31 | private String failedText; | |
| 32 | private Class<?> annotatedClass; | |
| 33 | private Method annotatedMethod; | |
| 34 | private FormatContext<?> formatContext; | |
| 35 | private FormatInstructions formatInstructions; | |
| 36 | ||
| 37 | /** | |
| 38 | * Create an new instance | |
| 39 | * @param completeText the complete text that failed to be parsed | |
| 40 | * @param failedText the part of the complete text that failed the actual parsing according to the {@link #getFormatInstructions()} | |
| 41 | * @param annotatedClass the Class containing the fixedformat annotations | |
| 42 | * @param annotatedMethod the method containing the annotations that was used to trying to parse the text in {@link #getFailedText()} | |
| 43 | * @param formatContext the context within the parsing was tried | |
| 44 | * @param formatInstructions The format instructions used to try parsing the text in {@link #getFailedText()} | |
| 45 | * @param cause the reason why the data couldn't be parsed | |
| 46 | */ | |
| 47 | public ParseException(String completeText, String failedText, Class<?> annotatedClass, Method annotatedMethod, FormatContext<?> formatContext, FormatInstructions formatInstructions, Throwable cause) { | |
| 48 | super(String.format("Failed to parse '%s' at offset %d as %s from '%s'. Got format instructions from %s.%s. See details{%s, %s}", | |
| 49 | failedText, formatContext.getOffset(), formatContext.getDataType().getName(), completeText, | |
| 50 | annotatedClass.getName(), annotatedMethod.getName(), formatContext, formatInstructions), cause); | |
| 51 | this.completeText = completeText; | |
| 52 | this.failedText = failedText; | |
| 53 | this.annotatedClass = annotatedClass; | |
| 54 | this.annotatedMethod = annotatedMethod; | |
| 55 | this.formatContext = formatContext; | |
| 56 | this.formatInstructions = formatInstructions; | |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * Contains the complete text that failed to be parsed | |
| 61 | * @return String containing the complete text | |
| 62 | */ | |
| 63 | public String getCompleteText() { | |
| 64 |
1
1. getCompleteText : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/ParseException::getCompleteText → KILLED |
return completeText; |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * The part of the complete text that failed the actual parsing according to the {@link #getFormatInstructions()} | |
| 69 | * @return String containing the part that failed | |
| 70 | */ | |
| 71 | public String getFailedText() { | |
| 72 |
1
1. getFailedText : replaced return value with "" for com/ancientprogramming/fixedformat4j/format/ParseException::getFailedText → KILLED |
return failedText; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * The Class containing the fixedformat annotations | |
| 77 | * @return the Class | |
| 78 | */ | |
| 79 | public Class<?> getAnnotatedClass() { | |
| 80 |
1
1. getAnnotatedClass : replaced return value with null for com/ancientprogramming/fixedformat4j/format/ParseException::getAnnotatedClass → KILLED |
return annotatedClass; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * The method containing the annotations that was used to trying to parse the text in {@link #getFailedText()} | |
| 85 | * @return the annotated method | |
| 86 | */ | |
| 87 | public Method getAnnotatedMethod() { | |
| 88 |
1
1. getAnnotatedMethod : replaced return value with null for com/ancientprogramming/fixedformat4j/format/ParseException::getAnnotatedMethod → KILLED |
return annotatedMethod; |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * The context within the parsing was tried | |
| 93 | * @return the format context | |
| 94 | */ | |
| 95 | public FormatContext<?> getFormatContext() { | |
| 96 |
1
1. getFormatContext : replaced return value with null for com/ancientprogramming/fixedformat4j/format/ParseException::getFormatContext → KILLED |
return formatContext; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * The format instructions used to try parsing the text in {@link #getFailedText()} | |
| 101 | * @return the format instructions | |
| 102 | */ | |
| 103 | public FormatInstructions getFormatInstructions() { | |
| 104 |
1
1. getFormatInstructions : replaced return value with null for com/ancientprogramming/fixedformat4j/format/ParseException::getFormatInstructions → KILLED |
return formatInstructions; |
| 105 | } | |
| 106 | } | |
Mutations | ||
| 64 |
1.1 |
|
| 72 |
1.1 |
|
| 80 |
1.1 |
|
| 88 |
1.1 |
|
| 96 |
1.1 |
|
| 104 |
1.1 |