This commit is contained in:
Clément Fournier 2024-04-26 13:28:01 +02:00
parent 3f7840c1df
commit e81449db4a
No known key found for this signature in database
GPG Key ID: 91A544D7F05BBCBB
2 changed files with 5 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
import net.sourceforge.pmd.lang.ast.LexException;
import net.sourceforge.pmd.lang.ast.impl.javacc.MalformedSourceException;
import net.sourceforge.pmd.lang.document.FileCollector;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.InternalApiBridge;
@ -171,7 +172,7 @@ public final class CpdAnalysis implements AutoCloseable {
int newTokens = doTokenize(textDocument, tokenizers.get(textFile.getLanguageVersion().getLanguage()), tokens);
numberOfTokensPerFile.put(textDocument.getFileId(), newTokens);
listener.addedFile(1);
} catch (LexException | IOException e) {
} catch (LexException | IOException | MalformedSourceException e) {
if (e instanceof FileAnalysisException) { // NOPMD
((FileAnalysisException) e).setFileId(textFile.getFileId());
}

View File

@ -68,6 +68,9 @@ abstract class BaseMappedDocument implements TextDocument {
* @return Input region
*/
protected @NonNull TextRegion inputRegion(TextRegion outputRegion) {
if (outputRegion.isEmpty()) {
return TextRegion.caretAt(inputOffset(outputRegion.getStartOffset(), false));
}
return TextRegion.fromBothOffsets(inputOffset(outputRegion.getStartOffset(), true),
inputOffset(outputRegion.getEndOffset(), false));
}