Skip to content

Commit

Permalink
[LO extension] solves issues languagetool-org#1217 and languagetool-o…
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKruse committed Feb 10, 2022
1 parent 52d2194 commit 0aa652f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ public void addParaErrorsToCache(int nFPara, SwJLanguageTool lt, int cacheNum, i
// make the method thread save
MultiDocumentsHandler mDH = mDocHandler;
DocumentCursorTools docCursor = this.docCursor;
if (isDisposed()) {
if (isDisposed() || docCache == null || nFPara < 0 || nFPara >= docCache.size()) {
MessageHandler.printToLogFile("SingleCheck: addParaErrorsToCache: return: isDisposed = " + isDisposed() + ", nFPara = " + nFPara
+ ", docCache(Size) = " + (docCache == null ? "null" : docCache.size()) );
return;
}
if (docCache == null || lt == null || nFPara < 0 || nFPara >= docCache.size()) {
return;
if (lt == null) {
MessageHandler.printToLogFile("SingleCheck: addParaErrorsToCache: return: lt is null");
}
DocumentCache docCache = new DocumentCache(this.docCache);
try {
Expand All @@ -197,6 +199,8 @@ public void addParaErrorsToCache(int nFPara, SwJLanguageTool lt, int cacheNum, i

String textToCheck = docCache.getDocAsString(tPara, parasToCheck, checkOnlyParagraph, useQueue, hasFootnotes);
List<RuleMatch> paragraphMatches = null;
// NOTE: lt == null if language is not supported by LT
// but empty proof reading errors have added to cache to satisfy text level queue
if (lt != null && mDocHandler.isSortedRuleForIndex(cacheNum)) {
paragraphMatches = lt.check(textToCheck, true, JLanguageTool.ParagraphHandling.ONLYPARA);
}
Expand All @@ -207,6 +211,9 @@ public void addParaErrorsToCache(int nFPara, SwJLanguageTool lt, int cacheNum, i
int endPos;
for (int i = startPara; i < endPara; i++) {
if (isDisposed() || (useQueue && !isDialogRequest && (mDH.getTextLevelCheckQueue() == null || mDH.getTextLevelCheckQueue().isInterrupted()))) {
MessageHandler.printToLogFile("SingleCheck: addParaErrorsToCache: return: isDisposed = " + isDisposed() + ", useQueue = " + useQueue
+ ", isDialogRequest = " + isDialogRequest + ", TextLevelCheckQueue(isInterrupted) = "
+ (mDH.getTextLevelCheckQueue() == null ? "null" : mDH.getTextLevelCheckQueue().isInterrupted()));
return;
}
TextParagraph textPara = docCache.createTextParagraph(cursorType, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ Language getLanguage(String docId, TextParagraph nStart) {
if (multiDocHandler.hasLocale(locale)) {
return multiDocHandler.getLanguage(locale);
}
MessageHandler.printToLogFile("Queue: getLanguage: return null: locale = " + OfficeTools.localeToString(locale));
}
}
return null;
Expand Down Expand Up @@ -534,7 +535,18 @@ public void run() {
if (textRuleQueue.isEmpty()) {
synchronized(textRuleQueue) {
if (lastDocId != null) {
QueueEntry queueEntry = getNextQueueEntry(lastStart, lastDocId);
QueueEntry queueEntry = null;
try {
queueEntry = getNextQueueEntry(lastStart, lastDocId);
} catch (Throwable e) {
// there may be exceptions because of timing problems
// catch them and write to log file but don't stop the queue
if (debugMode) {
MessageHandler.showError(e);
} else {
MessageHandler.printException(e);
}
}
if (queueEntry != null) {
textRuleQueue.add(queueEntry);
queueEntry = null;
Expand Down Expand Up @@ -577,23 +589,40 @@ public void run() {
MessageHandler.printToLogFile("run queue entry: docId = " + queueEntry.docId + ", nStart.type = " + queueEntry.nStart.type
+ ", nStart.number = " + queueEntry.nStart.number + ", nEnd.number = " + queueEntry.nEnd.number
+ ", nCheck = " + queueEntry.nCheck + ", overrideRunning = " + queueEntry.overrideRunning);
if (queueEntry.nStart.number + 1 == queueEntry.nEnd.number) {
SingleDocument document = getSingleDocument(queueEntry.docId);
MessageHandler.printToLogFile("Paragraph(" + queueEntry.nStart.number + "): '"
+ document.getDocumentCache().getTextParagraph(queueEntry.nStart) + "'");
}
}
Language entryLanguage = getLanguage(queueEntry.docId, queueEntry.nStart);
if (entryLanguage != null) {
if (lastLanguage == null || !lastLanguage.equals(entryLanguage)) {
lastLanguage = entryLanguage;
initLangtool(lastLanguage);
sortedTextRules.activateTextRulesByIndex(queueEntry.nCache, lt);
} else if (lastCache != queueEntry.nCache) {
sortedTextRules.activateTextRulesByIndex(queueEntry.nCache, lt);
try {
Language entryLanguage = getLanguage(queueEntry.docId, queueEntry.nStart);
if (entryLanguage != null) {
if (lastLanguage == null || !lastLanguage.equals(entryLanguage)) {
lastLanguage = entryLanguage;
initLangtool(lastLanguage);
sortedTextRules.activateTextRulesByIndex(queueEntry.nCache, lt);
} else if (lastCache != queueEntry.nCache) {
sortedTextRules.activateTextRulesByIndex(queueEntry.nCache, lt);
}
}
lastDocId = queueEntry.docId;
lastStart = queueEntry.nStart;
lastEnd = queueEntry.nEnd;
lastCache = queueEntry.nCache;
// entryLanguage == null: language is not supported by LT
// lt is set to null - results in empty entry in result cache
queueEntry.runQueueEntry(multiDocHandler, entryLanguage == null ? null : lt);
queueEntry = null;
} catch (Throwable e) {
// there may be exceptions because of timing problems
// catch them and write to log file but don't stop the queue
if (debugMode) {
MessageHandler.showError(e);
} else {
MessageHandler.printException(e);
}
}
lastDocId = queueEntry.docId;
lastStart = queueEntry.nStart;
lastEnd = queueEntry.nEnd;
lastCache = queueEntry.nCache;
queueEntry.runQueueEntry(multiDocHandler, entryLanguage == null ? null : lt);
queueEntry = null;
}
}
}
Expand Down

0 comments on commit 0aa652f

Please sign in to comment.