From e81449db4a5a8710036fb73d4bfc350a4a988baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 26 Apr 2024 13:28:01 +0200 Subject: [PATCH] fixes --- .../src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java | 3 ++- .../net/sourceforge/pmd/lang/document/BaseMappedDocument.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java index d9b8f452b3..34497c47f4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java @@ -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()); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/BaseMappedDocument.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/BaseMappedDocument.java index 55daae33ce..be92385faa 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/BaseMappedDocument.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/BaseMappedDocument.java @@ -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)); }