Skip to content

Commit

Permalink
Do not flag spelling errors in Javadoc code or link tags (#1503)
Browse files Browse the repository at this point in the history
- revert previous fix for param tag spelling errors as it is no
  longer needed
- add logic to recognize an in-line code or see tag and skip tokens
  in SpellCheckIterator until closing bracket of in-line tag
- fixes #1502
  • Loading branch information
jjohnstn authored Jul 10, 2024
1 parent 123be94 commit f119f2e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -34,6 +34,9 @@ public interface IJavaDocTagConstants {
/** Javadoc root tags */
String[] JAVADOC_ROOT_TAGS= new String[] { "@author", "@deprecated", "@return", "@see", "@serial", "@serialData", "@since", "@version", "@inheritDoc", "@category", "@value", "@literal", "@code", "@noinstantiate", "@noreference", "@noimplement", "@noextend", "@nooverride" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$ //$NON-NLS-15$ //$NON-NLS-16$ //$NON-NLS-17$ //$NON-NLS-18$

/** Javadoc example tags */
String[] JAVADOC_INLINE_EXAMPLE_TAGS= new String[] { "@code", "@see" }; //$NON-NLS-1$ //$NON-NLS-2$

/** Javadoc tag prefix */
char JAVADOC_TAG_PREFIX= '@';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,11 +13,10 @@
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.spelling;

import java.text.BreakIterator;
import java.util.LinkedList;
import java.util.Locale;

import java.text.BreakIterator;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

Expand Down Expand Up @@ -79,6 +78,9 @@ public class SpellCheckIterator implements ISpellCheckIterator {
/** The word iterator */
private final BreakIterator fWordIterator;

/** Whether last Javadoc tag is inlined or not */
private boolean fInlinedTag;

private boolean fIsIgnoringSingleLetters;

private final IProgressMonitor fMonitor;
Expand Down Expand Up @@ -338,11 +340,11 @@ protected String nextToken() {

if (fSuccessor != BreakIterator.DONE && fContent.charAt(fPrevious) == IJavaDocTagConstants.JAVADOC_TAG_PREFIX) {

int oldNextValue= fNext;
nextBreak();
if (Character.isLetter(fContent.charAt(fPrevious + 1))) {
update= true;
token= fContent.substring(fPrevious, oldNextValue);
token= fContent.substring(fPrevious, fNext);
fInlinedTag= fPrevious > 0 ? fContent.charAt(fPrevious - 1) == '{' : false;
} else
fPredecessor= fNext;

Expand Down Expand Up @@ -378,9 +380,13 @@ protected String nextToken() {

if (isUrlToken(fPrevious))
skipTokens(fPrevious, WHITE_SPACE_TOKEN);
else if (isToken(IJavaDocTagConstants.JAVADOC_PARAM_TAGS))
else if (isToken(IJavaDocTagConstants.JAVADOC_PARAM_TAGS)) {
fLastToken= null;
} else if (isToken(IJavaDocTagConstants.JAVADOC_INLINE_EXAMPLE_TAGS) && fInlinedTag) {
fLastToken= null;
else if (isToken(IJavaDocTagConstants.JAVADOC_REFERENCE_TAGS)) {
fInlinedTag= false;
skipPaired(fPrevious, '{' , '}');
} else if (isToken(IJavaDocTagConstants.JAVADOC_REFERENCE_TAGS)) {
fLastToken= null;
skipTokens(fPrevious, fDelimiter.charAt(0));
} else if (fNext - fPrevious > 1 || isSingleLetter(fPrevious) && !fIsIgnoringSingleLetters)
Expand Down Expand Up @@ -437,6 +443,35 @@ protected final void skipTokens(final int begin, final int stop) {
fSuccessor= BreakIterator.DONE;
}

/**
* Skip the tokens until the close character is reached to match all opening character.
*
* @param begin the begin index
* @param open the opening character
* @param close the closing character
*/
protected final void skipPaired(final int begin, final int open, final int close) {
int end= begin;
int openCount= 0;
while (end < fContent.length()) {
char ch= fContent.charAt(end);
if (ch == close && openCount == 0)
break;
else if (ch == open)
++openCount;
end++;
}

if (end < fContent.length()) {

fNext= end;
fPredecessor= fNext;

fSuccessor= fWordIterator.following(fNext);
} else
fSuccessor= BreakIterator.DONE;
}

/*
* @see org.eclipse.spelling.done.ISpellCheckIterator#startsSentence()
*/
Expand Down

0 comments on commit f119f2e

Please sign in to comment.